@studious-lms/server 1.0.2 → 1.0.3
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/package.json +1 -6
- package/prisma/schema.prisma +228 -0
- package/src/exportType.ts +9 -0
- package/src/index.ts +94 -0
- package/src/lib/fileUpload.ts +163 -0
- package/src/lib/googleCloudStorage.ts +94 -0
- package/src/lib/prisma.ts +16 -0
- package/src/lib/thumbnailGenerator.ts +185 -0
- package/src/logger.ts +163 -0
- package/src/middleware/auth.ts +191 -0
- package/src/middleware/logging.ts +54 -0
- package/src/routers/_app.ts +34 -0
- package/src/routers/agenda.ts +79 -0
- package/src/routers/announcement.ts +134 -0
- package/src/routers/assignment.ts +1614 -0
- package/src/routers/attendance.ts +284 -0
- package/src/routers/auth.ts +286 -0
- package/src/routers/class.ts +753 -0
- package/src/routers/event.ts +509 -0
- package/src/routers/file.ts +96 -0
- package/src/routers/section.ts +138 -0
- package/src/routers/user.ts +82 -0
- package/src/socket/handlers.ts +143 -0
- package/src/trpc.ts +90 -0
- package/src/types/trpc.ts +15 -0
- package/src/utils/email.ts +11 -0
- package/src/utils/generateInviteCode.ts +8 -0
- package/src/utils/logger.ts +156 -0
- package/tsconfig.json +17 -0
- package/generated/prisma/client.d.ts +0 -1
- package/generated/prisma/client.js +0 -4
- package/generated/prisma/default.d.ts +0 -1
- package/generated/prisma/default.js +0 -4
- package/generated/prisma/edge.d.ts +0 -1
- package/generated/prisma/edge.js +0 -389
- package/generated/prisma/index-browser.js +0 -375
- package/generated/prisma/index.d.ts +0 -34865
- package/generated/prisma/index.js +0 -410
- package/generated/prisma/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/generated/prisma/package.json +0 -140
- package/generated/prisma/runtime/edge-esm.js +0 -34
- package/generated/prisma/runtime/edge.js +0 -34
- package/generated/prisma/runtime/index-browser.d.ts +0 -370
- package/generated/prisma/runtime/index-browser.js +0 -16
- package/generated/prisma/runtime/library.d.ts +0 -3647
- package/generated/prisma/runtime/library.js +0 -146
- package/generated/prisma/runtime/react-native.js +0 -83
- package/generated/prisma/runtime/wasm.js +0 -35
- package/generated/prisma/schema.prisma +0 -304
- package/generated/prisma/wasm.d.ts +0 -1
- package/generated/prisma/wasm.js +0 -375
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createTRPCRouter, protectedClassMemberProcedure, protectedTeacherProcedure, protectedProcedure } from "../trpc";
|
|
3
|
+
import { prisma } from "../lib/prisma";
|
|
4
|
+
import { TRPCError } from "@trpc/server";
|
|
5
|
+
|
|
6
|
+
const AnnouncementSelect = {
|
|
7
|
+
id: true,
|
|
8
|
+
teacher: {
|
|
9
|
+
select: {
|
|
10
|
+
id: true,
|
|
11
|
+
username: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
remarks: true,
|
|
15
|
+
createdAt: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const announcementRouter = createTRPCRouter({
|
|
19
|
+
getAll: protectedClassMemberProcedure
|
|
20
|
+
.input(z.object({
|
|
21
|
+
classId: z.string(),
|
|
22
|
+
}))
|
|
23
|
+
.query(async ({ ctx, input }) => {
|
|
24
|
+
const announcements = await prisma.announcement.findMany({
|
|
25
|
+
where: {
|
|
26
|
+
classId: input.classId,
|
|
27
|
+
},
|
|
28
|
+
select: AnnouncementSelect,
|
|
29
|
+
orderBy: {
|
|
30
|
+
createdAt: 'desc',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
announcements,
|
|
36
|
+
};
|
|
37
|
+
}),
|
|
38
|
+
|
|
39
|
+
create: protectedTeacherProcedure
|
|
40
|
+
.input(z.object({
|
|
41
|
+
classId: z.string(),
|
|
42
|
+
remarks: z.string(),
|
|
43
|
+
}))
|
|
44
|
+
.mutation(async ({ ctx, input }) => {
|
|
45
|
+
const announcement = await prisma.announcement.create({
|
|
46
|
+
data: {
|
|
47
|
+
remarks: input.remarks,
|
|
48
|
+
teacher: {
|
|
49
|
+
connect: {
|
|
50
|
+
id: ctx.user?.id,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
class: {
|
|
54
|
+
connect: {
|
|
55
|
+
id: input.classId,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
select: AnnouncementSelect,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
announcement,
|
|
64
|
+
};
|
|
65
|
+
}),
|
|
66
|
+
|
|
67
|
+
update: protectedProcedure
|
|
68
|
+
.input(z.object({
|
|
69
|
+
id: z.string(),
|
|
70
|
+
data: z.object({
|
|
71
|
+
content: z.string(),
|
|
72
|
+
}),
|
|
73
|
+
}))
|
|
74
|
+
.mutation(async ({ ctx, input }) => {
|
|
75
|
+
|
|
76
|
+
const announcement = await prisma.announcement.findUnique({
|
|
77
|
+
where: { id: input.id },
|
|
78
|
+
include: {
|
|
79
|
+
class: {
|
|
80
|
+
include: {
|
|
81
|
+
teachers: true,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (!announcement) {
|
|
88
|
+
throw new TRPCError({
|
|
89
|
+
code: "NOT_FOUND",
|
|
90
|
+
message: "Announcement not found",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const updatedAnnouncement = await prisma.announcement.update({
|
|
95
|
+
where: { id: input.id },
|
|
96
|
+
data: {
|
|
97
|
+
remarks: input.data.content,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return { announcement: updatedAnnouncement };
|
|
102
|
+
}),
|
|
103
|
+
|
|
104
|
+
delete: protectedProcedure
|
|
105
|
+
.input(z.object({
|
|
106
|
+
id: z.string(),
|
|
107
|
+
}))
|
|
108
|
+
.mutation(async ({ ctx, input }) => {
|
|
109
|
+
|
|
110
|
+
const announcement = await prisma.announcement.findUnique({
|
|
111
|
+
where: { id: input.id },
|
|
112
|
+
include: {
|
|
113
|
+
class: {
|
|
114
|
+
include: {
|
|
115
|
+
teachers: true,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (!announcement) {
|
|
122
|
+
throw new TRPCError({
|
|
123
|
+
code: "NOT_FOUND",
|
|
124
|
+
message: "Announcement not found",
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
await prisma.announcement.delete({
|
|
129
|
+
where: { id: input.id },
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return { success: true };
|
|
133
|
+
}),
|
|
134
|
+
});
|