forked from TomDoesTech/Testing-Express-REST-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct.schema.ts
More file actions
47 lines (41 loc) · 1.09 KB
/
Copy pathproduct.schema.ts
File metadata and controls
47 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { object, number, string, TypeOf } from "zod";
const payload = {
body: object({
title: string({
required_error: "Title is required",
}),
description: string({
required_error: "Description is required",
}).min(120, "Description should be at least 120 characters long"),
price: number({
required_error: "Price is required",
}),
image: string({
required_error: "Image is required",
}),
}),
};
const params = {
params: object({
productId: string({
required_error: "productId is required",
}),
}),
};
export const createProductSchema = object({
...payload,
});
export const updateProductSchema = object({
...payload,
...params,
});
export const deleteProductSchema = object({
...params,
});
export const getProductSchema = object({
...params,
});
export type CreateProductInput = TypeOf<typeof createProductSchema>;
export type UpdateProductInput = TypeOf<typeof updateProductSchema>;
export type ReadProductInput = TypeOf<typeof getProductSchema>;
export type DeleteProductInput = TypeOf<typeof deleteProductSchema>;