feat: implement onboarding flow with complex creation and email verification, and add Zustand for state management
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { db } from '@/lib/prisma';
|
||||
import { createComplex } from '@/modules/complex/services/complex.service';
|
||||
import type { AppContext } from '@/types/hono';
|
||||
import type { CreateComplexInput } from '@repo/api-contract';
|
||||
@@ -6,16 +7,32 @@ export async function createComplexHandler(c: AppContext) {
|
||||
const payload = c.req.valid('json' as never) as CreateComplexInput;
|
||||
|
||||
const user = c.get('user');
|
||||
const adminEmail = user.email;
|
||||
let adminEmail = user?.email;
|
||||
let userId = user?.id;
|
||||
|
||||
if (!adminEmail) {
|
||||
return c.json({ message: 'El usuario autenticado no tiene email.' }, 400);
|
||||
const body = await c.req.json().catch(() => ({}));
|
||||
adminEmail = body.adminEmail;
|
||||
userId = body.userId;
|
||||
}
|
||||
|
||||
if (!adminEmail) {
|
||||
return c.json({ message: 'Se requiere email del administrador.' }, 400);
|
||||
}
|
||||
|
||||
if (!userId && adminEmail) {
|
||||
const existingUser = await db.user.findUnique({
|
||||
where: { email: adminEmail },
|
||||
select: { id: true },
|
||||
});
|
||||
userId = existingUser?.id;
|
||||
}
|
||||
|
||||
const complex = await createComplex({
|
||||
complexName: payload.complexName,
|
||||
physicalAddress: payload.physicalAddress,
|
||||
adminEmail,
|
||||
userId,
|
||||
planCode: payload.planCode,
|
||||
city: payload.city,
|
||||
state: payload.state,
|
||||
|
||||
Reference in New Issue
Block a user