-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.ts
More file actions
116 lines (109 loc) · 3.41 KB
/
schema.ts
File metadata and controls
116 lines (109 loc) · 3.41 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { z } from "zod";
export const registrationSchema = z.object({
fname: z
.string({ message: "name cannot be left empty" })
.trim()
.min(2, { message: "first name is atleast two characters" }),
lname: z.string().optional(),
email: z
.string({ message: "email cannot be left empty" })
.trim()
.email({ message: "email is incorrect" }),
password: z
.string({ message: "password cannot be empty" })
.min(8, { message: "password cannot be smaller than 8" })
.regex(/[A-Z]/, {
message: "password must have at least one uppercase letter",
})
.regex(/[\W_]/, {
message: "password must have at least one special character",
}),
});
export const todoSchema = z.object({
title: z
.string({ message: "title cannot be left empty" })
.trim()
.min(1, { message: "title cannot be left empty" }),
description: z.string().optional(),
priority: z.enum(["Low", "Medium", "High"], {
errorMap: () => ({ message: "priority must be one of: low, medium, high" }),
}),
dtstart: z.date({ message: "start date is not identified" }),
due: z.date({ message: "end date is not identified" }),
rrule: z.string().nullable(),
listID: z.string().nullable().optional(),
});
export const todoInstanceSchema = z.object({
title: z
.string({ message: "title cannot be left empty" })
.trim()
.min(1, { message: "title cannot be left empty" }),
description: z.string().optional(),
priority: z.enum(["Low", "Medium", "High"], {
errorMap: () => ({ message: "priority must be one of: low, medium, high" }),
}),
dtstart: z.date({ message: "start date is not identified" }),
due: z.date({ message: "end date is not identified" }),
instanceDate: z.date({ message: "instance date is not identified" }),
rrule: z.string().nullable(),
});
export const noteSchema = z.object({
name: z
.string({ message: "title cannot be left empty" })
.trim()
.min(1, { message: "title cannot be left empty" }),
content: z.string().nullable().optional(),
});
const listColorValues = [
"RED",
"ORANGE",
"YELLOW",
"LIME",
"BLUE",
"PURPLE",
"PINK",
"TEAL",
"CORAL",
"GOLD",
"DEEP_BLUE",
"ROSE",
"LIGHT_RED",
"BRICK",
"SLATE",
] as const;
const listBaseSchema = z.object({
id: z.string({ message: "id cannot be left empty" }),
name: z
.string({ message: "title cannot be left empty" })
.trim()
.min(1, { message: "title cannot be left empty" }),
color: z.enum(listColorValues).nullable(),
iconKey: z.string().trim().min(1).nullable().optional(),
});
export const listCreateSchema = listBaseSchema.pick({
name: true,
}).extend({
color: z.enum(listColorValues).optional(),
iconKey: z.string().trim().min(1).max(64).optional(),
});
export type ListColorType = (typeof listColorValues)[number];
export const listPatchSchema = listBaseSchema.partial().extend({
name: z
.string({ message: "title cannot be left empty" })
.trim()
.min(1, { message: "title cannot be left empty" })
.optional(),
color: z.enum(listColorValues).optional(),
iconKey: z.string().trim().min(1).max(64).optional(),
});
export const userPreferencesSchema = z.object({
sortBy: z
.enum(["dtstart", "due", "duration", "priority"])
.nullable()
.optional(),
groupBy: z
.enum(["dtstart", "due", "duration", "priority", "rrule", "list"])
.nullable()
.optional(),
direction: z.enum(["Ascending", "Descending"]).nullable().optional(),
});