94 lines
2.6 KiB
TypeScript
94 lines
2.6 KiB
TypeScript
/**
|
|
* Billing Domain - Schemas
|
|
*
|
|
* Zod validation schemas for billing domain types.
|
|
* Used for runtime validation of data from any source.
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
|
|
// Invoice Status Schema
|
|
export const invoiceStatusSchema = z.enum([
|
|
"Draft",
|
|
"Pending",
|
|
"Paid",
|
|
"Unpaid",
|
|
"Overdue",
|
|
"Cancelled",
|
|
"Refunded",
|
|
"Collections",
|
|
]);
|
|
|
|
// Invoice Item Schema
|
|
export const invoiceItemSchema = z.object({
|
|
id: z.number().int().positive("Invoice item id must be positive"),
|
|
description: z.string().min(1, "Description is required"),
|
|
amount: z.number(),
|
|
quantity: z.number().int().positive("Quantity must be positive").optional(),
|
|
type: z.string().min(1, "Item type is required"),
|
|
serviceId: z.number().int().positive().optional(),
|
|
});
|
|
|
|
// Invoice Schema
|
|
export const invoiceSchema = z.object({
|
|
id: z.number().int().positive("Invoice id must be positive"),
|
|
number: z.string().min(1, "Invoice number is required"),
|
|
status: invoiceStatusSchema,
|
|
currency: z.string().min(1, "Currency is required"),
|
|
currencySymbol: z.string().min(1, "Currency symbol is required").optional(),
|
|
total: z.number(),
|
|
subtotal: z.number(),
|
|
tax: z.number(),
|
|
issuedAt: z.string().optional(),
|
|
dueDate: z.string().optional(),
|
|
paidDate: z.string().optional(),
|
|
pdfUrl: z.string().optional(),
|
|
paymentUrl: z.string().optional(),
|
|
description: z.string().optional(),
|
|
items: z.array(invoiceItemSchema).optional(),
|
|
daysOverdue: z.number().int().nonnegative().optional(),
|
|
});
|
|
|
|
// Invoice Pagination Schema
|
|
export const invoicePaginationSchema = z.object({
|
|
page: z.number().int().nonnegative(),
|
|
totalPages: z.number().int().nonnegative(),
|
|
totalItems: z.number().int().nonnegative(),
|
|
nextCursor: z.string().optional(),
|
|
});
|
|
|
|
// Invoice List Schema
|
|
export const invoiceListSchema = z.object({
|
|
invoices: z.array(invoiceSchema),
|
|
pagination: invoicePaginationSchema,
|
|
});
|
|
|
|
// Invoice SSO Link Schema
|
|
export const invoiceSsoLinkSchema = z.object({
|
|
url: z.string().url(),
|
|
expiresAt: z.string(),
|
|
});
|
|
|
|
// Payment Invoice Request Schema
|
|
export const paymentInvoiceRequestSchema = z.object({
|
|
invoiceId: z.number().int().positive(),
|
|
paymentMethodId: z.number().int().positive().optional(),
|
|
gatewayName: z.string().optional(),
|
|
amount: z.number().positive().optional(),
|
|
});
|
|
|
|
// Billing Summary Schema
|
|
export const billingSummarySchema = z.object({
|
|
totalOutstanding: z.number(),
|
|
totalOverdue: z.number(),
|
|
totalPaid: z.number(),
|
|
currency: z.string(),
|
|
currencySymbol: z.string().optional(),
|
|
invoiceCount: z.object({
|
|
total: z.number().int().min(0),
|
|
unpaid: z.number().int().min(0),
|
|
overdue: z.number().int().min(0),
|
|
paid: z.number().int().min(0),
|
|
}),
|
|
});
|