simple-kiosk/src/schema.ts
2024-05-03 01:19:24 +09:00

47 lines
1.3 KiB
TypeScript

import { z } from "zod";
export const addNewMenuItemSchema = z.object({
HOT: z.number().nullable(),
COLD: z.number().nullable(),
price: z.number().nullable(),
category: z.string(),
});
export type AddNewMenuItemType = z.infer<typeof addNewMenuItemSchema>;
export const updateMenuItemSchema = z.object({
HOT: z.number().nullable().optional(),
COLD: z.number().nullable().optional(),
price: z.number().nullable().optional(),
category: z.string().optional(),
});
export type UpdateMenuItemType = z.infer<typeof updateMenuItemSchema>;
const paymentMethodSchema = z.enum(["account", "cash"]);
export type PaymentMethod = z.infer<typeof paymentMethodSchema>;
/**
* SQLite has no Boolean datatype. Use cast(true|false|SqliteBoolean).
* https://www.sqlite.org/quirks.html#no_separate_boolean_datatype
*/
export const SqliteBooleanSchema = z
.union([z.literal(0), z.literal(1)]);
export type SqliteBoolean = z.infer<typeof SqliteBooleanSchema>;
const orderSchema = z.object({
name: z.string(),
quantity: z.number(),
price: z.number(),
HOT: SqliteBooleanSchema,
});
export type OrderType = z.infer<typeof orderSchema>;
export const addNewOrderSchema = z.object({
orders: z.array(orderSchema),
payment: paymentMethodSchema,
});
export type AddNewOrderType = z.infer<typeof addNewOrderSchema>;