fix setup script
This commit is contained in:
@@ -1,19 +1,15 @@
|
|||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { db, getId } from '@/server/db';
|
import { db, getId } from '@/server/db';
|
||||||
import { handleError } from '@/server/exceptions';
|
|
||||||
import { hashPassword } from '@/server/services/hash.service';
|
import { hashPassword } from '@/server/services/hash.service';
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
const userName = 'Admin';
|
const userName = 'demo';
|
||||||
const userPassword = 'password';
|
const userPassword = 'demo';
|
||||||
const userEmail = 'acme@acme.com';
|
const userEmail = 'demo@demo.com';
|
||||||
const organizationName = 'Acme Inc.';
|
const organizationName = 'Demo Org';
|
||||||
const projectName = 'Website';
|
const projectName = 'Demo Project';
|
||||||
|
|
||||||
export default async function handler(
|
export async function GET() {
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
const counts = await db.$transaction([
|
const counts = await db.$transaction([
|
||||||
db.user.count(),
|
db.user.count(),
|
||||||
@@ -23,7 +19,7 @@ export default async function handler(
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (counts.some((count) => count > 0)) {
|
if (counts.some((count) => count > 0)) {
|
||||||
return res.json('Setup already done');
|
return NextResponse.json({ message: 'Already setup' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const organization = await db.organization.create({
|
const organization = await db.organization.create({
|
||||||
@@ -59,12 +55,12 @@ export default async function handler(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
res.json({
|
return NextResponse.json({
|
||||||
clientId: client.id,
|
clientId: client.id,
|
||||||
clientSecret: secret,
|
clientSecret: secret,
|
||||||
user,
|
user,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(res, error);
|
return NextResponse.json({ error: 'Failed to setup' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user