export function generateCustomerNumber(): string { const timestamp = Date.now().toString(36).toUpperCase(); const random = Math.random().toString(36).substring(2, 6).toUpperCase(); return `K${timestamp}${random}`; } export function generateContractNumber(type: string | null | undefined): string { // Defensiv: ohne validen Type-String fällt der Prefix auf "CON" zurück. // Pentest Runde 12: POST /contracts ohne `type` warf // "Cannot read properties of undefined (reading 'substring')". const safeType = (typeof type === 'string' && type.length > 0) ? type : 'CON'; const prefix = safeType.substring(0, 3).toUpperCase(); const timestamp = Date.now().toString(36).toUpperCase(); const random = Math.random().toString(36).substring(2, 5).toUpperCase(); return `${prefix}-${timestamp}${random}`; } export function paginate(page: number = 1, limit: number = 20) { const skip = (page - 1) * limit; return { skip, take: limit }; } export function buildPaginationResponse( page: number, limit: number, total: number ) { return { page, limit, total, totalPages: Math.ceil(total / limit), }; }