-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIUser.ts
45 lines (40 loc) · 1.09 KB
/
IUser.ts
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
import z from "zod";
export const UserRegSchema = z.object({
email: z.string().email().nonempty(),
password: z.string().nonempty(),
firstName: z.string().nonempty(),
lastName: z.string().nonempty(),
});
// extract the inferred type
export type UserReg = z.infer<typeof UserRegSchema>;
// f
export const AddressTypeSchema = z.object({
address: z.any(),
preferred: z.boolean(),
id: z.string(),
});
export const IUserSchema = UserRegSchema.merge(
z.object({
_id: z.string().nonempty(),
dob: z.string().optional(),
addresses: AddressTypeSchema.optional(),
stripeId: z.string().optional(),
photoUrl: z.string().optional(),
createdAt: z.date(),
updatedAt: z.date(),
})
).omit({ password: true });
export const IUserUpdateSchema = IUserSchema.omit({
_id: true,
createdAt: true,
updatedAt: true,
})
.partial()
.transform((val) => ({ ...val, updatedAt: new Date() }));
export type IUser = z.infer<typeof IUserSchema>;
export type IUserUpdate = z.infer<typeof IUserUpdateSchema>;
export type AddressType = {
address: any;
preferred: boolean;
id: string;
};