-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Saasfy/max-members
feat(web): add user limits
- Loading branch information
Showing
4 changed files
with
65 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
45 changes: 45 additions & 0 deletions
45
apps/web/app/api/workspaces/[workspaceSlug]/members/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { withWorkspaceOwner } from '@saasfy/api/server'; | ||
import { createWorkspaceUser } from '@saasfy/crud/workspace-users/server'; | ||
import { createAdminClient } from '@saasfy/supabase/server'; | ||
|
||
export const POST = withWorkspaceOwner(async ({ req, workspace: { id: workspaceId }, user }) => { | ||
const data = await req.json(); | ||
|
||
const supabase = createAdminClient(); | ||
|
||
const { data: workspace } = await supabase | ||
.from('workspaces') | ||
.select('*, plans(*), workspace_users(id)') | ||
.eq('id', workspaceId) | ||
.single(); | ||
|
||
const maxUsers = workspace?.plans?.max_users || 0; | ||
|
||
if (workspace?.workspace_users?.length ?? 0 >= maxUsers) { | ||
return Response.json( | ||
{ | ||
errors: ['Workspace is full'], | ||
workspace: null, | ||
}, | ||
{ | ||
status: 400, | ||
}, | ||
); | ||
} | ||
|
||
const { errors, workspaceUser } = await createWorkspaceUser({ | ||
...data, | ||
workspace_id: workspaceId, | ||
user_id: user.id, | ||
}); | ||
|
||
return Response.json( | ||
{ | ||
errors, | ||
workspaceUser, | ||
}, | ||
{ | ||
status: errors ? 400 : 200, | ||
}, | ||
); | ||
}); |
22 changes: 0 additions & 22 deletions
22
apps/web/app/api/workspaces/[workspaceSlug]/users/route.ts
This file was deleted.
Oops, something went wrong.