@studious-lms/server 1.20.0 → 1.21.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/Dockerfile +5 -2
- package/dist/routers/_app.d.ts +148 -0
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/assignment.d.ts +74 -0
- package/dist/routers/assignment.d.ts.map +1 -1
- package/dist/routers/assignment.js +180 -2
- package/dist/routers/assignment.js.map +1 -1
- package/docker-entrypoint.sh +7 -0
- package/package.json +1 -1
- package/prisma/migrations/20260708011456_add_file_annotations/migration.sql +35 -0
- package/prisma/schema.prisma +70 -38
- package/src/routers/assignment.ts +204 -0
|
@@ -180,6 +180,30 @@ const confirmAnnotationUploadSchema = z.object({
|
|
|
180
180
|
errorMessage: z.string().optional(),
|
|
181
181
|
});
|
|
182
182
|
|
|
183
|
+
const listFileAnnotationsSchema = z.object({
|
|
184
|
+
classId: z.string(),
|
|
185
|
+
submissionId: z.string(),
|
|
186
|
+
fileId: z.string(),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const upsertFileAnnotationSchema = z.object({
|
|
190
|
+
classId: z.string(),
|
|
191
|
+
submissionId: z.string(),
|
|
192
|
+
fileId: z.string(),
|
|
193
|
+
id: z.string().optional(),
|
|
194
|
+
page: z.number().int().min(1),
|
|
195
|
+
type: z.enum(["HIGHLIGHT", "INK", "COMMENT", "TEXT"]),
|
|
196
|
+
geometry: z.record(z.string(), z.unknown()),
|
|
197
|
+
text: z.string().optional(),
|
|
198
|
+
color: z.string().optional(),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const deleteFileAnnotationSchema = z.object({
|
|
202
|
+
classId: z.string(),
|
|
203
|
+
submissionId: z.string(),
|
|
204
|
+
id: z.string(),
|
|
205
|
+
});
|
|
206
|
+
|
|
183
207
|
const updateUploadProgressSchema = z.object({
|
|
184
208
|
fileId: z.string(),
|
|
185
209
|
progress: z.number().min(0).max(100),
|
|
@@ -966,6 +990,186 @@ export const assignmentRouter = createTRPCRouter({
|
|
|
966
990
|
};
|
|
967
991
|
}),
|
|
968
992
|
|
|
993
|
+
listFileAnnotations: protectedClassMemberProcedure
|
|
994
|
+
.input(listFileAnnotationsSchema)
|
|
995
|
+
.query(async ({ ctx, input }) => {
|
|
996
|
+
const { classId, submissionId, fileId } = input;
|
|
997
|
+
|
|
998
|
+
const submission = await prisma.submission.findFirst({
|
|
999
|
+
where: {
|
|
1000
|
+
id: submissionId,
|
|
1001
|
+
assignment: { classId },
|
|
1002
|
+
},
|
|
1003
|
+
select: {
|
|
1004
|
+
id: true,
|
|
1005
|
+
studentId: true,
|
|
1006
|
+
returned: true,
|
|
1007
|
+
assignment: {
|
|
1008
|
+
select: {
|
|
1009
|
+
class: {
|
|
1010
|
+
select: {
|
|
1011
|
+
teachers: { where: { id: ctx.user!.id }, select: { id: true } },
|
|
1012
|
+
},
|
|
1013
|
+
},
|
|
1014
|
+
},
|
|
1015
|
+
},
|
|
1016
|
+
},
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
if (!submission) {
|
|
1020
|
+
throw new TRPCError({
|
|
1021
|
+
code: "NOT_FOUND",
|
|
1022
|
+
message: "Submission not found",
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const isTeacher = submission.assignment.class.teachers.length > 0;
|
|
1027
|
+
const isOwningStudent = submission.studentId === ctx.user!.id;
|
|
1028
|
+
|
|
1029
|
+
if (!isTeacher && !(isOwningStudent && submission.returned)) {
|
|
1030
|
+
throw new TRPCError({
|
|
1031
|
+
code: "FORBIDDEN",
|
|
1032
|
+
message: "You don't have access to these annotations",
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
const annotations = await prisma.fileAnnotation.findMany({
|
|
1037
|
+
where: { submissionId, fileId },
|
|
1038
|
+
orderBy: { createdAt: "asc" },
|
|
1039
|
+
include: {
|
|
1040
|
+
author: {
|
|
1041
|
+
select: {
|
|
1042
|
+
id: true,
|
|
1043
|
+
username: true,
|
|
1044
|
+
profile: { select: { displayName: true } },
|
|
1045
|
+
},
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
return { annotations };
|
|
1051
|
+
}),
|
|
1052
|
+
|
|
1053
|
+
upsertFileAnnotation: protectedTeacherProcedure
|
|
1054
|
+
.input(upsertFileAnnotationSchema)
|
|
1055
|
+
.mutation(async ({ ctx, input }) => {
|
|
1056
|
+
const { classId, submissionId, fileId, id, page, type, geometry, text, color } = input;
|
|
1057
|
+
|
|
1058
|
+
const submission = await prisma.submission.findFirst({
|
|
1059
|
+
where: {
|
|
1060
|
+
id: submissionId,
|
|
1061
|
+
assignment: {
|
|
1062
|
+
classId,
|
|
1063
|
+
class: {
|
|
1064
|
+
teachers: {
|
|
1065
|
+
some: { id: ctx.user!.id },
|
|
1066
|
+
},
|
|
1067
|
+
},
|
|
1068
|
+
},
|
|
1069
|
+
},
|
|
1070
|
+
select: { id: true },
|
|
1071
|
+
});
|
|
1072
|
+
|
|
1073
|
+
if (!submission) {
|
|
1074
|
+
throw new TRPCError({
|
|
1075
|
+
code: "NOT_FOUND",
|
|
1076
|
+
message: "Submission not found or you are not a teacher of this class",
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
const file = await prisma.file.findFirst({
|
|
1081
|
+
where: {
|
|
1082
|
+
id: fileId,
|
|
1083
|
+
OR: [{ submissionId }, { annotationId: submissionId }],
|
|
1084
|
+
},
|
|
1085
|
+
select: { id: true },
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
if (!file) {
|
|
1089
|
+
throw new TRPCError({
|
|
1090
|
+
code: "NOT_FOUND",
|
|
1091
|
+
message: "File does not belong to this submission",
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
if (id) {
|
|
1096
|
+
const existing = await prisma.fileAnnotation.findFirst({
|
|
1097
|
+
where: { id, submissionId, fileId },
|
|
1098
|
+
select: { id: true },
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
if (!existing) {
|
|
1102
|
+
throw new TRPCError({
|
|
1103
|
+
code: "NOT_FOUND",
|
|
1104
|
+
message: "Annotation not found",
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
const annotation = await prisma.fileAnnotation.update({
|
|
1109
|
+
where: { id },
|
|
1110
|
+
data: {
|
|
1111
|
+
page,
|
|
1112
|
+
type,
|
|
1113
|
+
geometry: geometry as object,
|
|
1114
|
+
text: text ?? null,
|
|
1115
|
+
color: color ?? null,
|
|
1116
|
+
},
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
return { annotation };
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
const annotation = await prisma.fileAnnotation.create({
|
|
1123
|
+
data: {
|
|
1124
|
+
fileId,
|
|
1125
|
+
submissionId,
|
|
1126
|
+
authorId: ctx.user!.id,
|
|
1127
|
+
page,
|
|
1128
|
+
type,
|
|
1129
|
+
geometry: geometry as object,
|
|
1130
|
+
text: text ?? null,
|
|
1131
|
+
color: color ?? null,
|
|
1132
|
+
},
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
return { annotation };
|
|
1136
|
+
}),
|
|
1137
|
+
|
|
1138
|
+
deleteFileAnnotation: protectedTeacherProcedure
|
|
1139
|
+
.input(deleteFileAnnotationSchema)
|
|
1140
|
+
.mutation(async ({ ctx, input }) => {
|
|
1141
|
+
const { classId, submissionId, id } = input;
|
|
1142
|
+
|
|
1143
|
+
const annotation = await prisma.fileAnnotation.findFirst({
|
|
1144
|
+
where: {
|
|
1145
|
+
id,
|
|
1146
|
+
submissionId,
|
|
1147
|
+
submission: {
|
|
1148
|
+
assignment: {
|
|
1149
|
+
classId,
|
|
1150
|
+
class: {
|
|
1151
|
+
teachers: {
|
|
1152
|
+
some: { id: ctx.user!.id },
|
|
1153
|
+
},
|
|
1154
|
+
},
|
|
1155
|
+
},
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
select: { id: true },
|
|
1159
|
+
});
|
|
1160
|
+
|
|
1161
|
+
if (!annotation) {
|
|
1162
|
+
throw new TRPCError({
|
|
1163
|
+
code: "NOT_FOUND",
|
|
1164
|
+
message: "Annotation not found or you are not a teacher of this class",
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
await prisma.fileAnnotation.delete({ where: { id } });
|
|
1169
|
+
|
|
1170
|
+
return { success: true };
|
|
1171
|
+
}),
|
|
1172
|
+
|
|
969
1173
|
updateUploadProgress: protectedProcedure
|
|
970
1174
|
.input(updateUploadProgressSchema)
|
|
971
1175
|
.mutation(async ({ ctx, input }) => {
|