(request: Request)
| 27 | } |
| 28 | |
| 29 | export async function POST(request: Request) { |
| 30 | const schema = z.object({ |
| 31 | name: z.string().max(100), |
| 32 | slug: z.string().max(100), |
| 33 | teamId: z.string().nullable().optional(), |
| 34 | id: z.uuid().nullable().optional(), |
| 35 | }); |
| 36 | |
| 37 | const { auth, body, error } = await parseRequest(request, schema); |
| 38 | |
| 39 | if (error) { |
| 40 | return error(); |
| 41 | } |
| 42 | |
| 43 | const { id, name, slug, teamId } = body; |
| 44 | |
| 45 | if ((teamId && !(await canCreateTeamWebsite(auth, teamId))) || !(await canCreateWebsite(auth))) { |
| 46 | return unauthorized(); |
| 47 | } |
| 48 | |
| 49 | const data: any = { |
| 50 | id: id ?? uuid(), |
| 51 | name, |
| 52 | slug, |
| 53 | teamId, |
| 54 | }; |
| 55 | |
| 56 | if (!teamId) { |
| 57 | data.userId = auth.user.id; |
| 58 | } |
| 59 | |
| 60 | const result = await createPixel(data); |
| 61 | |
| 62 | return json(result); |
| 63 | } |
nothing calls this directly
no test coverage detected