Skip to content

Commit

Permalink
Merge pull request #48 from Saasfy/max-domains
Browse files Browse the repository at this point in the history
feat(web): add domain limits
  • Loading branch information
IKatsuba authored May 8, 2024
2 parents a1368ff + 8dd9e0c commit d3203b0
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions apps/web/app/api/workspaces/[workspaceSlug]/domains/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,34 @@ import { createAdminClient } from '@saasfy/supabase/server';

export const POST = withWorkspaceUser(
['owner', 'member'] as const,
async ({ req, params, workspace }) => {
async ({ req, params, workspace: { id: workspaceId } }) => {
const { name } = await req.json();

const supabase = createAdminClient();

const { data: workspace } = await supabase
.from('workspaces')
.select('*, plans(max_domains), domains(id)')
.eq('id', workspaceId)
.single();

const maxDomains = workspace?.plans?.max_domains || 1;

if (workspace?.domains?.length ?? 0 >= maxDomains) {
return Response.json(
{
errors: ['Workspace is full'],
domain: null,
},
{
status: 400,
},
);
}

const domain = await supabase
.from('domains')
.insert({ slug: name, workspace_id: workspace.id })
.insert({ slug: name, workspace_id: workspaceId })
.select('*')
.single();

Expand Down

0 comments on commit d3203b0

Please sign in to comment.