feat: add city/state/country to complex, new settings page with sidebar, and Biome linting
- Added city, state, and country optional fields to Complex model - Updated onboarding to include optional location fields - Created new settings page with sidebar navigation (Datos del Complejo, Canchas) - Replaced ESLint with Biome for frontend and backend linting - Added parallel dev script with concurrently - Migrated register-routes to use direct app.route() pattern
This commit is contained in:
@@ -1,37 +1,33 @@
|
||||
import { zValidator } from '@hono/zod-validator'
|
||||
import { createComplexSchema, updateComplexSchema } from '@repo/api-contract'
|
||||
import { Hono } from 'hono'
|
||||
import { z } from 'zod'
|
||||
import { requireAuth } from '@/middlewares/require-auth.middleware'
|
||||
import { createComplexHandler } from '@/modules/complex/handlers/create-complex.handler'
|
||||
import { getComplexByIdHandler } from '@/modules/complex/handlers/get-complex-by-id.handler'
|
||||
import { getComplexBySlugHandler } from '@/modules/complex/handlers/get-complex-by-slug.handler'
|
||||
import { listMyComplexesHandler } from '@/modules/complex/handlers/list-my-complexes.handler'
|
||||
import { updateComplexHandler } from '@/modules/complex/handlers/update-complex.handler'
|
||||
import type { AppEnv } from '@/types/hono'
|
||||
import { requireAuth } from '@/middlewares/require-auth.middleware';
|
||||
import { createComplexHandler } from '@/modules/complex/handlers/create-complex.handler';
|
||||
import { getComplexByIdHandler } from '@/modules/complex/handlers/get-complex-by-id.handler';
|
||||
import { getComplexBySlugHandler } from '@/modules/complex/handlers/get-complex-by-slug.handler';
|
||||
import { listMyComplexesHandler } from '@/modules/complex/handlers/list-my-complexes.handler';
|
||||
import { updateComplexHandler } from '@/modules/complex/handlers/update-complex.handler';
|
||||
import type { AppEnv } from '@/types/hono';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
import { createComplexSchema, updateComplexSchema } from '@repo/api-contract';
|
||||
import { Hono } from 'hono';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const complexRoutes = new Hono<AppEnv>()
|
||||
const complexIdParamsSchema = z.object({ id: z.uuid() })
|
||||
const complexSlugParamsSchema = z.object({ slug: z.string().trim().min(1) })
|
||||
export const complexRoutes = new Hono<AppEnv>();
|
||||
const complexIdParamsSchema = z.object({ id: z.uuid() });
|
||||
const complexSlugParamsSchema = z.object({ slug: z.string().trim().min(1) });
|
||||
|
||||
complexRoutes.use('*', requireAuth)
|
||||
complexRoutes.use('*', requireAuth);
|
||||
|
||||
complexRoutes.post('/', zValidator('json', createComplexSchema), createComplexHandler)
|
||||
complexRoutes.get('/mine', listMyComplexesHandler)
|
||||
complexRoutes.post('/', zValidator('json', createComplexSchema), createComplexHandler);
|
||||
complexRoutes.get('/mine', listMyComplexesHandler);
|
||||
complexRoutes.get(
|
||||
'/slug/:slug',
|
||||
zValidator('param', complexSlugParamsSchema),
|
||||
getComplexBySlugHandler,
|
||||
)
|
||||
getComplexBySlugHandler
|
||||
);
|
||||
|
||||
complexRoutes.get(
|
||||
'/:id',
|
||||
zValidator('param', complexIdParamsSchema),
|
||||
getComplexByIdHandler,
|
||||
)
|
||||
complexRoutes.get('/:id', zValidator('param', complexIdParamsSchema), getComplexByIdHandler);
|
||||
complexRoutes.patch(
|
||||
'/:id',
|
||||
zValidator('param', complexIdParamsSchema),
|
||||
zValidator('json', updateComplexSchema),
|
||||
updateComplexHandler,
|
||||
)
|
||||
updateComplexHandler
|
||||
);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import type { CreateComplexInput } from '@repo/api-contract'
|
||||
import type { AppContext } from '@/types/hono'
|
||||
import { createComplex } from '@/modules/complex/services/complex.service'
|
||||
import { createComplex } from '@/modules/complex/services/complex.service';
|
||||
import type { AppContext } from '@/types/hono';
|
||||
import type { CreateComplexInput } from '@repo/api-contract';
|
||||
|
||||
export async function createComplexHandler(c: AppContext) {
|
||||
const payload = c.req.valid('json' as never) as CreateComplexInput
|
||||
const payload = c.req.valid('json' as never) as CreateComplexInput;
|
||||
|
||||
const authUser = c.get('authUser')
|
||||
const adminEmail = authUser.email
|
||||
const authUser = c.get('authUser');
|
||||
const adminEmail = authUser.email;
|
||||
|
||||
if (!adminEmail) {
|
||||
return c.json({ message: 'El usuario autenticado no tiene email.' }, 400)
|
||||
return c.json({ message: 'El usuario autenticado no tiene email.' }, 400);
|
||||
}
|
||||
|
||||
const complex = await createComplex({
|
||||
@@ -20,7 +20,7 @@ export async function createComplexHandler(c: AppContext) {
|
||||
city: payload.city,
|
||||
state: payload.state,
|
||||
country: payload.country,
|
||||
})
|
||||
});
|
||||
|
||||
return c.json(complex, 201)
|
||||
return c.json(complex, 201);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { AppContext } from '@/types/hono'
|
||||
import { getComplexById } from '@/modules/complex/services/complex.service'
|
||||
import { getComplexById } from '@/modules/complex/services/complex.service';
|
||||
import type { AppContext } from '@/types/hono';
|
||||
|
||||
type ComplexIdParams = { id: string }
|
||||
type ComplexIdParams = { id: string };
|
||||
|
||||
export async function getComplexByIdHandler(c: AppContext) {
|
||||
const { id } = c.req.valid('param' as never) as ComplexIdParams
|
||||
const { id } = c.req.valid('param' as never) as ComplexIdParams;
|
||||
|
||||
const complex = await getComplexById(id)
|
||||
const complex = await getComplexById(id);
|
||||
|
||||
if (!complex) {
|
||||
return c.json({ message: 'Complejo no encontrado.' }, 404)
|
||||
return c.json({ message: 'Complejo no encontrado.' }, 404);
|
||||
}
|
||||
|
||||
return c.json(complex)
|
||||
return c.json(complex);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { AppContext } from '@/types/hono'
|
||||
import { getComplexBySlug } from '@/modules/complex/services/complex.service'
|
||||
import { getComplexBySlug } from '@/modules/complex/services/complex.service';
|
||||
import type { AppContext } from '@/types/hono';
|
||||
|
||||
type ComplexSlugParams = { slug: string }
|
||||
type ComplexSlugParams = { slug: string };
|
||||
|
||||
export async function getComplexBySlugHandler(c: AppContext) {
|
||||
const { slug } = c.req.valid('param' as never) as ComplexSlugParams
|
||||
const { slug } = c.req.valid('param' as never) as ComplexSlugParams;
|
||||
|
||||
const complex = await getComplexBySlug(slug)
|
||||
const complex = await getComplexBySlug(slug);
|
||||
|
||||
if (!complex) {
|
||||
return c.json({ message: 'Complejo no encontrado.' }, 404)
|
||||
return c.json({ message: 'Complejo no encontrado.' }, 404);
|
||||
}
|
||||
|
||||
return c.json(complex)
|
||||
return c.json(complex);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { AppContext } from '@/types/hono'
|
||||
import { listMyComplexes } from '@/modules/complex/services/complex.service'
|
||||
import { listMyComplexes } from '@/modules/complex/services/complex.service';
|
||||
import type { AppContext } from '@/types/hono';
|
||||
|
||||
export async function listMyComplexesHandler(c: AppContext) {
|
||||
const appUserId = c.get('appUserId')
|
||||
const complexes = await listMyComplexes(appUserId)
|
||||
return c.json(complexes)
|
||||
const appUserId = c.get('appUserId');
|
||||
const complexes = await listMyComplexes(appUserId);
|
||||
return c.json(complexes);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import type { UpdateComplexInput } from '@repo/api-contract'
|
||||
import { Prisma } from '@/generated/prisma/client'
|
||||
import type { AppContext } from '@/types/hono'
|
||||
import { getComplexById, updateComplex } from '@/modules/complex/services/complex.service'
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import { getComplexById, updateComplex } from '@/modules/complex/services/complex.service';
|
||||
import type { AppContext } from '@/types/hono';
|
||||
import type { UpdateComplexInput } from '@repo/api-contract';
|
||||
|
||||
type ComplexIdParams = { id: string }
|
||||
type ComplexIdParams = { id: string };
|
||||
|
||||
export async function updateComplexHandler(c: AppContext) {
|
||||
const { id } = c.req.valid('param' as never) as ComplexIdParams
|
||||
const payload = c.req.valid('json' as never) as UpdateComplexInput
|
||||
const { id } = c.req.valid('param' as never) as ComplexIdParams;
|
||||
const payload = c.req.valid('json' as never) as UpdateComplexInput;
|
||||
|
||||
const existing = await getComplexById(id)
|
||||
const existing = await getComplexById(id);
|
||||
|
||||
if (!existing) {
|
||||
return c.json({ message: 'Complejo no encontrado.' }, 404)
|
||||
return c.json({ message: 'Complejo no encontrado.' }, 404);
|
||||
}
|
||||
|
||||
try {
|
||||
const complex = await updateComplex(id, payload)
|
||||
return c.json(complex)
|
||||
const complex = await updateComplex(id, payload);
|
||||
return c.json(complex);
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
return c.json({ message: 'No se pudo actualizar el complejo.' }, 409)
|
||||
return c.json({ message: 'No se pudo actualizar el complejo.' }, 409);
|
||||
}
|
||||
throw error
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { v7 as uuidv7 } from 'uuid'
|
||||
import { Prisma } from '@/generated/prisma/client'
|
||||
import { db } from '@/lib/prisma'
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import { db } from '@/lib/prisma';
|
||||
import { v7 as uuidv7 } from 'uuid';
|
||||
|
||||
export type CreateComplexInput = {
|
||||
complexName: string
|
||||
physicalAddress: string
|
||||
adminEmail: string
|
||||
planCode?: string
|
||||
city?: string
|
||||
state?: string
|
||||
country?: string
|
||||
}
|
||||
complexName: string;
|
||||
physicalAddress: string;
|
||||
adminEmail: string;
|
||||
planCode?: string;
|
||||
city?: string;
|
||||
state?: string;
|
||||
country?: string;
|
||||
};
|
||||
|
||||
export type UpdateComplexInput = {
|
||||
complexName?: string
|
||||
physicalAddress?: string | null
|
||||
complexSlug?: string
|
||||
adminEmail?: string
|
||||
planCode?: string | null
|
||||
city?: string | null
|
||||
state?: string | null
|
||||
country?: string | null
|
||||
}
|
||||
complexName?: string;
|
||||
physicalAddress?: string | null;
|
||||
complexSlug?: string;
|
||||
adminEmail?: string;
|
||||
planCode?: string | null;
|
||||
city?: string | null;
|
||||
state?: string | null;
|
||||
country?: string | null;
|
||||
};
|
||||
|
||||
function slugify(value: string): string {
|
||||
return value
|
||||
@@ -31,18 +31,15 @@ function slugify(value: string): string {
|
||||
.trim()
|
||||
.replace(/[^a-z0-9\s-]/g, '')
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/-+/g, '-');
|
||||
}
|
||||
|
||||
async function buildUniqueSlug(
|
||||
source: string,
|
||||
excludeComplexId?: string,
|
||||
): Promise<string> {
|
||||
const base = slugify(source)
|
||||
const fallback = base.length > 0 ? base : `complex-${uuidv7().slice(0, 8)}`
|
||||
async function buildUniqueSlug(source: string, excludeComplexId?: string): Promise<string> {
|
||||
const base = slugify(source);
|
||||
const fallback = base.length > 0 ? base : `complex-${uuidv7().slice(0, 8)}`;
|
||||
|
||||
let candidate = fallback
|
||||
let index = 1
|
||||
let candidate = fallback;
|
||||
let index = 1;
|
||||
|
||||
while (true) {
|
||||
const existing = await db.complex.findFirst({
|
||||
@@ -57,17 +54,17 @@ async function buildUniqueSlug(
|
||||
: {}),
|
||||
},
|
||||
select: { id: true },
|
||||
})
|
||||
});
|
||||
|
||||
if (!existing) return candidate
|
||||
if (!existing) return candidate;
|
||||
|
||||
index += 1
|
||||
candidate = `${fallback}-${index}`
|
||||
index += 1;
|
||||
candidate = `${fallback}-${index}`;
|
||||
}
|
||||
}
|
||||
|
||||
export async function createComplex(input: CreateComplexInput) {
|
||||
const complexSlug = await buildUniqueSlug(input.complexName)
|
||||
const complexSlug = await buildUniqueSlug(input.complexName);
|
||||
|
||||
return db.complex.create({
|
||||
data: {
|
||||
@@ -81,19 +78,19 @@ export async function createComplex(input: CreateComplexInput) {
|
||||
adminEmail: input.adminEmail,
|
||||
planCode: input.planCode,
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export async function getComplexById(id: string) {
|
||||
return db.complex.findUnique({
|
||||
where: { id },
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export async function getComplexBySlug(slug: string) {
|
||||
return db.complex.findUnique({
|
||||
where: { complexSlug: slug },
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export async function listMyComplexes(appUserId: string) {
|
||||
@@ -105,49 +102,49 @@ export async function listMyComplexes(appUserId: string) {
|
||||
orderBy: {
|
||||
createdAt: 'asc',
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
return complexUsers.map((complexUser) => complexUser.complex)
|
||||
return complexUsers.map((complexUser) => complexUser.complex);
|
||||
}
|
||||
|
||||
export async function updateComplex(id: string, input: UpdateComplexInput) {
|
||||
const data: Record<string, unknown> = {}
|
||||
const data: Record<string, unknown> = {};
|
||||
|
||||
if (input.complexName) {
|
||||
data.complexName = input.complexName
|
||||
data.complexSlug = await buildUniqueSlug(input.complexName, id)
|
||||
data.complexName = input.complexName;
|
||||
data.complexSlug = await buildUniqueSlug(input.complexName, id);
|
||||
}
|
||||
|
||||
if (input.complexSlug) {
|
||||
data.complexSlug = await buildUniqueSlug(input.complexSlug, id)
|
||||
data.complexSlug = await buildUniqueSlug(input.complexSlug, id);
|
||||
}
|
||||
|
||||
if (input.adminEmail) {
|
||||
data.adminEmail = input.adminEmail
|
||||
data.adminEmail = input.adminEmail;
|
||||
}
|
||||
|
||||
if (input.planCode !== undefined) {
|
||||
data.planCode = input.planCode
|
||||
data.planCode = input.planCode;
|
||||
}
|
||||
|
||||
if (input.physicalAddress !== undefined) {
|
||||
data.physicalAddress = input.physicalAddress?.trim() ?? null
|
||||
data.physicalAddress = input.physicalAddress?.trim() ?? null;
|
||||
}
|
||||
|
||||
if (input.city !== undefined) {
|
||||
data.city = input.city?.trim() ?? null
|
||||
data.city = input.city?.trim() ?? null;
|
||||
}
|
||||
|
||||
if (input.state !== undefined) {
|
||||
data.state = input.state?.trim() ?? null
|
||||
data.state = input.state?.trim() ?? null;
|
||||
}
|
||||
|
||||
if (input.country !== undefined) {
|
||||
data.country = input.country?.trim() ?? null
|
||||
data.country = input.country?.trim() ?? null;
|
||||
}
|
||||
|
||||
return db.complex.update({
|
||||
where: { id },
|
||||
data: data as Prisma.ComplexUncheckedUpdateInput,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user