Skip to content

Commit

Permalink
added server user create team
Browse files Browse the repository at this point in the history
  • Loading branch information
fomalhautb committed Jun 18, 2024
1 parent e5b41ef commit b2a3f25
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/stack-shared/src/interface/clientInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ export class StackClientInterface {
};
}

async createClientTeam(
async createTeamForCurrentUser(
data: TeamCustomizableJson,
session: InternalSession,
): Promise<TeamJson> {
Expand Down
19 changes: 19 additions & 0 deletions packages/stack-shared/src/interface/serverInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,23 @@ export class StackServerInterface extends StackClientInterface {
null,
);
}

async createServerTeamForUser(
userId: string,
data: ServerTeamCustomizableJson,
session: InternalSession,
): Promise<ServerTeamJson> {
const response = await this.sendClientRequest(
`/users/${userId}/teams?server=true`,
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify(data),
},
session,
);
return await response.json();
}
}
8 changes: 5 additions & 3 deletions packages/stack/src/lib/stack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
return useMemo(() => teams.map((json) => app._teamFromJson(json)), [teams]);
},
async createTeam(data: TeamCustomizableJson) {
const teamJson = await app._interface.createClientTeam(data, session);
const teamJson = await app._interface.createTeamForCurrentUser(data, session);
await app._currentUserTeamsCache.refresh([session]);
return app._teamFromJson(teamJson);
},
Expand Down Expand Up @@ -1361,8 +1361,10 @@ class _StackServerAppImpl<HasTokenStore extends boolean, ProjectId extends strin
useTeams() {
return app._useCheckFeatureSupport("useTeams() on ServerUser", {});
},
createTeam: async () => {
throw new Error();
createTeam: async (data: ServerTeamCustomizableJson) => {
const team = await app._interface.createServerTeamForUser(json.id, data, app._getSession());
await app._serverTeamsCache.refresh([]);
return app._serverTeamFromJson(team);
},
async listPermissions(scope: Team, options?: { direct?: boolean }): Promise<ServerPermission[]> {
const permissions = await app._serverTeamUserPermissionsCache.getOrWait([scope.id, json.id, 'team', !!options?.direct], "write-only");
Expand Down

0 comments on commit b2a3f25

Please sign in to comment.