fix: resolve TypeScript compilation errors from service extraction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-03-23 09:11:04 +01:00
parent 28eb58946f
commit c0b8a94210
8 changed files with 34 additions and 29 deletions

View File

@@ -34,7 +34,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
const body = parsed.data;
const result = await attendanceService.saveNotes(authData.userId, body.notes ? String(body.notes) : null);
if ('error' in result) return error(reply, result.error, 400);
if ('error' in result) return error(reply, result.error!, 400);
return success(reply, null, 200, 'Poznámka uložena');
});
@@ -46,7 +46,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
const body = parsed.data;
const result = await attendanceService.updateAddress(authData.userId, body.address ?? null, body.punch_action);
if ('error' in result) return error(reply, result.error, 404);
if ('error' in result) return error(reply, result.error!, 404);
return success(reply, null, 200, 'Adresa aktualizována');
});
@@ -59,7 +59,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
const newProjectId = body.project_id ? Number(body.project_id) : null;
const result = await attendanceService.switchProject(authData.userId, newProjectId);
if ('error' in result) return error(reply, result.error, 400);
if ('error' in result) return error(reply, result.error!, 400);
return success(reply, null, 200, 'Projekt přepnut');
});
@@ -169,7 +169,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
sick_used: balBody.sick_used,
});
if ('error' in result) return error(reply, result.error, 400);
if ('error' in result) return error(reply, result.error!, 400);
await logAudit({
request, authData, action: 'update', entityType: 'leave_balance',
@@ -220,10 +220,10 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
date_to: leaveBody.date_to,
leave_type: leaveBody.leave_type,
leave_hours: leaveBody.leave_hours,
notes: leaveBody.notes,
notes: leaveBody.notes ?? undefined,
}, authData.userId);
if ('error' in result) return error(reply, result.error, 400);
if ('error' in result) return error(reply, result.error!, 400);
return success(reply, { created: result.created }, 200, result.message!);
}
@@ -241,7 +241,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
address: punchBody.address,
});
if ('error' in result) return error(reply, result.error, 400);
if ('error' in result) return error(reply, result.error!, 400);
await logAudit({
request, authData, action: result.auditAction, entityType: 'attendance',
@@ -303,14 +303,14 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
departure_time: body.departure_time,
break_start: body.break_start,
break_end: body.break_end,
notes: body.notes,
project_id: body.project_id,
notes: body.notes ?? undefined,
project_id: body.project_id != null ? Number(body.project_id) : (body.project_id as number | null | undefined),
leave_type: body.leave_type,
leave_hours: body.leave_hours,
leave_hours: body.leave_hours != null ? Number(body.leave_hours) : (body.leave_hours as number | null | undefined),
project_logs: body.project_logs,
}, authData.userId, isAdmin);
if ('error' in result) return error(reply, result.error, result.status!);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({
request,
@@ -330,7 +330,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
if (id === null) return;
const result = await attendanceService.deleteAttendance(id);
if ('error' in result) return error(reply, result.error, 404);
if ('error' in result) return error(reply, result.error!, 404);
await logAudit({
request,

View File

@@ -153,8 +153,9 @@ export default async function companySettingsRoutes(fastify: FastifyInstance): P
const data: Record<string, unknown> = { modified_at: new Date() };
const strFields = ['company_name', 'street', 'city', 'postal_code', 'country', 'company_id', 'vat_id', 'quotation_prefix', 'default_currency', 'order_type_code', 'invoice_type_code'];
const bodyRec = body as Record<string, unknown>;
for (const f of strFields) {
if (body[f] !== undefined) data[f] = body[f] ? String(body[f]) : null;
if (bodyRec[f] !== undefined) data[f] = bodyRec[f] ? String(bodyRec[f]) : null;
}
if (body.default_vat_rate !== undefined) data.default_vat_rate = Number(body.default_vat_rate);
if (body.require_2fa !== undefined) data.require_2fa = body.require_2fa === true || body.require_2fa === 1 || body.require_2fa === '1';

View File

@@ -89,7 +89,7 @@ export default async function ordersRoutes(fastify: FastifyInstance): Promise<vo
}
const result = await createOrderFromQuotation({ quotationId, customerOrderNumber, attachmentBuffer, attachmentName });
if ('error' in result) return error(reply, result.error, result.status);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({ request, authData: request.authData, action: 'create', entityType: 'order', entityId: result.data.order_id, description: `Vytvořena objednávka ${result.data.order_number} z nabídky #${result.data.quotationId}` });
return success(reply, { order_id: result.data.order_id, id: result.data.id, order_number: result.data.order_number }, 201, 'Objednávka byla vytvořena');
@@ -110,7 +110,7 @@ export default async function ordersRoutes(fastify: FastifyInstance): Promise<vo
}
const result = await createOrderFromQuotation({ quotationId, customerOrderNumber });
if ('error' in result) return error(reply, result.error, result.status);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({ request, authData: request.authData, action: 'create', entityType: 'order', entityId: result.data.order_id, description: `Vytvořena objednávka ${result.data.order_number} z nabídky #${result.data.quotationId}` });
return success(reply, { order_id: result.data.order_id, id: result.data.id, order_number: result.data.order_number }, 201, 'Objednávka byla vytvořena');
@@ -121,7 +121,7 @@ export default async function ordersRoutes(fastify: FastifyInstance): Promise<vo
if ('error' in manualParsed) return error(reply, manualParsed.error, 400);
const body = manualParsed.data;
const result = await createOrder(body);
const result = await createOrder(body as any);
await logAudit({ request, authData: request.authData, action: 'create', entityType: 'order', entityId: result.id, description: `Vytvořena objednávka ${result.order_number}` });
return success(reply, { id: result.id }, 201, 'Objednávka byla vytvořena');
@@ -133,8 +133,8 @@ export default async function ordersRoutes(fastify: FastifyInstance): Promise<vo
const parsed = parseBody(UpdateOrderSchema, request.body);
if ('error' in parsed) return error(reply, parsed.error, 400);
const result = await updateOrder(id, parsed.data);
if ('error' in result) return error(reply, result.error, result.status);
const result = await updateOrder(id, parsed.data as any);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({ request, authData: request.authData, action: 'update', entityType: 'order', entityId: id, description: `Upravena objednávka ${result.data.order_number}` });
return success(reply, { id }, 200, 'Objednávka byla uložena');
@@ -145,7 +145,7 @@ export default async function ordersRoutes(fastify: FastifyInstance): Promise<vo
if (id === null) return;
const result = await deleteOrder(id);
if ('error' in result) return error(reply, result.error, result.status);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({ request, authData: request.authData, action: 'delete', entityType: 'order', entityId: id, description: `Smazána objednávka ${result.data.order_number}` });
return success(reply, null, 200, 'Objednávka smazána');

View File

@@ -67,7 +67,7 @@ export default async function projectsRoutes(fastify: FastifyInstance): Promise<
userId: authData.userId,
firstName: authData.firstName,
lastName: authData.lastName,
content: parsed.data.content,
content: parsed.data.content ?? undefined,
});
return success(reply, { note }, 201, 'Poznámka byla přidána');

View File

@@ -46,7 +46,7 @@ export default async function usersRoutes(fastify: FastifyInstance): Promise<voi
is_active: body.is_active,
});
if ('error' in result) return error(reply, result.error, result.status);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({
request,
@@ -67,8 +67,12 @@ export default async function usersRoutes(fastify: FastifyInstance): Promise<voi
const parsed = parseBody(UpdateUserSchema, request.body);
if ('error' in parsed) return error(reply, parsed.error, 400);
const result = await updateUser(id, parsed.data);
if ('error' in result) return error(reply, result.error, result.status);
const userData = {
...parsed.data,
role_id: parsed.data.role_id != null ? Number(parsed.data.role_id) : parsed.data.role_id as number | null | undefined,
};
const result = await updateUser(id, userData);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({
request,
@@ -88,7 +92,7 @@ export default async function usersRoutes(fastify: FastifyInstance): Promise<voi
if (id === null) return;
const result = await deleteUser(id, request.authData?.userId);
if ('error' in result) return error(reply, result.error, result.status);
if ('error' in result) return error(reply, result.error!, result.status!);
await logAudit({
request,

View File

@@ -1,11 +1,11 @@
import { ZodSchema, ZodError } from 'zod';
import { ZodSchema, z } from 'zod';
export function parseBody<T>(schema: ZodSchema<T>, body: unknown): { data: T } | { error: string } {
try {
return { data: schema.parse(body) };
} catch (e) {
if (e instanceof ZodError) {
return { error: e.errors.map(err => err.message).join(', ') };
if (e instanceof z.ZodError) {
return { error: e.issues.map((err: z.ZodIssue) => err.message).join(', ') };
}
return { error: 'Neplatný požadavek' };
}

View File

@@ -1,7 +1,7 @@
import prisma from '../config/database';
import { generateSharedNumber } from './numbering.service';
interface OrderItemInput { description?: string; item_description?: string; quantity?: number; unit?: string; unit_price?: number; is_included_in_total?: boolean; position?: number }
interface OrderItemInput { description?: string | null; item_description?: string | null; quantity?: number; unit?: string | null; unit_price?: number; is_included_in_total?: boolean; position?: number }
interface OrderSectionInput { title?: string; title_cz?: string; content?: string; position?: number }
// Status transition rules matching PHP

View File

@@ -39,7 +39,7 @@ export async function listProjects(params: ListProjectsParams) {
...p,
customer_name: p.customers?.name || null,
responsible_user_name: p.users ? `${p.users.first_name} ${p.users.last_name}`.trim() : null,
order_number: p.orders?.[0]?.order_number || null,
order_number: (p.orders as any)?.order_number || null,
}));
return { data: enriched, total, page, limit };