@studious-lms/server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +8 -0
- package/README.md +143 -0
- package/dist/exportType.d.ts +9 -0
- package/dist/exportType.d.ts.map +1 -0
- package/dist/exportType.js +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/lib/fileUpload.d.ts +38 -0
- package/dist/lib/fileUpload.d.ts.map +1 -0
- package/dist/lib/fileUpload.js +136 -0
- package/dist/lib/googleCloudStorage.d.ts +20 -0
- package/dist/lib/googleCloudStorage.d.ts.map +1 -0
- package/dist/lib/googleCloudStorage.js +88 -0
- package/dist/lib/prisma.d.ts +8 -0
- package/dist/lib/prisma.d.ts.map +1 -0
- package/dist/lib/prisma.js +11 -0
- package/dist/lib/thumbnailGenerator.d.ts +23 -0
- package/dist/lib/thumbnailGenerator.d.ts.map +1 -0
- package/dist/lib/thumbnailGenerator.js +180 -0
- package/dist/logger.d.ts +26 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +135 -0
- package/dist/middleware/auth.d.ts +7 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +170 -0
- package/dist/middleware/logging.d.ts +2 -0
- package/dist/middleware/logging.d.ts.map +1 -0
- package/dist/middleware/logging.js +51 -0
- package/dist/routers/_app.d.ts +4369 -0
- package/dist/routers/_app.d.ts.map +1 -0
- package/dist/routers/_app.js +29 -0
- package/dist/routers/agenda.d.ts +66 -0
- package/dist/routers/agenda.d.ts.map +1 -0
- package/dist/routers/agenda.js +78 -0
- package/dist/routers/announcement.d.ts +79 -0
- package/dist/routers/announcement.d.ts.map +1 -0
- package/dist/routers/announcement.js +122 -0
- package/dist/routers/assignment.d.ts +1051 -0
- package/dist/routers/assignment.d.ts.map +1 -0
- package/dist/routers/assignment.js +1497 -0
- package/dist/routers/attendance.d.ts +99 -0
- package/dist/routers/attendance.d.ts.map +1 -0
- package/dist/routers/attendance.js +269 -0
- package/dist/routers/auth.d.ts +87 -0
- package/dist/routers/auth.d.ts.map +1 -0
- package/dist/routers/auth.js +255 -0
- package/dist/routers/class.d.ts +427 -0
- package/dist/routers/class.d.ts.map +1 -0
- package/dist/routers/class.js +693 -0
- package/dist/routers/event.d.ts +249 -0
- package/dist/routers/event.d.ts.map +1 -0
- package/dist/routers/event.js +467 -0
- package/dist/routers/file.d.ts +27 -0
- package/dist/routers/file.d.ts.map +1 -0
- package/dist/routers/file.js +88 -0
- package/dist/routers/section.d.ts +51 -0
- package/dist/routers/section.d.ts.map +1 -0
- package/dist/routers/section.js +123 -0
- package/dist/routers/user.d.ts +49 -0
- package/dist/routers/user.d.ts.map +1 -0
- package/dist/routers/user.js +74 -0
- package/dist/socket/handlers.d.ts +3 -0
- package/dist/socket/handlers.d.ts.map +1 -0
- package/dist/socket/handlers.js +130 -0
- package/dist/trpc.d.ts +147 -0
- package/dist/trpc.d.ts.map +1 -0
- package/dist/trpc.js +67 -0
- package/dist/types/trpc.d.ts +16 -0
- package/dist/types/trpc.d.ts.map +1 -0
- package/dist/types/trpc.js +2 -0
- package/dist/utils/email.d.ts +3 -0
- package/dist/utils/email.d.ts.map +1 -0
- package/dist/utils/email.js +16 -0
- package/dist/utils/generateInviteCode.d.ts +6 -0
- package/dist/utils/generateInviteCode.d.ts.map +1 -0
- package/dist/utils/generateInviteCode.js +11 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +124 -0
- package/generated/prisma/client.d.ts +1 -0
- package/generated/prisma/client.js +4 -0
- package/generated/prisma/default.d.ts +1 -0
- package/generated/prisma/default.js +4 -0
- package/generated/prisma/edge.d.ts +1 -0
- package/generated/prisma/edge.js +389 -0
- package/generated/prisma/index-browser.js +375 -0
- package/generated/prisma/index.d.ts +34865 -0
- package/generated/prisma/index.js +410 -0
- package/generated/prisma/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/generated/prisma/package.json +140 -0
- package/generated/prisma/runtime/edge-esm.js +34 -0
- package/generated/prisma/runtime/edge.js +34 -0
- package/generated/prisma/runtime/index-browser.d.ts +370 -0
- package/generated/prisma/runtime/index-browser.js +16 -0
- package/generated/prisma/runtime/library.d.ts +3647 -0
- package/generated/prisma/runtime/library.js +146 -0
- package/generated/prisma/runtime/react-native.js +83 -0
- package/generated/prisma/runtime/wasm.js +35 -0
- package/generated/prisma/schema.prisma +304 -0
- package/generated/prisma/wasm.d.ts +1 -0
- package/generated/prisma/wasm.js +375 -0
- package/package.json +46 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eventRouter = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const trpc_1 = require("../trpc");
|
|
6
|
+
const server_1 = require("@trpc/server");
|
|
7
|
+
const prisma_1 = require("@lib/prisma");
|
|
8
|
+
const date_fns_1 = require("date-fns");
|
|
9
|
+
const eventSchema = zod_1.z.object({
|
|
10
|
+
name: zod_1.z.string().optional(),
|
|
11
|
+
location: zod_1.z.string().optional(),
|
|
12
|
+
remarks: zod_1.z.string().optional(),
|
|
13
|
+
startTime: zod_1.z.string(),
|
|
14
|
+
endTime: zod_1.z.string(),
|
|
15
|
+
classId: zod_1.z.string().optional(),
|
|
16
|
+
color: zod_1.z.string().optional(),
|
|
17
|
+
});
|
|
18
|
+
exports.eventRouter = (0, trpc_1.createTRPCRouter)({
|
|
19
|
+
get: trpc_1.protectedProcedure
|
|
20
|
+
.input(zod_1.z.object({
|
|
21
|
+
id: zod_1.z.string(),
|
|
22
|
+
}))
|
|
23
|
+
.query(async ({ ctx, input }) => {
|
|
24
|
+
if (!ctx.user) {
|
|
25
|
+
throw new server_1.TRPCError({
|
|
26
|
+
code: "UNAUTHORIZED",
|
|
27
|
+
message: "You must be logged in to get an event",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const event = await prisma_1.prisma.event.findUnique({
|
|
31
|
+
where: { id: input.id },
|
|
32
|
+
include: {
|
|
33
|
+
class: true,
|
|
34
|
+
user: true,
|
|
35
|
+
assignmentsAttached: {
|
|
36
|
+
select: {
|
|
37
|
+
id: true,
|
|
38
|
+
title: true,
|
|
39
|
+
instructions: true,
|
|
40
|
+
dueDate: true,
|
|
41
|
+
type: true,
|
|
42
|
+
graded: true,
|
|
43
|
+
maxGrade: true,
|
|
44
|
+
weight: true,
|
|
45
|
+
attachments: {
|
|
46
|
+
select: {
|
|
47
|
+
id: true,
|
|
48
|
+
name: true,
|
|
49
|
+
type: true,
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
section: {
|
|
53
|
+
select: {
|
|
54
|
+
id: true,
|
|
55
|
+
name: true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
teacher: {
|
|
59
|
+
select: {
|
|
60
|
+
id: true,
|
|
61
|
+
username: true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (!event) {
|
|
69
|
+
throw new server_1.TRPCError({
|
|
70
|
+
code: "NOT_FOUND",
|
|
71
|
+
message: "Event not found",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (event.userId !== ctx.user.id) {
|
|
75
|
+
throw new server_1.TRPCError({
|
|
76
|
+
code: "UNAUTHORIZED",
|
|
77
|
+
message: "You are not authorized to view this event",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return { event };
|
|
81
|
+
}),
|
|
82
|
+
create: trpc_1.protectedProcedure
|
|
83
|
+
.input(eventSchema)
|
|
84
|
+
.mutation(async ({ ctx, input }) => {
|
|
85
|
+
if (!ctx.user) {
|
|
86
|
+
throw new server_1.TRPCError({
|
|
87
|
+
code: "UNAUTHORIZED",
|
|
88
|
+
message: "You must be logged in to create an event",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// If classId is provided, check if user is a teacher of the class
|
|
92
|
+
if (input.classId) {
|
|
93
|
+
const classData = await prisma_1.prisma.class.findUnique({
|
|
94
|
+
where: {
|
|
95
|
+
id: input.classId,
|
|
96
|
+
teachers: {
|
|
97
|
+
some: {
|
|
98
|
+
id: ctx.user.id,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
if (!classData) {
|
|
104
|
+
throw new server_1.TRPCError({
|
|
105
|
+
code: "UNAUTHORIZED",
|
|
106
|
+
message: "You are not authorized to create events for this class",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const event = await prisma_1.prisma.event.create({
|
|
111
|
+
data: {
|
|
112
|
+
name: input.name,
|
|
113
|
+
location: input.location,
|
|
114
|
+
remarks: input.remarks,
|
|
115
|
+
startTime: (0, date_fns_1.parseISO)(input.startTime),
|
|
116
|
+
endTime: (0, date_fns_1.parseISO)(input.endTime),
|
|
117
|
+
userId: ctx.user.id,
|
|
118
|
+
color: input.color,
|
|
119
|
+
...(input.classId ? { classId: input.classId } : {}),
|
|
120
|
+
},
|
|
121
|
+
select: {
|
|
122
|
+
id: true,
|
|
123
|
+
name: true,
|
|
124
|
+
location: true,
|
|
125
|
+
remarks: true,
|
|
126
|
+
startTime: true,
|
|
127
|
+
endTime: true,
|
|
128
|
+
color: true,
|
|
129
|
+
classId: true,
|
|
130
|
+
userId: true,
|
|
131
|
+
class: {
|
|
132
|
+
select: {
|
|
133
|
+
id: true,
|
|
134
|
+
name: true
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return { event };
|
|
140
|
+
}),
|
|
141
|
+
update: trpc_1.protectedProcedure
|
|
142
|
+
.input(zod_1.z.object({
|
|
143
|
+
id: zod_1.z.string(),
|
|
144
|
+
data: eventSchema,
|
|
145
|
+
}))
|
|
146
|
+
.mutation(async ({ ctx, input }) => {
|
|
147
|
+
if (!ctx.user) {
|
|
148
|
+
throw new server_1.TRPCError({
|
|
149
|
+
code: "UNAUTHORIZED",
|
|
150
|
+
message: "You must be logged in to update an event",
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const event = await prisma_1.prisma.event.findUnique({
|
|
154
|
+
where: { id: input.id },
|
|
155
|
+
});
|
|
156
|
+
if (!event) {
|
|
157
|
+
throw new server_1.TRPCError({
|
|
158
|
+
code: "NOT_FOUND",
|
|
159
|
+
message: "Event not found",
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (event.userId !== ctx.user.id) {
|
|
163
|
+
throw new server_1.TRPCError({
|
|
164
|
+
code: "UNAUTHORIZED",
|
|
165
|
+
message: "You are not authorized to update this event",
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const updatedEvent = await prisma_1.prisma.event.update({
|
|
169
|
+
where: { id: input.id },
|
|
170
|
+
data: {
|
|
171
|
+
name: input.data.name,
|
|
172
|
+
location: input.data.location,
|
|
173
|
+
remarks: input.data.remarks,
|
|
174
|
+
startTime: (0, date_fns_1.parseISO)(input.data.startTime),
|
|
175
|
+
endTime: (0, date_fns_1.parseISO)(input.data.endTime),
|
|
176
|
+
color: input.data.color,
|
|
177
|
+
...(input.data.classId ? { classId: input.data.classId } : {}),
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
return { event: updatedEvent };
|
|
181
|
+
}),
|
|
182
|
+
delete: trpc_1.protectedProcedure
|
|
183
|
+
.input(zod_1.z.object({
|
|
184
|
+
id: zod_1.z.string(),
|
|
185
|
+
}))
|
|
186
|
+
.mutation(async ({ ctx, input }) => {
|
|
187
|
+
if (!ctx.user) {
|
|
188
|
+
throw new server_1.TRPCError({
|
|
189
|
+
code: "UNAUTHORIZED",
|
|
190
|
+
message: "You must be logged in to delete an event",
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const event = await prisma_1.prisma.event.findUnique({
|
|
194
|
+
where: { id: input.id },
|
|
195
|
+
});
|
|
196
|
+
if (!event) {
|
|
197
|
+
throw new server_1.TRPCError({
|
|
198
|
+
code: "NOT_FOUND",
|
|
199
|
+
message: "Event not found",
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (event.userId !== ctx.user.id) {
|
|
203
|
+
throw new server_1.TRPCError({
|
|
204
|
+
code: "UNAUTHORIZED",
|
|
205
|
+
message: "You are not authorized to delete this event",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
await prisma_1.prisma.event.delete({
|
|
209
|
+
where: { id: input.id },
|
|
210
|
+
});
|
|
211
|
+
return { success: true };
|
|
212
|
+
}),
|
|
213
|
+
attachAssignment: trpc_1.protectedProcedure
|
|
214
|
+
.input(zod_1.z.object({
|
|
215
|
+
eventId: zod_1.z.string(),
|
|
216
|
+
assignmentId: zod_1.z.string(),
|
|
217
|
+
}))
|
|
218
|
+
.mutation(async ({ ctx, input }) => {
|
|
219
|
+
if (!ctx.user || !ctx.user.id) {
|
|
220
|
+
throw new server_1.TRPCError({
|
|
221
|
+
code: "UNAUTHORIZED",
|
|
222
|
+
message: "You must be logged in to attach an assignment",
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// Check if user owns the event
|
|
226
|
+
const event = await prisma_1.prisma.event.findUnique({
|
|
227
|
+
where: { id: input.eventId },
|
|
228
|
+
include: {
|
|
229
|
+
class: {
|
|
230
|
+
include: {
|
|
231
|
+
teachers: {
|
|
232
|
+
select: { id: true }
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
if (!event) {
|
|
239
|
+
throw new server_1.TRPCError({
|
|
240
|
+
code: "NOT_FOUND",
|
|
241
|
+
message: "Event not found",
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
// Check if user is the event owner or a teacher of the class
|
|
245
|
+
if (event.userId !== ctx.user.id &&
|
|
246
|
+
!event.class?.teachers.some(teacher => teacher.id === ctx.user.id)) {
|
|
247
|
+
throw new server_1.TRPCError({
|
|
248
|
+
code: "UNAUTHORIZED",
|
|
249
|
+
message: "You are not authorized to modify this event",
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
// Check if assignment exists and belongs to the same class
|
|
253
|
+
const assignment = await prisma_1.prisma.assignment.findUnique({
|
|
254
|
+
where: { id: input.assignmentId },
|
|
255
|
+
include: {
|
|
256
|
+
class: {
|
|
257
|
+
include: {
|
|
258
|
+
teachers: {
|
|
259
|
+
select: { id: true }
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
if (!assignment) {
|
|
266
|
+
throw new server_1.TRPCError({
|
|
267
|
+
code: "NOT_FOUND",
|
|
268
|
+
message: "Assignment not found",
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
// Check if user is a teacher of the assignment's class
|
|
272
|
+
if (!assignment.class.teachers.some(teacher => teacher.id === ctx.user.id)) {
|
|
273
|
+
throw new server_1.TRPCError({
|
|
274
|
+
code: "UNAUTHORIZED",
|
|
275
|
+
message: "You are not authorized to modify this assignment",
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
// Check if event and assignment belong to the same class
|
|
279
|
+
if (event.classId !== assignment.classId) {
|
|
280
|
+
throw new server_1.TRPCError({
|
|
281
|
+
code: "BAD_REQUEST",
|
|
282
|
+
message: "Event and assignment must belong to the same class",
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
// Attach assignment to event
|
|
286
|
+
const updatedAssignment = await prisma_1.prisma.assignment.update({
|
|
287
|
+
where: { id: input.assignmentId },
|
|
288
|
+
data: {
|
|
289
|
+
eventAttached: {
|
|
290
|
+
connect: { id: input.eventId }
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
include: {
|
|
294
|
+
attachments: {
|
|
295
|
+
select: {
|
|
296
|
+
id: true,
|
|
297
|
+
name: true,
|
|
298
|
+
type: true,
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
section: {
|
|
302
|
+
select: {
|
|
303
|
+
id: true,
|
|
304
|
+
name: true
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
teacher: {
|
|
308
|
+
select: {
|
|
309
|
+
id: true,
|
|
310
|
+
username: true
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
return { assignment: updatedAssignment };
|
|
316
|
+
}),
|
|
317
|
+
detachAssignment: trpc_1.protectedProcedure
|
|
318
|
+
.input(zod_1.z.object({
|
|
319
|
+
eventId: zod_1.z.string(),
|
|
320
|
+
assignmentId: zod_1.z.string(),
|
|
321
|
+
}))
|
|
322
|
+
.mutation(async ({ ctx, input }) => {
|
|
323
|
+
if (!ctx.user) {
|
|
324
|
+
throw new server_1.TRPCError({
|
|
325
|
+
code: "UNAUTHORIZED",
|
|
326
|
+
message: "You must be logged in to detach an assignment",
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
// Check if user owns the event
|
|
330
|
+
const event = await prisma_1.prisma.event.findUnique({
|
|
331
|
+
where: { id: input.eventId },
|
|
332
|
+
include: {
|
|
333
|
+
class: {
|
|
334
|
+
include: {
|
|
335
|
+
teachers: {
|
|
336
|
+
select: { id: true }
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
if (!event) {
|
|
343
|
+
throw new server_1.TRPCError({
|
|
344
|
+
code: "NOT_FOUND",
|
|
345
|
+
message: "Event not found",
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
// Check if user is the event owner or a teacher of the class
|
|
349
|
+
if (event.userId !== ctx.user.id &&
|
|
350
|
+
!event.class?.teachers.some(teacher => teacher.id === ctx.user.id)) {
|
|
351
|
+
throw new server_1.TRPCError({
|
|
352
|
+
code: "UNAUTHORIZED",
|
|
353
|
+
message: "You are not authorized to modify this event",
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
// Detach assignment from event
|
|
357
|
+
const updatedAssignment = await prisma_1.prisma.assignment.update({
|
|
358
|
+
where: { id: input.assignmentId },
|
|
359
|
+
data: {
|
|
360
|
+
eventAttached: {
|
|
361
|
+
disconnect: true
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
include: {
|
|
365
|
+
attachments: {
|
|
366
|
+
select: {
|
|
367
|
+
id: true,
|
|
368
|
+
name: true,
|
|
369
|
+
type: true,
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
section: {
|
|
373
|
+
select: {
|
|
374
|
+
id: true,
|
|
375
|
+
name: true
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
teacher: {
|
|
379
|
+
select: {
|
|
380
|
+
id: true,
|
|
381
|
+
username: true
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
return { assignment: updatedAssignment };
|
|
387
|
+
}),
|
|
388
|
+
getAvailableAssignments: trpc_1.protectedProcedure
|
|
389
|
+
.input(zod_1.z.object({
|
|
390
|
+
eventId: zod_1.z.string(),
|
|
391
|
+
}))
|
|
392
|
+
.query(async ({ ctx, input }) => {
|
|
393
|
+
if (!ctx.user) {
|
|
394
|
+
throw new server_1.TRPCError({
|
|
395
|
+
code: "UNAUTHORIZED",
|
|
396
|
+
message: "You must be logged in to get available assignments",
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
// Get the event to find the class
|
|
400
|
+
const event = await prisma_1.prisma.event.findUnique({
|
|
401
|
+
where: { id: input.eventId },
|
|
402
|
+
include: {
|
|
403
|
+
class: {
|
|
404
|
+
include: {
|
|
405
|
+
teachers: {
|
|
406
|
+
select: { id: true }
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
if (!event || !event.classId) {
|
|
413
|
+
throw new server_1.TRPCError({
|
|
414
|
+
code: "NOT_FOUND",
|
|
415
|
+
message: "Event not found",
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
// Check if user is authorized to access this event/class
|
|
419
|
+
if (event.userId !== ctx.user.id &&
|
|
420
|
+
!event.class?.teachers.some(teacher => teacher.id === ctx.user.id)) {
|
|
421
|
+
throw new server_1.TRPCError({
|
|
422
|
+
code: "UNAUTHORIZED",
|
|
423
|
+
message: "You are not authorized to access this event",
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
// Get all assignments for the class that are not already attached to an event
|
|
427
|
+
const assignments = await prisma_1.prisma.assignment.findMany({
|
|
428
|
+
where: {
|
|
429
|
+
classId: event.classId,
|
|
430
|
+
eventId: null, // Not already attached to any event
|
|
431
|
+
},
|
|
432
|
+
select: {
|
|
433
|
+
id: true,
|
|
434
|
+
title: true,
|
|
435
|
+
instructions: true,
|
|
436
|
+
dueDate: true,
|
|
437
|
+
type: true,
|
|
438
|
+
graded: true,
|
|
439
|
+
maxGrade: true,
|
|
440
|
+
weight: true,
|
|
441
|
+
section: {
|
|
442
|
+
select: {
|
|
443
|
+
id: true,
|
|
444
|
+
name: true
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
attachments: {
|
|
448
|
+
select: {
|
|
449
|
+
id: true,
|
|
450
|
+
name: true,
|
|
451
|
+
type: true,
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
teacher: {
|
|
455
|
+
select: {
|
|
456
|
+
id: true,
|
|
457
|
+
username: true
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
orderBy: {
|
|
462
|
+
createdAt: 'desc'
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
return { assignments };
|
|
466
|
+
}),
|
|
467
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const fileRouter: import("@trpc/server/dist/unstable-core-do-not-import").BuiltRouter<{
|
|
3
|
+
ctx: import("../trpc").Context;
|
|
4
|
+
meta: object;
|
|
5
|
+
errorShape: {
|
|
6
|
+
data: {
|
|
7
|
+
zodError: z.typeToFlattenedError<any, string> | null;
|
|
8
|
+
code: import("@trpc/server/dist/unstable-core-do-not-import").TRPC_ERROR_CODE_KEY;
|
|
9
|
+
httpStatus: number;
|
|
10
|
+
path?: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
};
|
|
13
|
+
message: string;
|
|
14
|
+
code: import("@trpc/server/dist/unstable-core-do-not-import").TRPC_ERROR_CODE_NUMBER;
|
|
15
|
+
};
|
|
16
|
+
transformer: false;
|
|
17
|
+
}, import("@trpc/server/dist/unstable-core-do-not-import").DecorateCreateRouterOptions<{
|
|
18
|
+
getSignedUrl: import("@trpc/server").TRPCMutationProcedure<{
|
|
19
|
+
input: {
|
|
20
|
+
fileId: string;
|
|
21
|
+
};
|
|
22
|
+
output: {
|
|
23
|
+
signedUrl: string;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
26
|
+
}>>;
|
|
27
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/routers/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;GAwFrB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fileRouter = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const trpc_1 = require("../trpc");
|
|
6
|
+
const server_1 = require("@trpc/server");
|
|
7
|
+
const googleCloudStorage_1 = require("@/lib/googleCloudStorage");
|
|
8
|
+
const prisma_1 = require("@lib/prisma");
|
|
9
|
+
exports.fileRouter = (0, trpc_1.createTRPCRouter)({
|
|
10
|
+
getSignedUrl: trpc_1.protectedProcedure
|
|
11
|
+
.input(zod_1.z.object({
|
|
12
|
+
fileId: zod_1.z.string(),
|
|
13
|
+
}))
|
|
14
|
+
.mutation(async ({ ctx, input }) => {
|
|
15
|
+
const { fileId } = input;
|
|
16
|
+
const userId = ctx.user?.id;
|
|
17
|
+
if (!userId) {
|
|
18
|
+
throw new server_1.TRPCError({
|
|
19
|
+
code: "UNAUTHORIZED",
|
|
20
|
+
message: "You must be logged in to access files",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// Get file metadata from database
|
|
24
|
+
const file = await prisma_1.prisma.file.findUnique({
|
|
25
|
+
where: { id: fileId },
|
|
26
|
+
include: {
|
|
27
|
+
assignment: {
|
|
28
|
+
include: {
|
|
29
|
+
class: {
|
|
30
|
+
include: {
|
|
31
|
+
students: true,
|
|
32
|
+
teachers: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
submission: {
|
|
38
|
+
include: {
|
|
39
|
+
student: true,
|
|
40
|
+
assignment: {
|
|
41
|
+
include: {
|
|
42
|
+
class: {
|
|
43
|
+
include: {
|
|
44
|
+
teachers: true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (!file) {
|
|
54
|
+
throw new server_1.TRPCError({
|
|
55
|
+
code: "NOT_FOUND",
|
|
56
|
+
message: "File does not exist",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// Check if user has access to the file
|
|
60
|
+
const hasAccess =
|
|
61
|
+
// File owner
|
|
62
|
+
file.userId === userId ||
|
|
63
|
+
// Assignment file - student in class or teacher
|
|
64
|
+
(file.assignment && (file.assignment.class.students.some((s) => s.id === userId) ||
|
|
65
|
+
file.assignment.class.teachers.some((t) => t.id === userId))) ||
|
|
66
|
+
// Submission file - student who submitted or teacher of class
|
|
67
|
+
(file.submission && (file.submission.student.id === userId ||
|
|
68
|
+
file.submission.assignment.class.teachers.some((t) => t.id === userId)));
|
|
69
|
+
if (!hasAccess) {
|
|
70
|
+
throw new server_1.TRPCError({
|
|
71
|
+
code: "FORBIDDEN",
|
|
72
|
+
message: "You do not have access to this file",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
// Generate a signed URL with short expiration
|
|
77
|
+
const signedUrl = await (0, googleCloudStorage_1.getSignedUrl)(file.path);
|
|
78
|
+
return { signedUrl };
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error('Error generating signed URL:', error);
|
|
82
|
+
throw new server_1.TRPCError({
|
|
83
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
84
|
+
message: "Failed to generate signed URL",
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const sectionRouter: import("@trpc/server/dist/unstable-core-do-not-import").BuiltRouter<{
|
|
3
|
+
ctx: import("../trpc").Context;
|
|
4
|
+
meta: object;
|
|
5
|
+
errorShape: {
|
|
6
|
+
data: {
|
|
7
|
+
zodError: z.typeToFlattenedError<any, string> | null;
|
|
8
|
+
code: import("@trpc/server/dist/unstable-core-do-not-import").TRPC_ERROR_CODE_KEY;
|
|
9
|
+
httpStatus: number;
|
|
10
|
+
path?: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
};
|
|
13
|
+
message: string;
|
|
14
|
+
code: import("@trpc/server/dist/unstable-core-do-not-import").TRPC_ERROR_CODE_NUMBER;
|
|
15
|
+
};
|
|
16
|
+
transformer: false;
|
|
17
|
+
}, import("@trpc/server/dist/unstable-core-do-not-import").DecorateCreateRouterOptions<{
|
|
18
|
+
create: import("@trpc/server").TRPCMutationProcedure<{
|
|
19
|
+
input: {
|
|
20
|
+
name: string;
|
|
21
|
+
classId: string;
|
|
22
|
+
};
|
|
23
|
+
output: {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
classId: string;
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
update: import("@trpc/server").TRPCMutationProcedure<{
|
|
30
|
+
input: {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
classId: string;
|
|
34
|
+
};
|
|
35
|
+
output: {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
classId: string;
|
|
39
|
+
};
|
|
40
|
+
}>;
|
|
41
|
+
delete: import("@trpc/server").TRPCMutationProcedure<{
|
|
42
|
+
input: {
|
|
43
|
+
id: string;
|
|
44
|
+
classId: string;
|
|
45
|
+
};
|
|
46
|
+
output: {
|
|
47
|
+
id: string;
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
}>>;
|
|
51
|
+
//# sourceMappingURL=section.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../../src/routers/section.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoHxB,CAAC"}
|