@studious-lms/server 1.2.31 → 1.2.33

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.
@@ -154,6 +154,22 @@ export const classRouter = createTRPCRouter({
154
154
  },
155
155
  },
156
156
  assignments: {
157
+ ...(!isTeacher && {
158
+ where: {OR: [
159
+ {
160
+ assignedTo: {
161
+ some: {
162
+ id: ctx.user?.id,
163
+ },
164
+ },
165
+ },
166
+ {
167
+ assignedTo: {
168
+ none: {},
169
+ },
170
+ },
171
+ ],}
172
+ }),
157
173
  select: {
158
174
  type: true,
159
175
  id: true,
@@ -217,8 +233,8 @@ export const classRouter = createTRPCRouter({
217
233
  assignments: classData.assignments.map(assignment => ({
218
234
  ...assignment,
219
235
  late: assignment.dueDate < new Date(),
220
- submitted: assignment.submissions.some(submission => submission.studentId === ctx.user?.id),
221
- returned: assignment.submissions.some(submission => submission.studentId === ctx.user?.id && submission.returned),
236
+ submitted: assignment.submissions.find(submission => submission.studentId === ctx.user?.id)?.submitted,
237
+ returned: assignment.submissions.find(submission => submission.studentId === ctx.user?.id)?.returned,
222
238
  })),
223
239
  }
224
240
 
@@ -223,6 +223,7 @@ export const worksheetRouter = createTRPCRouter({
223
223
  ...(answer !== undefined && { answer }),
224
224
  ...(markScheme !== undefined && { markScheme }),
225
225
  ...(type !== undefined && { type }),
226
+ ...(options !== undefined && { options }),
226
227
  },
227
228
  });
228
229
 
@@ -267,11 +268,36 @@ export const worksheetRouter = createTRPCRouter({
267
268
  throw new TRPCError({ code: 'NOT_FOUND', message: 'Submission not found' });
268
269
  }
269
270
 
270
- const worksheetResponses = await prisma.studentWorksheetResponse.findMany({
271
- where: { submissionId },
272
- include: {
273
- responses: true,
274
- },
271
+ // Find or create worksheet response for this submission
272
+ const worksheetResponses = await prisma.$transaction(async (tx) => {
273
+ // First check if a response exists
274
+ const existing = await tx.studentWorksheetResponse.findFirst({
275
+ where: {
276
+ submissionId,
277
+ worksheetId
278
+ },
279
+ include: {
280
+ responses: true,
281
+ },
282
+ });
283
+
284
+ if (existing) {
285
+ return existing;
286
+ }
287
+
288
+ // Create new response if it doesn't exist
289
+ const created = await tx.studentWorksheetResponse.create({
290
+ data: {
291
+ worksheetId,
292
+ submissionId,
293
+ studentId: submission.studentId,
294
+ },
295
+ include: {
296
+ responses: true,
297
+ },
298
+ });
299
+
300
+ return created;
275
301
  });
276
302
 
277
303
  return worksheetResponses;
@@ -421,14 +447,14 @@ export const worksheetRouter = createTRPCRouter({
421
447
  }),
422
448
 
423
449
  // Get all student responses for a worksheet (teacher view)
424
- getWorksheetResponses: protectedProcedure
450
+ getWorksheetResponse: protectedProcedure
425
451
  .input(z.object({
426
452
  worksheetId: z.string(),
427
453
  }))
428
454
  .query(async ({ ctx, input }) => {
429
455
  const { worksheetId } = input;
430
456
 
431
- const responses = await prisma.studentWorksheetResponse.findMany({
457
+ const responses = await prisma.studentWorksheetResponse.findFirst({
432
458
  where: { worksheetId },
433
459
  include: {
434
460
  student: {