manicanldes-backend/src/b2b/business.schemas.ts

64 lines
1.8 KiB
TypeScript

import { z } from 'zod';
import { text } from '../common/input';
import { pageSchema } from '../identity/identity.schemas';
const optionalText = (max: number) => text(max).nullable();
export const businessProfileSchema = z
.object({
legalName: text(160),
tradingName: optionalText(160),
registrationNumber: text(64, 3),
taxIdentifier: optionalText(64),
countryCode: z
.string()
.trim()
.toUpperCase()
.regex(/^[A-Z]{2}$/),
contactEmail: z
.email()
.max(254)
.transform((value) => value.toLowerCase()),
contactPhone: z
.string()
.trim()
.regex(/^\+?[0-9 ()-]{7,24}$/)
.nullable(),
billingLine1: text(200),
billingCity: text(100),
billingRegion: text(100),
billingPostalCode: text(20),
})
.strict();
export const createBusinessSchema = businessProfileSchema
.extend({
code: z
.string()
.trim()
.toUpperCase()
.max(32)
.regex(/^[A-Z0-9][A-Z0-9_-]*$/),
})
.strict();
export const updateBusinessSchema = businessProfileSchema
.partial()
.refine((value) => Object.keys(value).length > 0);
export const businessQuerySchema = pageSchema
.extend({
search: text(100).optional(),
})
.strict();
export const submitBusinessSchema = z
.object({ idempotencyKey: z.uuid() })
.strict();
export const decideBusinessSchema = submitBusinessSchema
.extend({
decision: z.enum(['APPROVED', 'REJECTED']),
note: text(500, 3),
})
.strict();
export type CreateBusinessInput = z.infer<typeof createBusinessSchema>;
export type UpdateBusinessInput = z.infer<typeof updateBusinessSchema>;
export type BusinessQuery = z.infer<typeof businessQuerySchema>;
export type SubmitBusinessInput = z.infer<typeof submitBusinessSchema>;
export type DecideBusinessInput = z.infer<typeof decideBusinessSchema>;