feat: enhance createSport functionality with conflict handling and result management
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,18 +1,10 @@
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import { handleResult } from '@/lib/http/handle-result';
|
||||
import { createSport } from '@/modules/sport/services/sport.service';
|
||||
import type { AppContext } from '@/types/hono';
|
||||
import type { CreateSportInput } from '@repo/api-contract';
|
||||
|
||||
export async function createSportHandler(c: AppContext) {
|
||||
const payload = c.req.valid('json' as never) as CreateSportInput;
|
||||
|
||||
try {
|
||||
const sport = await createSport(payload);
|
||||
return c.json(sport, 201);
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
return c.json({ message: 'No se pudo crear el deporte.' }, 409);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return handleResult(c, await createSport(payload), 201);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user