From ceee19bc36f1d2da8a56bc73a959ed4877cda0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Mon, 5 Feb 2024 22:04:41 +0100 Subject: [PATCH] fix setup script --- .../src/app/api/{setup.ts => setup/route.ts} | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) rename apps/web/src/app/api/{setup.ts => setup/route.ts} (74%) diff --git a/apps/web/src/app/api/setup.ts b/apps/web/src/app/api/setup/route.ts similarity index 74% rename from apps/web/src/app/api/setup.ts rename to apps/web/src/app/api/setup/route.ts index 15f60e31..a4209391 100644 --- a/apps/web/src/app/api/setup.ts +++ b/apps/web/src/app/api/setup/route.ts @@ -1,19 +1,15 @@ import { randomUUID } from 'crypto'; import { db, getId } from '@/server/db'; -import { handleError } from '@/server/exceptions'; import { hashPassword } from '@/server/services/hash.service'; -import type { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -const userName = 'Admin'; -const userPassword = 'password'; -const userEmail = 'acme@acme.com'; -const organizationName = 'Acme Inc.'; -const projectName = 'Website'; +const userName = 'demo'; +const userPassword = 'demo'; +const userEmail = 'demo@demo.com'; +const organizationName = 'Demo Org'; +const projectName = 'Demo Project'; -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { +export async function GET() { try { const counts = await db.$transaction([ db.user.count(), @@ -23,7 +19,7 @@ export default async function handler( ]); if (counts.some((count) => count > 0)) { - return res.json('Setup already done'); + return NextResponse.json({ message: 'Already setup' }); } const organization = await db.organization.create({ @@ -59,12 +55,12 @@ export default async function handler( }, }); - res.json({ + return NextResponse.json({ clientId: client.id, clientSecret: secret, user, }); } catch (error) { - handleError(res, error); + return NextResponse.json({ error: 'Failed to setup' }); } }