first commit
This commit is contained in:
35
apps/backend/src/modules/transactions/transactions.schema.ts
Normal file
35
apps/backend/src/modules/transactions/transactions.schema.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const baseTransactionSchema = z.object({
|
||||
title: z.string().min(1),
|
||||
amount: z.coerce.number().min(0),
|
||||
currency: z.string().length(3).default('CNY'),
|
||||
category: z.string().min(1),
|
||||
type: z.enum(['expense', 'income']),
|
||||
source: z.enum(['manual', 'notification', 'ocr', 'ai']).default('manual'),
|
||||
status: z.enum(['pending', 'confirmed', 'rejected']).default('confirmed'),
|
||||
occurredAt: z.coerce.date(),
|
||||
notes: z.string().max(300).optional(),
|
||||
metadata: z.record(z.any()).optional(),
|
||||
userId: z.string().optional()
|
||||
});
|
||||
|
||||
export const createTransactionSchema = baseTransactionSchema;
|
||||
|
||||
export const updateTransactionSchema = baseTransactionSchema.partial();
|
||||
|
||||
export const transactionIdSchema = z.object({
|
||||
id: z.string().min(1)
|
||||
});
|
||||
|
||||
export const notificationSchema = z.object({
|
||||
packageName: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
body: z.string().min(1),
|
||||
receivedAt: z.coerce.date(),
|
||||
signature: z.string().min(32),
|
||||
extras: z.record(z.any()).optional()
|
||||
});
|
||||
|
||||
export type CreateTransactionInput = z.infer<typeof createTransactionSchema>;
|
||||
export type UpdateTransactionInput = z.infer<typeof updateTransactionSchema>;
|
||||
Reference in New Issue
Block a user