Refactor to vertical slice

This commit is contained in:
Jose Selesan
2026-06-26 14:05:37 -03:00
parent 3949c9add1
commit c8477de5d2
149 changed files with 5011 additions and 5127 deletions

View File

@@ -0,0 +1,32 @@
import { db } from '@/lib/prisma';
import type { AdminCreatePlanInput } from '@repo/api-contract';
import { v7 as uuidv7 } from 'uuid';
export async function createPlan(input: AdminCreatePlanInput) {
const existing = await db.plan.findUnique({
where: { code: input.code },
});
if (existing) {
return { ok: false as const, message: 'Ya existe un plan con ese código.' };
}
const plan = await db.plan.create({
data: {
code: input.code,
name: input.name,
price: input.price,
rules: input.rules,
},
});
return {
ok: true as const,
data: {
code: plan.code,
name: plan.name,
price: Number(plan.price),
rules: plan.rules,
},
};
}

View File

@@ -0,0 +1,15 @@
import type { AppContext } from '@/types/hono';
import type { AdminCreatePlanInput } from '@repo/api-contract';
import { createPlan } from './create-plan.business';
export async function createPlanHandler(c: AppContext) {
const body = c.req.valid('json' as never) as AdminCreatePlanInput;
const result = await createPlan(body);
if (!result.ok) {
return c.json({ message: result.message }, 409);
}
return c.json(result.data, 201);
}