658496320b
- Added new DTOs for correction requests and responses in `nama-provider.dto.ts`. - Updated `nama-provider.adapter.ts` to include `originalSend` and `correctionSend` methods. - Enhanced `nama-provider.util.ts` with mapping functions for correction requests. - Created operational guidelines for agents in `AGENT.md`. - Updated Prisma migrations to support new invoice types and relationships. - Introduced new service and DTO for creating sales invoices in `sale-invoice-create.service.ts` and `sale-invoice-create.dto.ts`. - Added utility for handling Prisma errors in `prisma-error.util.ts`.
22 lines
607 B
TypeScript
22 lines
607 B
TypeScript
import { randomBytes } from 'crypto'
|
|
import { PrismaErrorUtil } from './prisma-error.util'
|
|
|
|
export function generateTrackingCode(prefix: string, suffixLength: number) {
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
const bytes = randomBytes(suffixLength)
|
|
|
|
let suffix = ''
|
|
for (let i = 0; i < suffixLength; i++) {
|
|
suffix += chars[bytes[i] % chars.length]
|
|
}
|
|
|
|
return `${prefix}-${suffix}`
|
|
}
|
|
|
|
export function isTrackingCodeUniqueViolation(error: unknown) {
|
|
if (!PrismaErrorUtil.isCode(error, 'P2002')) {
|
|
return false
|
|
}
|
|
return PrismaErrorUtil.hasTarget(error, 'tracking_code')
|
|
}
|