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:
@@ -34,7 +34,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
|
|||||||
const body = parsed.data;
|
const body = parsed.data;
|
||||||
|
|
||||||
const result = await attendanceService.saveNotes(authData.userId, body.notes ? String(body.notes) : null);
|
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');
|
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 body = parsed.data;
|
||||||
|
|
||||||
const result = await attendanceService.updateAddress(authData.userId, body.address ?? null, body.punch_action);
|
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');
|
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 newProjectId = body.project_id ? Number(body.project_id) : null;
|
||||||
const result = await attendanceService.switchProject(authData.userId, newProjectId);
|
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');
|
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,
|
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({
|
await logAudit({
|
||||||
request, authData, action: 'update', entityType: 'leave_balance',
|
request, authData, action: 'update', entityType: 'leave_balance',
|
||||||
@@ -220,10 +220,10 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
|
|||||||
date_to: leaveBody.date_to,
|
date_to: leaveBody.date_to,
|
||||||
leave_type: leaveBody.leave_type,
|
leave_type: leaveBody.leave_type,
|
||||||
leave_hours: leaveBody.leave_hours,
|
leave_hours: leaveBody.leave_hours,
|
||||||
notes: leaveBody.notes,
|
notes: leaveBody.notes ?? undefined,
|
||||||
}, authData.userId);
|
}, 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!);
|
return success(reply, { created: result.created }, 200, result.message!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +241,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
|
|||||||
address: punchBody.address,
|
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({
|
await logAudit({
|
||||||
request, authData, action: result.auditAction, entityType: 'attendance',
|
request, authData, action: result.auditAction, entityType: 'attendance',
|
||||||
@@ -303,14 +303,14 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
|
|||||||
departure_time: body.departure_time,
|
departure_time: body.departure_time,
|
||||||
break_start: body.break_start,
|
break_start: body.break_start,
|
||||||
break_end: body.break_end,
|
break_end: body.break_end,
|
||||||
notes: body.notes,
|
notes: body.notes ?? undefined,
|
||||||
project_id: body.project_id,
|
project_id: body.project_id != null ? Number(body.project_id) : (body.project_id as number | null | undefined),
|
||||||
leave_type: body.leave_type,
|
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,
|
project_logs: body.project_logs,
|
||||||
}, authData.userId, isAdmin);
|
}, 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({
|
await logAudit({
|
||||||
request,
|
request,
|
||||||
@@ -330,7 +330,7 @@ export default async function attendanceRoutes(fastify: FastifyInstance): Promis
|
|||||||
if (id === null) return;
|
if (id === null) return;
|
||||||
|
|
||||||
const result = await attendanceService.deleteAttendance(id);
|
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({
|
await logAudit({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -153,8 +153,9 @@ export default async function companySettingsRoutes(fastify: FastifyInstance): P
|
|||||||
|
|
||||||
const data: Record<string, unknown> = { modified_at: new Date() };
|
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 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) {
|
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.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';
|
if (body.require_2fa !== undefined) data.require_2fa = body.require_2fa === true || body.require_2fa === 1 || body.require_2fa === '1';
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export default async function ordersRoutes(fastify: FastifyInstance): Promise<vo
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await createOrderFromQuotation({ quotationId, customerOrderNumber, attachmentBuffer, attachmentName });
|
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}` });
|
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');
|
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 });
|
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}` });
|
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');
|
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);
|
if ('error' in manualParsed) return error(reply, manualParsed.error, 400);
|
||||||
const body = manualParsed.data;
|
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}` });
|
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');
|
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);
|
const parsed = parseBody(UpdateOrderSchema, request.body);
|
||||||
if ('error' in parsed) return error(reply, parsed.error, 400);
|
if ('error' in parsed) return error(reply, parsed.error, 400);
|
||||||
|
|
||||||
const result = await updateOrder(id, parsed.data);
|
const result = await updateOrder(id, parsed.data as any);
|
||||||
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: 'update', entityType: 'order', entityId: id, description: `Upravena objednávka ${result.data.order_number}` });
|
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');
|
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;
|
if (id === null) return;
|
||||||
|
|
||||||
const result = await deleteOrder(id);
|
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}` });
|
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');
|
return success(reply, null, 200, 'Objednávka smazána');
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default async function projectsRoutes(fastify: FastifyInstance): Promise<
|
|||||||
userId: authData.userId,
|
userId: authData.userId,
|
||||||
firstName: authData.firstName,
|
firstName: authData.firstName,
|
||||||
lastName: authData.lastName,
|
lastName: authData.lastName,
|
||||||
content: parsed.data.content,
|
content: parsed.data.content ?? undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return success(reply, { note }, 201, 'Poznámka byla přidána');
|
return success(reply, { note }, 201, 'Poznámka byla přidána');
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default async function usersRoutes(fastify: FastifyInstance): Promise<voi
|
|||||||
is_active: body.is_active,
|
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({
|
await logAudit({
|
||||||
request,
|
request,
|
||||||
@@ -67,8 +67,12 @@ export default async function usersRoutes(fastify: FastifyInstance): Promise<voi
|
|||||||
const parsed = parseBody(UpdateUserSchema, request.body);
|
const parsed = parseBody(UpdateUserSchema, request.body);
|
||||||
if ('error' in parsed) return error(reply, parsed.error, 400);
|
if ('error' in parsed) return error(reply, parsed.error, 400);
|
||||||
|
|
||||||
const result = await updateUser(id, parsed.data);
|
const userData = {
|
||||||
if ('error' in result) return error(reply, result.error, result.status);
|
...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({
|
await logAudit({
|
||||||
request,
|
request,
|
||||||
@@ -88,7 +92,7 @@ export default async function usersRoutes(fastify: FastifyInstance): Promise<voi
|
|||||||
if (id === null) return;
|
if (id === null) return;
|
||||||
|
|
||||||
const result = await deleteUser(id, request.authData?.userId);
|
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({
|
await logAudit({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -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 } {
|
export function parseBody<T>(schema: ZodSchema<T>, body: unknown): { data: T } | { error: string } {
|
||||||
try {
|
try {
|
||||||
return { data: schema.parse(body) };
|
return { data: schema.parse(body) };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ZodError) {
|
if (e instanceof z.ZodError) {
|
||||||
return { error: e.errors.map(err => err.message).join(', ') };
|
return { error: e.issues.map((err: z.ZodIssue) => err.message).join(', ') };
|
||||||
}
|
}
|
||||||
return { error: 'Neplatný požadavek' };
|
return { error: 'Neplatný požadavek' };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import prisma from '../config/database';
|
import prisma from '../config/database';
|
||||||
import { generateSharedNumber } from './numbering.service';
|
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 }
|
interface OrderSectionInput { title?: string; title_cz?: string; content?: string; position?: number }
|
||||||
|
|
||||||
// Status transition rules matching PHP
|
// Status transition rules matching PHP
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export async function listProjects(params: ListProjectsParams) {
|
|||||||
...p,
|
...p,
|
||||||
customer_name: p.customers?.name || null,
|
customer_name: p.customers?.name || null,
|
||||||
responsible_user_name: p.users ? `${p.users.first_name} ${p.users.last_name}`.trim() : 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 };
|
return { data: enriched, total, page, limit };
|
||||||
|
|||||||
Reference in New Issue
Block a user