source: src/schemas/invoice.ts@ 87c9f1e

main
Last change on this file since 87c9f1e was 87c9f1e, checked in by Naum Shapkarovski <naumshapkarovski@…>, 5 weeks ago

update the seed script. update the prisma schema, use mapping

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import { z } from 'zod';
2import { customerSchema, tenantSchema } from './customer';
3
4export const serviceSchema = z.object({
5 id: z.string(),
6 name: z.string(),
7 sprint: z.number(),
8 hour: z.number(),
9 month: z.number(),
10});
11
12export const invoiceTableFilterValueSchema = z
13 .union([z.string(), z.array(z.string()), z.date()])
14 .nullable();
15
16export const invoiceTableFiltersSchema = z.object({
17 name: z.string(),
18 service: z.array(z.string()),
19 status: z.string(),
20 startDate: z.date().nullable(),
21 endDate: z.date().nullable(),
22});
23
24export const invoiceItemSchema = z.object({
25 title: z.string(),
26 price: z.number(),
27 total: z.number(),
28 service: serviceSchema,
29 quantity: z.number(),
30 description: z.string(),
31});
32
33export const invoiceStatusSchema = z.union([
34 z.literal('draft'),
35 z.literal('processing'),
36 z.literal('pending'),
37 z.literal('overdue'),
38 z.literal('paid'),
39]);
40
41export const monthSchema = z.union([
42 z.literal('January'),
43 z.literal('February'),
44 z.literal('March'),
45 z.literal('April'),
46 z.literal('May'),
47 z.literal('June'),
48 z.literal('July'),
49 z.literal('August'),
50 z.literal('September'),
51 z.literal('October'),
52 z.literal('November'),
53 z.literal('December'),
54]);
55
56export const invoiceSchema = z.object({
57 id: z.string(),
58 sent: z.number().optional(),
59 dueDate: z.coerce.date(),
60 status: invoiceStatusSchema,
61 currency: z.union([z.literal('EUR'), z.literal('USD')]),
62 quantityType: z.union([
63 z.literal('Unit'),
64 z.literal('Hour'),
65 z.literal('Sprint'),
66 z.literal('Month'),
67 ]),
68 subTotal: z.number(),
69 issueDate: z.coerce.date(),
70 month: monthSchema,
71 discount: z.number().optional(),
72 taxes: z.number().optional(),
73 totalAmount: z.number(),
74 invoiceNumber: z.string(),
75 items: z.array(invoiceItemSchema),
76 invoiceFrom: tenantSchema,
77 invoiceTo: customerSchema,
78 pdfRef: z.string().optional(),
79});
80
81export const updateInvoiceSchema = invoiceSchema.omit({
82 id: true,
83 sent: true,
84});
85
86export const createInvoiceSchema = invoiceSchema.omit({
87 id: true,
88 sent: true,
89});
90
91export interface InvoiceFilters {
92 name: string;
93 service: string[];
94 status: string;
95 startDate: Date | null;
96 endDate: Date | null;
97 where?: [string, string, any][];
98}
Note: See TracBrowser for help on using the repository browser.