75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
|
|
import { z } from 'zod/v4';
|
||
|
|
|
||
|
|
export const CreatePurchaseItemSchema = z.object({
|
||
|
|
medicineProductId: z.string().optional(),
|
||
|
|
name: z.string().min(1).max(200).trim(),
|
||
|
|
quantity: z.number().positive(),
|
||
|
|
unit: z.string().min(1),
|
||
|
|
actualPrice: z.number().positive().optional(),
|
||
|
|
currency: z.string().min(1).max(10).optional(),
|
||
|
|
priceRecordId: z.string().optional(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const CreatePurchaseSchema = z.object({
|
||
|
|
storeId: z.string().min(1),
|
||
|
|
status: z.enum(['ordered', 'in_cabinet']).default('in_cabinet'),
|
||
|
|
items: z.array(CreatePurchaseItemSchema).min(1),
|
||
|
|
notes: z.string().max(1000).trim().optional(),
|
||
|
|
purchasedAt: z.iso.datetime().optional(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const UpdatePurchaseSchema = z.object({
|
||
|
|
notes: z.string().max(1000).trim().optional(),
|
||
|
|
items: z.array(CreatePurchaseItemSchema).min(1).optional(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const PurchaseItemResponseSchema = z.object({
|
||
|
|
_id: z.string(),
|
||
|
|
medicineProductId: z.string().optional(),
|
||
|
|
medicineId: z.string().optional(),
|
||
|
|
foodProductId: z.string().optional(),
|
||
|
|
name: z.string(),
|
||
|
|
quantity: z.number(),
|
||
|
|
unit: z.string(),
|
||
|
|
actualPrice: z.number().optional(),
|
||
|
|
currency: z.string().optional(),
|
||
|
|
priceRecordId: z.string().optional(),
|
||
|
|
addedToCabinet: z.boolean(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const PurchaseResponseSchema = z.object({
|
||
|
|
_id: z.string(),
|
||
|
|
householdId: z.string(),
|
||
|
|
storeId: z.string(),
|
||
|
|
storeName: z.string(),
|
||
|
|
status: z.enum(['ordered', 'in_cabinet']),
|
||
|
|
items: z.array(PurchaseItemResponseSchema),
|
||
|
|
notes: z.string().optional(),
|
||
|
|
purchasedAt: z.string(),
|
||
|
|
receivedAt: z.string().optional(),
|
||
|
|
createdBy: z.string(),
|
||
|
|
createdAt: z.string(),
|
||
|
|
updatedAt: z.string(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const PurchaseListResponseSchema = z.object({
|
||
|
|
data: z.array(PurchaseResponseSchema),
|
||
|
|
pagination: z.object({
|
||
|
|
cursor: z.string().nullable(),
|
||
|
|
hasMore: z.boolean(),
|
||
|
|
total: z.number().optional(),
|
||
|
|
}),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const PurchaseQuerySchema = z.object({
|
||
|
|
status: z.enum(['ordered', 'in_cabinet']).optional(),
|
||
|
|
storeId: z.string().optional(),
|
||
|
|
cursor: z.string().optional(),
|
||
|
|
limit: z.coerce.number().int().min(1).max(100).default(20),
|
||
|
|
});
|
||
|
|
|
||
|
|
export type CreatePurchaseItemInput = z.infer<typeof CreatePurchaseItemSchema>;
|
||
|
|
export type CreatePurchaseInput = z.infer<typeof CreatePurchaseSchema>;
|
||
|
|
export type UpdatePurchaseInput = z.infer<typeof UpdatePurchaseSchema>;
|
||
|
|
export type PurchaseQueryInput = z.infer<typeof PurchaseQuerySchema>;
|