- Introduced Zod DTOs for request validation across multiple controllers, replacing inline validation with structured classes for improved maintainability and clarity. - Updated ESLint configuration to enforce a rule against importing Zod directly in BFF controllers, promoting the use of shared domain schemas for request validation. - Removed the SecureErrorMapperService to streamline the security module, as its functionality was deemed unnecessary. - Enhanced various controllers to utilize the new DTOs, ensuring consistent validation and response handling across the application.
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
/**
|
|
* Payments Domain - Schemas
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
|
|
export const paymentMethodTypeSchema = z.enum([
|
|
"CreditCard",
|
|
"BankAccount",
|
|
"RemoteCreditCard",
|
|
"RemoteBankAccount",
|
|
"Manual",
|
|
]);
|
|
|
|
export const paymentMethodSchema = z.object({
|
|
id: z.number().int(),
|
|
type: paymentMethodTypeSchema,
|
|
description: z.string(),
|
|
gatewayName: z.string().optional(),
|
|
contactType: z.string().optional(),
|
|
contactId: z.number().int().optional(),
|
|
cardLastFour: z.string().optional(),
|
|
expiryDate: z.string().optional(),
|
|
startDate: z.string().optional(),
|
|
issueNumber: z.string().optional(),
|
|
cardType: z.string().optional(),
|
|
remoteToken: z.string().optional(),
|
|
lastUpdated: z.string().optional(),
|
|
bankName: z.string().optional(),
|
|
isDefault: z.boolean().optional(),
|
|
});
|
|
|
|
export const paymentMethodListSchema = z.object({
|
|
paymentMethods: z.array(paymentMethodSchema),
|
|
totalCount: z.number().int().min(0),
|
|
});
|
|
|
|
export const paymentGatewayTypeSchema = z.enum([
|
|
"merchant",
|
|
"thirdparty",
|
|
"tokenization",
|
|
"manual",
|
|
]);
|
|
|
|
export const paymentGatewaySchema = z.object({
|
|
name: z.string(),
|
|
displayName: z.string(),
|
|
type: paymentGatewayTypeSchema,
|
|
isActive: z.boolean(),
|
|
configuration: z.record(z.string(), z.unknown()).optional(),
|
|
});
|
|
|
|
export const paymentGatewayListSchema = z.object({
|
|
gateways: z.array(paymentGatewaySchema),
|
|
totalCount: z.number().int().min(0),
|
|
});
|
|
|
|
export const invoicePaymentLinkSchema = z.object({
|
|
url: z.string().url(),
|
|
expiresAt: z.string(),
|
|
gatewayName: z.string().optional(),
|
|
});
|
|
|
|
// ============================================================================
|
|
// Inferred Types from Schemas (Schema-First Approach)
|
|
// ============================================================================
|
|
|
|
export type PaymentMethodType = z.infer<typeof paymentMethodTypeSchema>;
|
|
export type PaymentMethod = z.infer<typeof paymentMethodSchema>;
|
|
export type PaymentMethodList = z.infer<typeof paymentMethodListSchema>;
|
|
export type PaymentGatewayType = z.infer<typeof paymentGatewayTypeSchema>;
|
|
export type PaymentGateway = z.infer<typeof paymentGatewaySchema>;
|
|
export type PaymentGatewayList = z.infer<typeof paymentGatewayListSchema>;
|
|
export type InvoicePaymentLink = z.infer<typeof invoicePaymentLinkSchema>;
|