website API shareId compatibility updates
This commit is contained in:
1 parent
fdb99607bc
commit
2489601ae6
4 files changed
+147
-11
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
import { ENTITY_TYPE } from '@/lib/constants';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { fetchAccount } from '@/lib/load';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { pagingParams, searchParams } from '@/lib/schema';
|
||||
import { canCreateTeamWebsite, canCreateWebsite } from '@/permissions';
|
||||
import { createWebsite, getWebsiteCount } from '@/queries/prisma';
|
||||
import { createShare, createWebsite, getWebsiteCount } from '@/queries/prisma';
|
||||
import { getAllUserWebsitesIncludingTeamOwner, getUserWebsites } from '@/queries/prisma/website';
|
||||
|
||||
const CLOUD_WEBSITE_LIMIT = 3;
|
||||
@@ -38,6 +39,7 @@ export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
name: z.string().max(100),
|
||||
domain: z.string().max(500),
|
||||
shareId: z.string().max(50).nullable().optional(),
|
||||
teamId: z.uuid().nullable().optional(),
|
||||
id: z.uuid().nullable().optional(),
|
||||
});
|
||||
@@ -48,7 +50,7 @@ export async function POST(request: Request) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { id, name, domain, teamId } = body;
|
||||
const { id, name, domain, shareId, teamId } = body;
|
||||
|
||||
if (process.env.CLOUD_MODE && !teamId) {
|
||||
const account = await fetchAccount(auth.user.id);
|
||||
@@ -80,5 +82,19 @@ export async function POST(request: Request) {
|
||||
|
||||
const website = await createWebsite(data);
|
||||
|
||||
return json(website);
|
||||
const share = shareId
|
||||
? await createShare({
|
||||
id: uuid(),
|
||||
entityId: website.id,
|
||||
shareType: ENTITY_TYPE.website,
|
||||
name: website.name,
|
||||
slug: shareId,
|
||||
parameters: { overview: true, events: true },
|
||||
})
|
||||
: null;
|
||||
|
||||
return json({
|
||||
...website,
|
||||
shareId: share?.slug ?? null,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user