-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschemas.ts
More file actions
200 lines (168 loc) · 5.11 KB
/
schemas.ts
File metadata and controls
200 lines (168 loc) · 5.11 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import { z } from "zod";
export const UserIDSchema = z.number();
export const GUIDSchema = z.string();
export const IDTokenSchema = z.string();
//TODO: make z.union([
// MALE
// FEMALE
// OTHER
// SECRET
// ])
export const NameSchema = z
.string()
.min(1, { message: "名前は1文字以上です" })
.max(10, { message: "名前は10文字以下です" });
export const PictureUrlSchema = z.string().url().min(1, "画像を選択して下さい");
export const GenderSchema = z
.string()
.min(1, { message: "性別を入力して下さい" });
export const HobbySchema = z
.string()
// .min(1, { message: "趣味は1文字以上です" })
.max(25, { message: "趣味は25文字以下です" });
export const IntroShortSchema = z
.string()
.min(2, { message: "コメントは2文字以上です" })
.max(25, { message: "コメントは25文字以下です" });
export const IntroLongSchema = z
.string()
// .min(2, { message: "自己紹介文は2文字以上です" })
.max(225, { message: "自己紹介文は225文字以下です" });
export const UserSchema = z.object({
id: UserIDSchema,
guid: GUIDSchema,
name: NameSchema,
gender: GenderSchema,
grade: z.string().min(1, { message: "学年を入力して下さい" }),
faculty: z.string().min(1, { message: "学部を入力して下さい" }), // TODO: validate this further
department: z.string().min(1, { message: "学科を入力して下さい" }), // same
intro: z.string().max(150, { message: "自己紹介文は150文字以下です" }),
pictureUrl: z.string(),
});
export const RelationshipStatusSchema = z.union([
z.literal("PENDING"),
z.literal("MATCHED"),
z.literal("REJECTED"),
]);
export const InitUserSchema = UserSchema.omit({ id: true });
export const UpdateUserSchema = InitUserSchema.omit({ guid: true });
export const Step1UserSchema = UpdateUserSchema.omit({ pictureUrl: true });
export const RelationshipIDSchema = z.number();
export const RelationshipSchema = z.object({
id: z.number(),
sendingUserId: UserIDSchema,
receivingUserId: UserIDSchema,
status: RelationshipStatusSchema,
});
export const CourseIDSchema = z.string();
export const InterestSubjectIDSchema = z.number();
export const DaySchema = z.enum([
"mon",
"tue",
"wed",
"thu",
"fri",
"sat",
"sun",
"other",
]);
export const PeriodSchema = z.number().min(0).max(6);
export const SlotSchema = z.object({
day: DaySchema,
period: PeriodSchema,
courseId: CourseIDSchema,
});
export const CourseSchema = z.object({
id: CourseIDSchema,
name: z.string(),
teacher: z.string(),
slots: SlotSchema.array(),
});
export const EnrollmentSchema = z.object({
id: z.number(),
userId: UserIDSchema,
courseId: CourseIDSchema,
});
export const InterestSubjectSchema = z.object({
id: InterestSubjectIDSchema,
name: z.string(),
group: z.string(),
});
export const InterestSchema = z.object({
userId: UserIDSchema,
subjectId: InterestSubjectIDSchema,
});
export const UserWithCoursesAndSubjectsSchema = UserSchema.extend({
courses: CourseSchema.array(),
interestSubjects: InterestSubjectSchema.array(),
});
export const MessageIDSchema = z.number(); // TODO! Add __internal_prevent_cast_MessageID: PhantomData
export const ShareRoomIDSchema = z.number();
export const ContentSchema = z
.string()
.min(1, { message: "Content must not be empty." })
.max(255, { message: "Content is too big" });
export const MessageSchema = z.object({
id: MessageIDSchema,
creator: UserIDSchema,
createdAt: z.date(),
content: ContentSchema,
isPicture: z.boolean(),
edited: z.boolean(),
});
export const SendMessageSchema = z.object({
content: z.string().min(1, { message: "Content must not be empty." }),
});
export const MatchingStatusSchema = z.union([
z.literal("myRequest"),
z.literal("otherRequest"),
z.literal("matched"),
]);
export const DMOverviewSchema = z.object({
isDM: z.literal(true),
matchingStatus: MatchingStatusSchema,
friendId: UserIDSchema,
name: NameSchema,
thumbnail: z.string(),
lastMsg: MessageSchema.optional(),
unreadMessages: z.number(),
});
export const SharedRoomOverviewSchema = z.object({
isDM: z.literal(false),
roomId: ShareRoomIDSchema,
name: NameSchema,
thumbnail: z.string(),
lastMsg: MessageSchema.optional(),
});
export const RoomOverviewSchema = z.union([
SharedRoomOverviewSchema,
DMOverviewSchema,
]);
export const DMRoomSchema = z.object({
id: RelationshipIDSchema,
isDM: z.literal(true),
messages: z.array(MessageSchema),
});
export const PersonalizedDMRoomSchema = z.object({
name: NameSchema,
thumbnail: z.string(),
matchingStatus: MatchingStatusSchema,
unreadMessages: z.number(),
friendId: z.number(),
});
export const SharedRoomSchema = z.object({
id: ShareRoomIDSchema,
thumbnail: z.string(),
name: NameSchema,
isDM: z.literal(false),
members: z.array(UserIDSchema),
messages: z.array(MessageSchema),
});
export const InitRoomSchema = SharedRoomSchema.omit({ id: true });
export const InitSharedRoomSchema = InitRoomSchema.extend({
isDM: z.literal(false),
});
export const UpdateRoomSchema = z.object({
name: NameSchema,
pictureUrl: PictureUrlSchema,
});