@studious-lms/server 1.2.45 → 1.2.46
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/.env.example +45 -0
- package/.env.test.example +37 -0
- package/README.md +34 -7
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +12110 -0
- package/coverage/coverage-final.json +44 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +221 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/server/index.html +116 -0
- package/coverage/server/src/exportType.ts.html +109 -0
- package/coverage/server/src/index.html +161 -0
- package/coverage/server/src/index.ts.html +1702 -0
- package/coverage/server/src/instrument.ts.html +130 -0
- package/coverage/server/src/lib/config/env.ts.html +448 -0
- package/coverage/server/src/lib/config/index.html +116 -0
- package/coverage/server/src/lib/fileUpload.ts.html +1138 -0
- package/coverage/server/src/lib/googleCloudStorage.ts.html +334 -0
- package/coverage/server/src/lib/index.html +206 -0
- package/coverage/server/src/lib/jsonConversion.ts.html +2323 -0
- package/coverage/server/src/lib/jsonStyles.ts.html +193 -0
- package/coverage/server/src/lib/notificationHandler.ts.html +193 -0
- package/coverage/server/src/lib/pusher.ts.html +121 -0
- package/coverage/server/src/lib/thumbnailGenerator.ts.html +592 -0
- package/coverage/server/src/middleware/auth.ts.html +646 -0
- package/coverage/server/src/middleware/index.html +146 -0
- package/coverage/server/src/middleware/logging.ts.html +244 -0
- package/coverage/server/src/middleware/security.ts.html +271 -0
- package/coverage/server/src/routers/_app.ts.html +232 -0
- package/coverage/server/src/routers/agenda.ts.html +319 -0
- package/coverage/server/src/routers/announcement.ts.html +3481 -0
- package/coverage/server/src/routers/assignment.ts.html +7633 -0
- package/coverage/server/src/routers/attendance.ts.html +1030 -0
- package/coverage/server/src/routers/auth.ts.html +1081 -0
- package/coverage/server/src/routers/class.ts.html +3535 -0
- package/coverage/server/src/routers/comment.ts.html +991 -0
- package/coverage/server/src/routers/conversation.ts.html +982 -0
- package/coverage/server/src/routers/event.ts.html +1609 -0
- package/coverage/server/src/routers/file.ts.html +1144 -0
- package/coverage/server/src/routers/folder.ts.html +2797 -0
- package/coverage/server/src/routers/index.html +386 -0
- package/coverage/server/src/routers/labChat.ts.html +3073 -0
- package/coverage/server/src/routers/marketing.ts.html +340 -0
- package/coverage/server/src/routers/message.ts.html +1912 -0
- package/coverage/server/src/routers/notifications.ts.html +364 -0
- package/coverage/server/src/routers/section.ts.html +1120 -0
- package/coverage/server/src/routers/user.ts.html +862 -0
- package/coverage/server/src/routers/worksheet.ts.html +1729 -0
- package/coverage/server/src/trpc.ts.html +397 -0
- package/coverage/server/src/types/index.html +116 -0
- package/coverage/server/src/types/trpc.ts.html +127 -0
- package/coverage/server/src/utils/aiUser.ts.html +280 -0
- package/coverage/server/src/utils/email.ts.html +121 -0
- package/coverage/server/src/utils/generateInviteCode.ts.html +106 -0
- package/coverage/server/src/utils/index.html +206 -0
- package/coverage/server/src/utils/inference.ts.html +709 -0
- package/coverage/server/src/utils/logger.ts.html +664 -0
- package/coverage/server/src/utils/prismaErrorHandler.ts.html +907 -0
- package/coverage/server/src/utils/prismaWrapper.ts.html +355 -0
- package/coverage/server/vitest.config.ts.html +196 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -52
- package/dist/index.js.map +1 -1
- package/dist/instrument.js +15 -8
- package/dist/instrument.js.map +1 -1
- package/dist/lib/config/env.d.ts +169 -0
- package/dist/lib/config/env.d.ts.map +1 -0
- package/dist/lib/config/env.js +115 -0
- package/dist/lib/config/env.js.map +1 -0
- package/dist/lib/fileUpload.d.ts.map +1 -1
- package/dist/lib/fileUpload.js +5 -4
- package/dist/lib/fileUpload.js.map +1 -1
- package/dist/lib/googleCloudStorage.d.ts.map +1 -1
- package/dist/lib/googleCloudStorage.js +7 -8
- package/dist/lib/googleCloudStorage.js.map +1 -1
- package/dist/lib/jsonConversion.d.ts.map +1 -1
- package/dist/lib/jsonConversion.js +14 -16
- package/dist/lib/jsonConversion.js.map +1 -1
- package/dist/lib/notificationHandler.d.ts +2 -2
- package/dist/lib/prisma.d.ts +2 -2
- package/dist/lib/prisma.d.ts.map +1 -1
- package/dist/lib/prisma.js +22 -3
- package/dist/lib/prisma.js.map +1 -1
- package/dist/lib/pusher.d.ts.map +1 -1
- package/dist/lib/pusher.js +8 -7
- package/dist/lib/pusher.js.map +1 -1
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +6 -5
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/security.d.ts +5 -0
- package/dist/middleware/security.d.ts.map +1 -0
- package/dist/middleware/security.js +77 -0
- package/dist/middleware/security.js.map +1 -0
- package/dist/routers/_app.d.ts +294 -98
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/_app.js +4 -2
- package/dist/routers/_app.js.map +1 -1
- package/dist/routers/agenda.d.ts.map +1 -1
- package/dist/routers/agenda.js +12 -9
- package/dist/routers/agenda.js.map +1 -1
- package/dist/routers/announcement.d.ts +8 -0
- package/dist/routers/announcement.d.ts.map +1 -1
- package/dist/routers/announcement.js +6 -4
- package/dist/routers/announcement.js.map +1 -1
- package/dist/routers/assignment.d.ts +7 -4
- package/dist/routers/assignment.d.ts.map +1 -1
- package/dist/routers/assignment.js +35 -18
- package/dist/routers/assignment.js.map +1 -1
- package/dist/routers/attendance.d.ts +1 -0
- package/dist/routers/attendance.d.ts.map +1 -1
- package/dist/routers/attendance.js +4 -4
- package/dist/routers/attendance.js.map +1 -1
- package/dist/routers/auth.d.ts +20 -0
- package/dist/routers/auth.d.ts.map +1 -1
- package/dist/routers/auth.js +132 -15
- package/dist/routers/auth.js.map +1 -1
- package/dist/routers/class.d.ts +10 -0
- package/dist/routers/class.d.ts.map +1 -1
- package/dist/routers/class.js +49 -5
- package/dist/routers/class.js.map +1 -1
- package/dist/routers/comment.d.ts +2 -0
- package/dist/routers/comment.d.ts.map +1 -1
- package/dist/routers/conversation.d.ts +1 -0
- package/dist/routers/conversation.d.ts.map +1 -1
- package/dist/routers/conversation.js +46 -31
- package/dist/routers/conversation.js.map +1 -1
- package/dist/routers/file.d.ts.map +1 -1
- package/dist/routers/file.js +30 -7
- package/dist/routers/file.js.map +1 -1
- package/dist/routers/labChat.d.ts +1 -0
- package/dist/routers/labChat.d.ts.map +1 -1
- package/dist/routers/labChat.js +2 -3
- package/dist/routers/labChat.js.map +1 -1
- package/dist/routers/marketing.d.ts +1 -1
- package/dist/routers/newtonChat.d.ts +55 -0
- package/dist/routers/newtonChat.d.ts.map +1 -0
- package/dist/routers/newtonChat.js +438 -0
- package/dist/routers/newtonChat.js.map +1 -0
- package/dist/routers/notifications.d.ts +4 -4
- package/dist/routers/section.d.ts +9 -4
- package/dist/routers/section.d.ts.map +1 -1
- package/dist/routers/section.js +8 -8
- package/dist/routers/section.js.map +1 -1
- package/dist/routers/user.d.ts.map +1 -1
- package/dist/routers/user.js +5 -4
- package/dist/routers/user.js.map +1 -1
- package/dist/routers/worksheet.d.ts +30 -36
- package/dist/routers/worksheet.d.ts.map +1 -1
- package/dist/routers/worksheet.js +11 -33
- package/dist/routers/worksheet.js.map +1 -1
- package/dist/seedDatabase.d.ts +1 -1
- package/dist/seedDatabase.js +275 -284
- package/dist/seedDatabase.js.map +1 -1
- package/dist/server/pipelines/aiLabChat.d.ts +10 -0
- package/dist/server/pipelines/aiLabChat.d.ts.map +1 -0
- package/dist/server/pipelines/aiLabChat.js +83 -0
- package/dist/server/pipelines/aiLabChat.js.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts +2 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.js +138 -0
- package/dist/server/pipelines/gradeWorksheet.js.map +1 -0
- package/dist/trpc.d.ts.map +1 -1
- package/dist/trpc.js +2 -2
- package/dist/trpc.js.map +1 -1
- package/dist/utils/email.d.ts +9 -1
- package/dist/utils/email.d.ts.map +1 -1
- package/dist/utils/email.js +20 -5
- package/dist/utils/email.js.map +1 -1
- package/dist/utils/inference.d.ts +3 -0
- package/dist/utils/inference.d.ts.map +1 -1
- package/dist/utils/inference.js +41 -7
- package/dist/utils/inference.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils/logger.js.map +1 -1
- package/docker-compose.yml +14 -0
- package/package.json +13 -4
- package/prisma/schema.prisma +32 -5
- package/scripts/test-pre-push.ts +14 -0
- package/src/index.ts +98 -54
- package/src/instrument.ts +13 -6
- package/src/lib/config/env.ts +126 -0
- package/src/lib/fileUpload.ts +3 -2
- package/src/lib/googleCloudStorage.ts +6 -6
- package/src/lib/jsonConversion.ts +12 -14
- package/src/lib/prisma.ts +23 -2
- package/src/lib/pusher.ts +6 -5
- package/src/middleware/auth.ts +4 -3
- package/src/middleware/security.ts +80 -0
- package/src/routers/_app.ts +2 -0
- package/src/routers/agenda.ts +10 -7
- package/src/routers/announcement.ts +4 -2
- package/src/routers/assignment.ts +58 -40
- package/src/routers/attendance.ts +2 -2
- package/src/routers/auth.ts +143 -14
- package/src/routers/class.ts +52 -3
- package/src/routers/conversation.ts +49 -29
- package/src/routers/file.ts +29 -5
- package/src/routers/labChat.ts +0 -1
- package/src/routers/newtonChat.ts +520 -0
- package/src/routers/section.ts +6 -6
- package/src/routers/user.ts +3 -2
- package/src/routers/worksheet.ts +9 -37
- package/src/seedDatabase.ts +290 -283
- package/src/server/pipelines/aiLabChat.ts +92 -0
- package/src/server/pipelines/gradeWorksheet.ts +152 -0
- package/src/trpc.ts +2 -0
- package/src/utils/email.ts +30 -3
- package/src/utils/inference.ts +50 -5
- package/src/utils/logger.ts +2 -1
- package/tests/announcement.test.ts +164 -0
- package/tests/assignment.test.ts +296 -0
- package/tests/attendance.test.ts +168 -0
- package/tests/auth.test.ts +33 -10
- package/tests/class.test.ts +34 -9
- package/tests/event.test.ts +228 -0
- package/tests/section.test.ts +216 -0
- package/tests/setup.ts +70 -16
- package/tests/user.test.ts +158 -0
- package/vitest.config.ts +26 -0
- package/API_SPECIFICATION.md +0 -1597
- package/BASE64_REMOVAL_SUMMARY.md +0 -164
- package/CHAT_API_SPEC.md +0 -579
- package/LAB_CHAT_API_SPEC.md +0 -518
- package/dist/routers/school.d.ts +0 -208
- package/dist/routers/school.d.ts.map +0 -1
- package/dist/routers/school.js +0 -483
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section.js","sources":["routers/section.ts"],"sourceRoot":"/","sourcesContent":["import { z } from \"zod\";\nimport { createTRPCRouter, protectedProcedure } from \"../trpc.js\";\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\n\nconst createSectionSchema = z.object({\n classId: z.string(),\n name: z.string(),\n color: z.string().optional(),\n});\n\nconst updateSectionSchema = z.object({\n id: z.string(),\n classId: z.string(),\n name: z.string(),\n color: z.string().optional(),\n});\n\nconst deleteSectionSchema = z.object({\n id: z.string(),\n classId: z.string(),\n});\n\nexport const sectionRouter = createTRPCRouter({\n create: protectedProcedure\n .input(createSectionSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n const section = await prisma.section.create({\n data: {\n name: input.name,\n order: 0,\n class: {\n connect: { id: input.classId },\n },\n ...(input.color && {\n color: input.color,\n }),\n },\n });\n\n // Insert new section at top of unified list (sections + assignments) and normalize\n const [sections, assignments] = await Promise.all([\n prisma.section.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n prisma.assignment.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n ]);\n\n const unified = [\n ...sections.map(s => ({ id: s.id, order: s.order, type: 'section' as const })),\n ...assignments.map(a => ({ id: a.id, order: a.order, type: 'assignment' as const })),\n ].sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));\n\n const withoutNew = unified.filter(item => !(item.id === section.id && item.type === 'section'));\n const reindexed = [{ id: section.id, type: 'section' as const }, ...withoutNew.map(item => ({ id: item.id, type: item.type }))];\n\n await Promise.all(\n reindexed.map((item, index) => {\n if (item.type === 'section') {\n return prisma.section.update({ where: { id: item.id }, data: { order: index + 1 } });\n } else {\n return prisma.assignment.update({ where: { id: item.id }, data: { order: index + 1 } });\n }\n })\n );\n\n return section;\n }),\n\n reorder: protectedProcedure\n .input(z.object({\n classId: z.string(),\n movedId: z.string(), // Section ID\n // One of: place at start/end of unified list, or relative to targetId (can be section or assignment)\n position: z.enum(['start', 'end', 'before', 'after']),\n targetId: z.string().optional(), // Can be a section ID or assignment ID\n }))\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n const { classId, movedId, position, targetId } = input;\n\n const moved = await prisma.section.findFirst({\n where: { id: movedId, classId },\n select: { id: true, classId: true },\n });\n\n if (!moved) {\n throw new TRPCError({ code: 'NOT_FOUND', message: 'Section not found' });\n }\n\n if ((position === 'before' || position === 'after') && !targetId) {\n throw new TRPCError({ code: 'BAD_REQUEST', message: 'targetId required for before/after' });\n }\n\n const result = await prisma.$transaction(async (tx) => {\n const [sections, assignments] = await Promise.all([\n tx.section.findMany({\n where: { classId },\n select: { id: true, order: true },\n }),\n tx.assignment.findMany({\n where: { classId },\n select: { id: true, order: true },\n }),\n ]);\n\n const unified = [\n ...sections.map(s => ({ id: s.id, order: s.order, type: 'section' as const })),\n ...assignments.map(a => ({ id: a.id, order: a.order, type: 'assignment' as const })),\n ].sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));\n\n const movedIdx = unified.findIndex(item => item.id === movedId && item.type === 'section');\n if (movedIdx === -1) {\n throw new TRPCError({ code: 'NOT_FOUND', message: 'Section not found in unified list' });\n }\n\n const withoutMoved = unified.filter(item => !(item.id === movedId && item.type === 'section'));\n\n let next: Array<{ id: string; type: 'section' | 'assignment' }> = [];\n\n if (position === 'start') {\n next = [{ id: movedId, type: 'section' }, ...withoutMoved.map(item => ({ id: item.id, type: item.type }))];\n } else if (position === 'end') {\n next = [...withoutMoved.map(item => ({ id: item.id, type: item.type })), { id: movedId, type: 'section' }];\n } else {\n const targetIdx = withoutMoved.findIndex(item => item.id === targetId);\n if (targetIdx === -1) {\n throw new TRPCError({ code: 'BAD_REQUEST', message: 'targetId not found in unified list' });\n }\n if (position === 'before') {\n next = [\n ...withoutMoved.slice(0, targetIdx).map(item => ({ id: item.id, type: item.type })),\n { id: movedId, type: 'section' },\n ...withoutMoved.slice(targetIdx).map(item => ({ id: item.id, type: item.type })),\n ];\n } else {\n next = [\n ...withoutMoved.slice(0, targetIdx + 1).map(item => ({ id: item.id, type: item.type })),\n { id: movedId, type: 'section' },\n ...withoutMoved.slice(targetIdx + 1).map(item => ({ id: item.id, type: item.type })),\n ];\n }\n }\n\n // Normalize to 1..n\n await Promise.all(\n next.map((item, index) => {\n if (item.type === 'section') {\n return tx.section.update({ where: { id: item.id }, data: { order: index + 1 } });\n } else {\n return tx.assignment.update({ where: { id: item.id }, data: { order: index + 1 } });\n }\n })\n );\n\n return tx.section.findUnique({ where: { id: movedId } });\n });\n\n return result;\n }),\n\n update: protectedProcedure\n .input(updateSectionSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n const section = await prisma.section.update({\n where: { id: input.id },\n data: {\n name: input.name,\n ...(input.color && {\n color: input.color,\n }),\n },\n });\n\n return section;\n }),\n\n reOrder: protectedProcedure\n .input(z.object({\n id: z.string(),\n classId: z.string(),\n order: z.number(),\n }))\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n // Update order and normalize unified list\n await prisma.$transaction(async (tx) => {\n await tx.section.update({\n where: { id: input.id },\n data: { order: input.order },\n });\n\n // Normalize entire unified list\n const [sections, assignments] = await Promise.all([\n tx.section.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n tx.assignment.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n ]);\n\n const unified = [\n ...sections.map(s => ({ id: s.id, order: s.order, type: 'section' as const })),\n ...assignments.map(a => ({ id: a.id, order: a.order, type: 'assignment' as const })),\n ].sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));\n\n await Promise.all(\n unified.map((item, index) => {\n if (item.type === 'section') {\n return tx.section.update({ where: { id: item.id }, data: { order: index + 1 } });\n } else {\n return tx.assignment.update({ where: { id: item.id }, data: { order: index + 1 } });\n }\n })\n );\n });\n\n return { id: input.id };\n }),\n\n delete: protectedProcedure\n .input(deleteSectionSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n await prisma.section.delete({\n where: { id: input.id },\n });\n\n return { id: input.id };\n }),\n}); "],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;IAC5C,MAAM,EAAE,kBAAkB;SACvB,KAAK,CAAC,mBAAmB,CAAC;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AAE;SACxB,CAAC,CAAC;QAEH,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;IAC1B,CAAC,CAAC;CACL,CAAC,CAAC","debug_id":"ac1474d5-7092-5f48-9b93-aa7c2055bdb3"}
|
|
1
|
+
{"version":3,"file":"section.js","sources":["routers/section.ts"],"sourceRoot":"/","sourcesContent":["import { z } from \"zod\";\nimport { createTRPCRouter, protectedProcedure, protectedTeacherProcedure } from \"../trpc.js\";\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\n\nconst createSectionSchema = z.object({\n classId: z.string(),\n name: z.string(),\n color: z.string().optional(),\n});\n\nconst updateSectionSchema = z.object({\n id: z.string(),\n classId: z.string(),\n name: z.string(),\n color: z.string().optional(),\n});\n\nconst deleteSectionSchema = z.object({\n id: z.string(),\n classId: z.string(),\n});\n\nexport const sectionRouter = createTRPCRouter({\n create: protectedTeacherProcedure\n .input(createSectionSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n const section = await prisma.section.create({\n data: {\n name: input.name,\n order: 0,\n class: {\n connect: { id: input.classId },\n },\n ...(input.color && {\n color: input.color,\n }),\n },\n });\n\n // Insert new section at top of unified list (sections + assignments) and normalize\n const [sections, assignments] = await Promise.all([\n prisma.section.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n prisma.assignment.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n ]);\n\n const unified = [\n ...sections.map(s => ({ id: s.id, order: s.order, type: 'section' as const })),\n ...assignments.map(a => ({ id: a.id, order: a.order, type: 'assignment' as const })),\n ].sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));\n\n const withoutNew = unified.filter(item => !(item.id === section.id && item.type === 'section'));\n const reindexed = [{ id: section.id, type: 'section' as const }, ...withoutNew.map(item => ({ id: item.id, type: item.type }))];\n\n await Promise.all(\n reindexed.map((item, index) => {\n if (item.type === 'section') {\n return prisma.section.update({ where: { id: item.id }, data: { order: index + 1 } });\n } else {\n return prisma.assignment.update({ where: { id: item.id }, data: { order: index + 1 } });\n }\n })\n );\n\n return section;\n }),\n\n reorder: protectedTeacherProcedure\n .input(z.object({\n classId: z.string(),\n movedId: z.string(), // Section ID\n // One of: place at start/end of unified list, or relative to targetId (can be section or assignment)\n position: z.enum(['start', 'end', 'before', 'after']),\n targetId: z.string().optional(), // Can be a section ID or assignment ID\n }))\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n const { classId, movedId, position, targetId } = input;\n\n const moved = await prisma.section.findFirst({\n where: { id: movedId, classId },\n select: { id: true, classId: true },\n });\n\n if (!moved) {\n throw new TRPCError({ code: 'NOT_FOUND', message: 'Section not found' });\n }\n\n if ((position === 'before' || position === 'after') && !targetId) {\n throw new TRPCError({ code: 'BAD_REQUEST', message: 'targetId required for before/after' });\n }\n\n const result = await prisma.$transaction(async (tx) => {\n const [sections, assignments] = await Promise.all([\n tx.section.findMany({\n where: { classId },\n select: { id: true, order: true },\n }),\n tx.assignment.findMany({\n where: { classId },\n select: { id: true, order: true },\n }),\n ]);\n\n const unified = [\n ...sections.map(s => ({ id: s.id, order: s.order, type: 'section' as const })),\n ...assignments.map(a => ({ id: a.id, order: a.order, type: 'assignment' as const })),\n ].sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));\n\n const movedIdx = unified.findIndex(item => item.id === movedId && item.type === 'section');\n if (movedIdx === -1) {\n throw new TRPCError({ code: 'NOT_FOUND', message: 'Section not found in unified list' });\n }\n\n const withoutMoved = unified.filter(item => !(item.id === movedId && item.type === 'section'));\n\n let next: Array<{ id: string; type: 'section' | 'assignment' }> = [];\n\n if (position === 'start') {\n next = [{ id: movedId, type: 'section' }, ...withoutMoved.map(item => ({ id: item.id, type: item.type }))];\n } else if (position === 'end') {\n next = [...withoutMoved.map(item => ({ id: item.id, type: item.type })), { id: movedId, type: 'section' }];\n } else {\n const targetIdx = withoutMoved.findIndex(item => item.id === targetId);\n if (targetIdx === -1) {\n throw new TRPCError({ code: 'BAD_REQUEST', message: 'targetId not found in unified list' });\n }\n if (position === 'before') {\n next = [\n ...withoutMoved.slice(0, targetIdx).map(item => ({ id: item.id, type: item.type })),\n { id: movedId, type: 'section' },\n ...withoutMoved.slice(targetIdx).map(item => ({ id: item.id, type: item.type })),\n ];\n } else {\n next = [\n ...withoutMoved.slice(0, targetIdx + 1).map(item => ({ id: item.id, type: item.type })),\n { id: movedId, type: 'section' },\n ...withoutMoved.slice(targetIdx + 1).map(item => ({ id: item.id, type: item.type })),\n ];\n }\n }\n\n // Normalize to 1..n\n await Promise.all(\n next.map((item, index) => {\n if (item.type === 'section') {\n return tx.section.update({ where: { id: item.id }, data: { order: index + 1 } });\n } else {\n return tx.assignment.update({ where: { id: item.id }, data: { order: index + 1 } });\n }\n })\n );\n\n return tx.section.findUnique({ where: { id: movedId } });\n });\n\n return result;\n }),\n\n update: protectedTeacherProcedure\n .input(updateSectionSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n const section = await prisma.section.update({\n where: { id: input.id },\n data: {\n name: input.name,\n ...(input.color && {\n color: input.color,\n }),\n },\n });\n\n return section;\n }),\n\n reOrder: protectedTeacherProcedure\n .input(z.object({\n id: z.string(),\n classId: z.string(),\n order: z.number(),\n }))\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n // Update order and normalize unified list\n await prisma.$transaction(async (tx) => {\n await tx.section.update({\n where: { id: input.id },\n data: { order: input.order },\n });\n\n // Normalize entire unified list\n const [sections, assignments] = await Promise.all([\n tx.section.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n tx.assignment.findMany({\n where: { classId: input.classId },\n select: { id: true, order: true },\n }),\n ]);\n\n const unified = [\n ...sections.map(s => ({ id: s.id, order: s.order, type: 'section' as const })),\n ...assignments.map(a => ({ id: a.id, order: a.order, type: 'assignment' as const })),\n ].sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));\n\n await Promise.all(\n unified.map((item, index) => {\n if (item.type === 'section') {\n return tx.section.update({ where: { id: item.id }, data: { order: index + 1 } });\n } else {\n return tx.assignment.update({ where: { id: item.id }, data: { order: index + 1 } });\n }\n })\n );\n });\n\n return { id: input.id };\n }),\n\n delete: protectedTeacherProcedure\n .input(deleteSectionSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Verify user is a teacher of the class\n const classData = await prisma.class.findFirst({\n where: {\n id: input.classId,\n teachers: {\n some: {\n id: ctx.user.id,\n },\n },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a teacher\",\n });\n }\n\n await prisma.section.delete({\n where: { id: input.id },\n });\n\n return { id: input.id };\n }),\n}); "],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAsB,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;IAC5C,MAAM,EAAE,yBAAyB;SAC9B,KAAK,CAAC,mBAAmB,CAAC;SAC1B,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE;QACjC,IAAI,CAAC,GAAG,C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,CAAC;CACL,CAAC,CAAC","debug_id":"cc26fa87-90ce-5e16-b19c-83e9fbfd0a40"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"/","sources":["routers/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"/","sources":["routers/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA4DxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuMrB,CAAC"}
|
package/dist/routers/user.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0dff2490-6903-5dec-aa0c-7d8bd2ac7c23")}catch(e){}}();
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { createTRPCRouter, protectedProcedure } from "../trpc.js";
|
|
5
5
|
import { TRPCError } from "@trpc/server";
|
|
6
6
|
import { prisma } from "../lib/prisma.js";
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
8
|
+
import { env } from "../lib/config/env.js";
|
|
8
9
|
// Helper function to convert file path to backend proxy URL
|
|
9
10
|
function getFileUrl(filePath) {
|
|
10
11
|
if (!filePath)
|
|
@@ -14,7 +15,7 @@ function getFileUrl(filePath) {
|
|
|
14
15
|
return filePath;
|
|
15
16
|
}
|
|
16
17
|
// Convert GCS path to full backend proxy URL
|
|
17
|
-
const backendUrl =
|
|
18
|
+
const backendUrl = env.BACKEND_URL || 'http://localhost:3001';
|
|
18
19
|
return `${backendUrl}/api/files/${encodeURIComponent(filePath)}`;
|
|
19
20
|
}
|
|
20
21
|
// For direct file uploads (file already uploaded to GCS)
|
|
@@ -205,7 +206,7 @@ export const userRouter = createTRPCRouter({
|
|
|
205
206
|
const uniqueFilename = `${ctx.user.id}-${Date.now()}.${fileExtension}`;
|
|
206
207
|
const filePath = `users/${ctx.user.id}/profile/${uniqueFilename}`;
|
|
207
208
|
// Generate backend proxy upload URL instead of direct GCS signed URL
|
|
208
|
-
const backendUrl =
|
|
209
|
+
const backendUrl = env.BACKEND_URL || 'http://localhost:3001';
|
|
209
210
|
const uploadUrl = `${backendUrl}/api/upload/${encodeURIComponent(filePath)}`;
|
|
210
211
|
logger.info('Generated upload URL', {
|
|
211
212
|
userId: ctx.user.id,
|
|
@@ -233,4 +234,4 @@ export const userRouter = createTRPCRouter({
|
|
|
233
234
|
}),
|
|
234
235
|
});
|
|
235
236
|
//# sourceMappingURL=user.js.map
|
|
236
|
-
//# debugId=
|
|
237
|
+
//# debugId=0dff2490-6903-5dec-aa0c-7d8bd2ac7c23
|
package/dist/routers/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sources":["routers/user.ts"],"sourceRoot":"/","sourcesContent":["import { z } from \"zod\";\nimport { createTRPCRouter, protectedProcedure } from \"../trpc.js\";\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { createDirectUploadFiles, type DirectUploadFile } from \"../lib/fileUpload.js\";\nimport { getSignedUrl } from \"../lib/googleCloudStorage.js\";\nimport { logger } from \"../utils/logger.js\";\nimport { bucket } from \"../lib/googleCloudStorage.js\";\n\n// Helper function to convert file path to backend proxy URL\nfunction getFileUrl(filePath: string | null): string | null {\n if (!filePath) return null;\n \n // If it's already a full URL (DiceBear or external), return as is\n if (filePath.startsWith('http')) {\n return filePath;\n }\n \n // Convert GCS path to full backend proxy URL\n const backendUrl = process.env.BACKEND_URL || 'http://localhost:3001';\n return `${backendUrl}/api/files/${encodeURIComponent(filePath)}`;\n}\n\n// For direct file uploads (file already uploaded to GCS)\nconst fileUploadSchema = z.object({\n filePath: z.string().min(1, \"File path is required\"),\n fileName: z.string().min(1, \"File name is required\"),\n fileType: z.string().regex(/^image\\/(jpeg|jpg|png|gif|webp)$/i, \"Only image files (JPEG, PNG, GIF, WebP) are allowed\"),\n fileSize: z.number().max(5 * 1024 * 1024, \"File size must be less than 5MB\"),\n});\n\n// For DiceBear avatar URL\nconst dicebearSchema = z.object({\n url: z.string().url(\"Invalid DiceBear avatar URL\"),\n});\n\nconst profileSchema = z.object({\n displayName: z.string().nullable().optional().transform(val => val === null ? undefined : val),\n bio: z.string().nullable().optional().transform(val => val === null ? undefined : val),\n location: z.string().nullable().optional().transform(val => val === null ? undefined : val),\n website: z.union([\n z.string().url(),\n z.literal(\"\"),\n z.null().transform(() => undefined)\n ]).optional(),\n});\n\nconst updateProfileSchema = z.object({\n profile: profileSchema.optional(),\n // Support both custom file upload and DiceBear avatar\n profilePicture: fileUploadSchema.optional(),\n dicebearAvatar: dicebearSchema.optional(),\n});\n\nconst getUploadUrlSchema = z.object({\n fileName: z.string().min(1, \"File name is required\"),\n fileType: z.string().regex(/^image\\/(jpeg|jpg|png|gif|webp)$/i, \"Only image files are allowed\"),\n});\n\nexport const userRouter = createTRPCRouter({\n getProfile: protectedProcedure\n .query(async ({ ctx }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n const user = await prisma.user.findUnique({\n where: { id: ctx.user.id },\n select: {\n id: true,\n username: true,\n },\n });\n\n if (!user) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"User not found\",\n });\n }\n\n // Get user profile separately\n const userProfile = await prisma.userProfile.findUnique({\n where: { userId: ctx.user.id },\n });\n\n return {\n id: user.id,\n username: user.username,\n profile: userProfile ? {\n displayName: (userProfile as any).displayName || null,\n bio: (userProfile as any).bio || null,\n location: (userProfile as any).location || null,\n website: (userProfile as any).website || null,\n profilePicture: getFileUrl((userProfile as any).profilePicture),\n profilePictureThumbnail: getFileUrl((userProfile as any).profilePictureThumbnail),\n } : {\n displayName: null,\n bio: null,\n location: null,\n website: null,\n profilePicture: null,\n profilePictureThumbnail: null,\n },\n };\n }),\n\n updateProfile: protectedProcedure\n .input(updateProfileSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Get current profile to clean up old profile picture\n const currentProfile = await prisma.userProfile.findUnique({\n where: { userId: ctx.user.id },\n });\n\n let profilePictureUrl: string | null = null;\n let profilePictureThumbnail: string | null = null;\n\n // Handle custom profile picture (already uploaded to GCS)\n if (input.profilePicture) {\n try {\n // File is already uploaded to GCS, just use the path\n profilePictureUrl = input.profilePicture.filePath;\n \n // Generate thumbnail for the uploaded file\n // TODO: Implement thumbnail generation for direct uploads\n profilePictureThumbnail = null;\n\n // Clean up old profile picture if it exists\n if ((currentProfile as any)?.profilePicture) {\n // TODO: Implement file deletion logic here\n // await deleteFile((currentProfile as any).profilePicture);\n }\n } catch (error) {\n logger.error('Profile picture processing failed', { \n userId: ctx.user.id, \n error: error instanceof Error ? error.message : 'Unknown error' \n });\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to process profile picture. Please try again.\",\n });\n }\n }\n\n // Handle DiceBear avatar URL\n if (input.dicebearAvatar) {\n profilePictureUrl = input.dicebearAvatar.url;\n // No thumbnail for DiceBear avatars since they're SVG URLs\n profilePictureThumbnail = null;\n }\n\n // Prepare update data\n const updateData: any = {};\n if (input.profile) {\n if (input.profile.displayName !== undefined && input.profile.displayName !== null) {\n updateData.displayName = input.profile.displayName;\n }\n if (input.profile.bio !== undefined && input.profile.bio !== null) {\n updateData.bio = input.profile.bio;\n }\n if (input.profile.location !== undefined && input.profile.location !== null) {\n updateData.location = input.profile.location;\n }\n if (input.profile.website !== undefined && input.profile.website !== null) {\n updateData.website = input.profile.website;\n }\n }\n if (profilePictureUrl !== null) updateData.profilePicture = profilePictureUrl;\n if (profilePictureThumbnail !== null) updateData.profilePictureThumbnail = profilePictureThumbnail;\n\n // Upsert user profile with structured data\n const updatedProfile = await prisma.userProfile.upsert({\n where: { userId: ctx.user.id },\n create: {\n userId: ctx.user.id,\n ...updateData,\n },\n update: {\n ...updateData,\n updatedAt: new Date(),\n },\n });\n\n // Get username for response\n const user = await prisma.user.findUnique({\n where: { id: ctx.user.id },\n select: { username: true },\n });\n\n return {\n id: ctx.user.id,\n username: user?.username || '',\n profile: {\n displayName: (updatedProfile as any).displayName || null,\n bio: (updatedProfile as any).bio || null,\n location: (updatedProfile as any).location || null,\n website: (updatedProfile as any).website || null,\n profilePicture: getFileUrl((updatedProfile as any).profilePicture),\n profilePictureThumbnail: getFileUrl((updatedProfile as any).profilePictureThumbnail),\n },\n };\n }),\n\n getUploadUrl: protectedProcedure\n .input(getUploadUrlSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n try {\n // Generate unique filename\n const fileExtension = input.fileName.split('.').pop();\n const uniqueFilename = `${ctx.user.id}-${Date.now()}.${fileExtension}`;\n const filePath = `users/${ctx.user.id}/profile/${uniqueFilename}`;\n\n // Generate backend proxy upload URL instead of direct GCS signed URL\n const backendUrl = process.env.BACKEND_URL || 'http://localhost:3001';\n const uploadUrl = `${backendUrl}/api/upload/${encodeURIComponent(filePath)}`;\n\n logger.info('Generated upload URL', {\n userId: ctx.user.id,\n filePath,\n fileName: uniqueFilename,\n fileType: input.fileType,\n uploadUrl\n });\n\n return {\n uploadUrl,\n filePath,\n fileName: uniqueFilename,\n };\n } catch (error) {\n logger.error('Failed to generate upload URL', { \n userId: ctx.user.id, \n error: error instanceof Error ? error.message : 'Unknown error' \n });\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to generate upload URL\",\n });\n }\n }),\n}); "],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,4DAA4D;AAC5D,SAAS,UAAU,CAAC,QAAuB;IACzC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,kEAAkE;IAClE,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,6CAA6C;IAC7C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,uBAAuB,CAAC;IACtE,OAAO,GAAG,UAAU,cAAc,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;AACnE,CAAC;AAED,yDAAyD;AACzD,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;IACpD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;IACpD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,mCAAmC,EAAE,qDAAqD,CAAC;IACtH,QAAQ,EAAE,CAAC,CAAC,MAA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AAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAE7E,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;gBAClC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;gBACnB,QAAQ;gBACR,QAAQ,EAAE,cAAc;gBACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,SAAS;aACV,CAAC,CAAC;YAEH,OAAO;gBACL,SAAS;gBACT,QAAQ;gBACR,QAAQ,EAAE,cAAc;aACzB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBAC5C,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;gBACnB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC,CAAC;YACH,MAAM,IAAI,SAAS,CAAC;gBAClB,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;CACL,CAAC,CAAC","debug_id":"9fd79d80-c720-5d04-af6a-a66a555d5f74"}
|
|
1
|
+
{"version":3,"file":"user.js","sources":["routers/user.ts"],"sourceRoot":"/","sourcesContent":["import { z } from \"zod\";\nimport { createTRPCRouter, protectedProcedure } from \"../trpc.js\";\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { createDirectUploadFiles, type DirectUploadFile } from \"../lib/fileUpload.js\";\nimport { getSignedUrl } from \"../lib/googleCloudStorage.js\";\nimport { logger } from \"../utils/logger.js\";\nimport { bucket } from \"../lib/googleCloudStorage.js\";\nimport { env } from \"../lib/config/env.js\";\n\n// Helper function to convert file path to backend proxy URL\nfunction getFileUrl(filePath: string | null): string | null {\n if (!filePath) return null;\n \n // If it's already a full URL (DiceBear or external), return as is\n if (filePath.startsWith('http')) {\n return filePath;\n }\n \n // Convert GCS path to full backend proxy URL\n const backendUrl = env.BACKEND_URL || 'http://localhost:3001';\n return `${backendUrl}/api/files/${encodeURIComponent(filePath)}`;\n}\n\n// For direct file uploads (file already uploaded to GCS)\nconst fileUploadSchema = z.object({\n filePath: z.string().min(1, \"File path is required\"),\n fileName: z.string().min(1, \"File name is required\"),\n fileType: z.string().regex(/^image\\/(jpeg|jpg|png|gif|webp)$/i, \"Only image files (JPEG, PNG, GIF, WebP) are allowed\"),\n fileSize: z.number().max(5 * 1024 * 1024, \"File size must be less than 5MB\"),\n});\n\n// For DiceBear avatar URL\nconst dicebearSchema = z.object({\n url: z.string().url(\"Invalid DiceBear avatar URL\"),\n});\n\nconst profileSchema = z.object({\n displayName: z.string().nullable().optional().transform(val => val === null ? undefined : val),\n bio: z.string().nullable().optional().transform(val => val === null ? undefined : val),\n location: z.string().nullable().optional().transform(val => val === null ? undefined : val),\n website: z.union([\n z.string().url(),\n z.literal(\"\"),\n z.null().transform(() => undefined)\n ]).optional(),\n});\n\nconst updateProfileSchema = z.object({\n profile: profileSchema.optional(),\n // Support both custom file upload and DiceBear avatar\n profilePicture: fileUploadSchema.optional(),\n dicebearAvatar: dicebearSchema.optional(),\n});\n\nconst getUploadUrlSchema = z.object({\n fileName: z.string().min(1, \"File name is required\"),\n fileType: z.string().regex(/^image\\/(jpeg|jpg|png|gif|webp)$/i, \"Only image files are allowed\"),\n});\n\nexport const userRouter = createTRPCRouter({\n getProfile: protectedProcedure\n .query(async ({ ctx }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n const user = await prisma.user.findUnique({\n where: { id: ctx.user.id },\n select: {\n id: true,\n username: true,\n },\n });\n\n if (!user) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"User not found\",\n });\n }\n\n // Get user profile separately\n const userProfile = await prisma.userProfile.findUnique({\n where: { userId: ctx.user.id },\n });\n\n return {\n id: user.id,\n username: user.username,\n profile: userProfile ? {\n displayName: (userProfile as any).displayName || null,\n bio: (userProfile as any).bio || null,\n location: (userProfile as any).location || null,\n website: (userProfile as any).website || null,\n profilePicture: getFileUrl((userProfile as any).profilePicture),\n profilePictureThumbnail: getFileUrl((userProfile as any).profilePictureThumbnail),\n } : {\n displayName: null,\n bio: null,\n location: null,\n website: null,\n profilePicture: null,\n profilePictureThumbnail: null,\n },\n };\n }),\n\n updateProfile: protectedProcedure\n .input(updateProfileSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n // Get current profile to clean up old profile picture\n const currentProfile = await prisma.userProfile.findUnique({\n where: { userId: ctx.user.id },\n });\n\n let profilePictureUrl: string | null = null;\n let profilePictureThumbnail: string | null = null;\n\n // Handle custom profile picture (already uploaded to GCS)\n if (input.profilePicture) {\n try {\n // File is already uploaded to GCS, just use the path\n profilePictureUrl = input.profilePicture.filePath;\n \n // Generate thumbnail for the uploaded file\n // TODO: Implement thumbnail generation for direct uploads\n profilePictureThumbnail = null;\n\n // Clean up old profile picture if it exists\n if ((currentProfile as any)?.profilePicture) {\n // TODO: Implement file deletion logic here\n // await deleteFile((currentProfile as any).profilePicture);\n }\n } catch (error) {\n logger.error('Profile picture processing failed', { \n userId: ctx.user.id, \n error: error instanceof Error ? error.message : 'Unknown error' \n });\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to process profile picture. Please try again.\",\n });\n }\n }\n\n // Handle DiceBear avatar URL\n if (input.dicebearAvatar) {\n profilePictureUrl = input.dicebearAvatar.url;\n // No thumbnail for DiceBear avatars since they're SVG URLs\n profilePictureThumbnail = null;\n }\n\n // Prepare update data\n const updateData: any = {};\n if (input.profile) {\n if (input.profile.displayName !== undefined && input.profile.displayName !== null) {\n updateData.displayName = input.profile.displayName;\n }\n if (input.profile.bio !== undefined && input.profile.bio !== null) {\n updateData.bio = input.profile.bio;\n }\n if (input.profile.location !== undefined && input.profile.location !== null) {\n updateData.location = input.profile.location;\n }\n if (input.profile.website !== undefined && input.profile.website !== null) {\n updateData.website = input.profile.website;\n }\n }\n if (profilePictureUrl !== null) updateData.profilePicture = profilePictureUrl;\n if (profilePictureThumbnail !== null) updateData.profilePictureThumbnail = profilePictureThumbnail;\n\n // Upsert user profile with structured data\n const updatedProfile = await prisma.userProfile.upsert({\n where: { userId: ctx.user.id },\n create: {\n userId: ctx.user.id,\n ...updateData,\n },\n update: {\n ...updateData,\n updatedAt: new Date(),\n },\n });\n\n // Get username for response\n const user = await prisma.user.findUnique({\n where: { id: ctx.user.id },\n select: { username: true },\n });\n\n return {\n id: ctx.user.id,\n username: user?.username || '',\n profile: {\n displayName: (updatedProfile as any).displayName || null,\n bio: (updatedProfile as any).bio || null,\n location: (updatedProfile as any).location || null,\n website: (updatedProfile as any).website || null,\n profilePicture: getFileUrl((updatedProfile as any).profilePicture),\n profilePictureThumbnail: getFileUrl((updatedProfile as any).profilePictureThumbnail),\n },\n };\n }),\n\n getUploadUrl: protectedProcedure\n .input(getUploadUrlSchema)\n .mutation(async ({ ctx, input }) => {\n if (!ctx.user) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"User must be authenticated\",\n });\n }\n\n try {\n // Generate unique filename\n const fileExtension = input.fileName.split('.').pop();\n const uniqueFilename = `${ctx.user.id}-${Date.now()}.${fileExtension}`;\n const filePath = `users/${ctx.user.id}/profile/${uniqueFilename}`;\n\n // Generate backend proxy upload URL instead of direct GCS signed URL\n const backendUrl = env.BACKEND_URL || 'http://localhost:3001';\n const uploadUrl = `${backendUrl}/api/upload/${encodeURIComponent(filePath)}`;\n\n logger.info('Generated upload URL', {\n userId: ctx.user.id,\n filePath,\n fileName: uniqueFilename,\n fileType: input.fileType,\n uploadUrl\n });\n\n return {\n uploadUrl,\n filePath,\n fileName: uniqueFilename,\n };\n } catch (error) {\n logger.error('Failed to generate upload URL', { \n userId: ctx.user.id, \n error: error instanceof Error ? error.message : 'Unknown error' \n });\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to generate upload URL\",\n });\n }\n }),\n}); "],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE3C,4DAA4D;AAC5D,SAAS,UAAU,CAAC,QAAuB;IACzC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,kEAAkE;IAClE,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,6CAA6C;IAC7C,MAAM,UAAU,GAAG,GAAG,CAAC,WAAW,IAAI,uBAAuB,CAAC;IAC9D,OAAO,GAAG,UAAU,cAAc,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;AACnE,CAAC;AAED,yDAAyD;AACzD,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;IACpD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;IACpD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,mCAAmC,EAAE,qDAAqD,CAAC;IACtH,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,G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IAAI,CAAC,sBAAsB,EAAE;gBAClC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;gBACnB,QAAQ;gBACR,QAAQ,EAAE,cAAc;gBACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,SAAS;aACV,CAAC,CAAC;YAEH,OAAO;gBACL,SAAS;gBACT,QAAQ;gBACR,QAAQ,EAAE,cAAc;aACzB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBAC5C,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;gBACnB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC,CAAC;YACH,MAAM,IAAI,SAAS,CAAC;gBAClB,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;CACL,CAAC,CAAC","debug_id":"0dff2490-6903-5dec-aa0c-7d8bd2ac7c23"}
|
|
@@ -31,17 +31,17 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
31
31
|
syllabus: string | null;
|
|
32
32
|
} | null;
|
|
33
33
|
questions: {
|
|
34
|
+
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
34
35
|
type: import(".prisma/client").$Enums.WorksheetQuestionType;
|
|
35
36
|
id: string;
|
|
36
|
-
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
37
37
|
createdAt: Date;
|
|
38
38
|
order: number | null;
|
|
39
39
|
markScheme: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
40
40
|
updatedAt: Date;
|
|
41
|
-
points: number;
|
|
42
41
|
question: string;
|
|
43
42
|
worksheetId: string;
|
|
44
43
|
answer: string;
|
|
44
|
+
points: number;
|
|
45
45
|
}[];
|
|
46
46
|
} & {
|
|
47
47
|
id: string;
|
|
@@ -121,26 +121,26 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
121
121
|
points?: number | undefined;
|
|
122
122
|
};
|
|
123
123
|
output: {
|
|
124
|
+
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
124
125
|
type: import(".prisma/client").$Enums.WorksheetQuestionType;
|
|
125
126
|
id: string;
|
|
126
|
-
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
127
127
|
createdAt: Date;
|
|
128
128
|
order: number | null;
|
|
129
129
|
markScheme: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
130
130
|
updatedAt: Date;
|
|
131
|
-
points: number;
|
|
132
131
|
question: string;
|
|
133
132
|
worksheetId: string;
|
|
134
133
|
answer: string;
|
|
134
|
+
points: number;
|
|
135
135
|
};
|
|
136
136
|
meta: object;
|
|
137
137
|
}>;
|
|
138
138
|
reorderQuestions: import("@trpc/server").TRPCMutationProcedure<{
|
|
139
139
|
input: {
|
|
140
|
+
worksheetId: string;
|
|
140
141
|
movedId: string;
|
|
141
142
|
position: "before" | "after";
|
|
142
143
|
targetId: string;
|
|
143
|
-
worksheetId: string;
|
|
144
144
|
};
|
|
145
145
|
output: {
|
|
146
146
|
id: string;
|
|
@@ -151,25 +151,25 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
151
151
|
input: {
|
|
152
152
|
worksheetId: string;
|
|
153
153
|
questionId: string;
|
|
154
|
-
type?: "ESSAY" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "SHORT_ANSWER" | "LONG_ANSWER" | "MATH_EXPRESSION" | undefined;
|
|
155
154
|
options?: any;
|
|
155
|
+
type?: "ESSAY" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "SHORT_ANSWER" | "LONG_ANSWER" | "MATH_EXPRESSION" | undefined;
|
|
156
156
|
markScheme?: any;
|
|
157
|
-
points?: number | undefined;
|
|
158
157
|
question?: string | undefined;
|
|
159
158
|
answer?: string | undefined;
|
|
159
|
+
points?: number | undefined;
|
|
160
160
|
};
|
|
161
161
|
output: {
|
|
162
|
+
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
162
163
|
type: import(".prisma/client").$Enums.WorksheetQuestionType;
|
|
163
164
|
id: string;
|
|
164
|
-
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
165
165
|
createdAt: Date;
|
|
166
166
|
order: number | null;
|
|
167
167
|
markScheme: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
168
168
|
updatedAt: Date;
|
|
169
|
-
points: number;
|
|
170
169
|
question: string;
|
|
171
170
|
worksheetId: string;
|
|
172
171
|
answer: string;
|
|
172
|
+
points: number;
|
|
173
173
|
};
|
|
174
174
|
meta: object;
|
|
175
175
|
}>;
|
|
@@ -179,17 +179,17 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
179
179
|
questionId: string;
|
|
180
180
|
};
|
|
181
181
|
output: {
|
|
182
|
+
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
182
183
|
type: import(".prisma/client").$Enums.WorksheetQuestionType;
|
|
183
184
|
id: string;
|
|
184
|
-
options: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
185
185
|
createdAt: Date;
|
|
186
186
|
order: number | null;
|
|
187
187
|
markScheme: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
188
188
|
updatedAt: Date;
|
|
189
|
-
points: number;
|
|
190
189
|
question: string;
|
|
191
190
|
worksheetId: string;
|
|
192
191
|
answer: string;
|
|
192
|
+
points: number;
|
|
193
193
|
};
|
|
194
194
|
meta: object;
|
|
195
195
|
}>;
|
|
@@ -204,6 +204,7 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
204
204
|
id: string;
|
|
205
205
|
}[];
|
|
206
206
|
} & {
|
|
207
|
+
status: import(".prisma/client").$Enums.GenerationStatus | null;
|
|
207
208
|
id: string;
|
|
208
209
|
feedback: string | null;
|
|
209
210
|
studentId: string;
|
|
@@ -212,9 +213,9 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
212
213
|
points: number;
|
|
213
214
|
questionId: string;
|
|
214
215
|
response: string;
|
|
215
|
-
studentWorksheetResponseId: string | null;
|
|
216
216
|
isCorrect: boolean;
|
|
217
217
|
markschemeState: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
218
|
+
studentWorksheetResponseId: string | null;
|
|
218
219
|
})[];
|
|
219
220
|
} & {
|
|
220
221
|
id: string;
|
|
@@ -230,12 +231,13 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
230
231
|
}>;
|
|
231
232
|
answerQuestion: import("@trpc/server").TRPCMutationProcedure<{
|
|
232
233
|
input: {
|
|
233
|
-
questionId: string;
|
|
234
234
|
worksheetResponseId: string;
|
|
235
|
+
questionId: string;
|
|
235
236
|
response: string;
|
|
236
237
|
};
|
|
237
238
|
output: ({
|
|
238
239
|
responses: {
|
|
240
|
+
status: import(".prisma/client").$Enums.GenerationStatus | null;
|
|
239
241
|
id: string;
|
|
240
242
|
feedback: string | null;
|
|
241
243
|
studentId: string;
|
|
@@ -244,9 +246,9 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
244
246
|
points: number;
|
|
245
247
|
questionId: string;
|
|
246
248
|
response: string;
|
|
247
|
-
studentWorksheetResponseId: string | null;
|
|
248
249
|
isCorrect: boolean;
|
|
249
250
|
markschemeState: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
251
|
+
studentWorksheetResponseId: string | null;
|
|
250
252
|
}[];
|
|
251
253
|
} & {
|
|
252
254
|
id: string;
|
|
@@ -260,46 +262,37 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
260
262
|
}) | null;
|
|
261
263
|
meta: object;
|
|
262
264
|
}>;
|
|
263
|
-
|
|
265
|
+
cancelAutoGrading: import("@trpc/server").TRPCMutationProcedure<{
|
|
264
266
|
input: {
|
|
265
267
|
worksheetResponseId: string;
|
|
268
|
+
questionId: string;
|
|
266
269
|
};
|
|
267
270
|
output: {
|
|
268
|
-
|
|
269
|
-
id: string;
|
|
270
|
-
feedback: string | null;
|
|
271
|
-
studentId: string;
|
|
272
|
-
createdAt: Date;
|
|
273
|
-
updatedAt: Date | null;
|
|
274
|
-
points: number;
|
|
275
|
-
questionId: string;
|
|
276
|
-
response: string;
|
|
277
|
-
studentWorksheetResponseId: string | null;
|
|
278
|
-
isCorrect: boolean;
|
|
279
|
-
markschemeState: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
280
|
-
}[];
|
|
281
|
-
} & {
|
|
271
|
+
status: import(".prisma/client").$Enums.GenerationStatus | null;
|
|
282
272
|
id: string;
|
|
283
|
-
|
|
273
|
+
feedback: string | null;
|
|
284
274
|
studentId: string;
|
|
285
275
|
createdAt: Date;
|
|
286
|
-
updatedAt: Date;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
276
|
+
updatedAt: Date | null;
|
|
277
|
+
points: number;
|
|
278
|
+
questionId: string;
|
|
279
|
+
response: string;
|
|
280
|
+
isCorrect: boolean;
|
|
281
|
+
markschemeState: import("@prisma/client/runtime/library.js").JsonValue | null;
|
|
282
|
+
studentWorksheetResponseId: string | null;
|
|
290
283
|
};
|
|
291
284
|
meta: object;
|
|
292
285
|
}>;
|
|
293
286
|
gradeAnswer: import("@trpc/server").TRPCMutationProcedure<{
|
|
294
287
|
input: {
|
|
295
288
|
questionId: string;
|
|
296
|
-
studentWorksheetResponseId: string;
|
|
297
289
|
isCorrect: boolean;
|
|
290
|
+
studentWorksheetResponseId: string;
|
|
298
291
|
feedback?: string | undefined;
|
|
299
292
|
points?: number | undefined;
|
|
300
293
|
response?: string | undefined;
|
|
301
|
-
responseId?: string | undefined;
|
|
302
294
|
markschemeState?: any;
|
|
295
|
+
responseId?: string | undefined;
|
|
303
296
|
};
|
|
304
297
|
output: any;
|
|
305
298
|
meta: object;
|
|
@@ -310,6 +303,7 @@ export declare const worksheetRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
310
303
|
responseId: string;
|
|
311
304
|
};
|
|
312
305
|
output: {
|
|
306
|
+
status: import(".prisma/client").$Enums.GenerationStatus | null;
|
|
313
307
|
id: string;
|
|
314
308
|
content: string;
|
|
315
309
|
createdAt: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worksheet.d.ts","sourceRoot":"/","sources":["routers/worksheet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA8KA,MAAM
|
|
1
|
+
{"version":3,"file":"worksheet.d.ts","sourceRoot":"/","sources":["routers/worksheet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA8KA,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6UhC,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8ce7e00a-a700-5561-86f2-98c6c27ff6d8")}catch(e){}}();
|
|
3
3
|
import { TRPCError } from "@trpc/server";
|
|
4
4
|
import { createTRPCRouter, protectedProcedure } from "../trpc.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { prisma } from "../lib/prisma.js";
|
|
7
|
+
import { GenerationStatus } from "@prisma/client";
|
|
7
8
|
export const worksheetRouter = createTRPCRouter({
|
|
8
9
|
// Get a single worksheet with all questions
|
|
9
10
|
getWorksheet: protectedProcedure
|
|
@@ -309,6 +310,7 @@ export const worksheetRouter = createTRPCRouter({
|
|
|
309
310
|
data: { response,
|
|
310
311
|
...(isMarkableByAlgo && { isCorrect: response === correctAnswer }),
|
|
311
312
|
...(isMarkableByAlgo && { points: response === correctAnswer ? marksAwardedIfCorrect : 0 }),
|
|
313
|
+
status: GenerationStatus.NOT_STARTED,
|
|
312
314
|
},
|
|
313
315
|
});
|
|
314
316
|
}
|
|
@@ -334,44 +336,20 @@ export const worksheetRouter = createTRPCRouter({
|
|
|
334
336
|
});
|
|
335
337
|
return updatedWorksheetResponse;
|
|
336
338
|
}),
|
|
337
|
-
|
|
339
|
+
cancelAutoGrading: protectedProcedure
|
|
338
340
|
.input(z.object({
|
|
339
341
|
worksheetResponseId: z.string(),
|
|
342
|
+
questionId: z.string(),
|
|
340
343
|
}))
|
|
341
344
|
.mutation(async ({ ctx, input }) => {
|
|
342
|
-
const { worksheetResponseId } = input;
|
|
343
|
-
const
|
|
344
|
-
where: { id: worksheetResponseId },
|
|
345
|
-
include: {
|
|
346
|
-
worksheet: {
|
|
347
|
-
include: {
|
|
348
|
-
questions: true,
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
responses: true,
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
if (!worksheetResponse) {
|
|
355
|
-
throw new TRPCError({ code: 'NOT_FOUND', message: 'Worksheet response not found' });
|
|
356
|
-
}
|
|
357
|
-
if (worksheetResponse.submitted) {
|
|
358
|
-
throw new TRPCError({ code: 'BAD_REQUEST', message: 'Worksheet already submitted' });
|
|
359
|
-
}
|
|
360
|
-
// Mark worksheet as submitted
|
|
361
|
-
const submittedWorksheet = await prisma.studentWorksheetResponse.update({
|
|
362
|
-
where: { id: worksheetResponseId },
|
|
345
|
+
const { worksheetResponseId, questionId } = input;
|
|
346
|
+
const updatedQuestion = await prisma.studentQuestionProgress.update({
|
|
347
|
+
where: { id: questionId, studentWorksheetResponseId: worksheetResponseId },
|
|
363
348
|
data: {
|
|
364
|
-
|
|
365
|
-
submittedAt: new Date(),
|
|
366
|
-
},
|
|
367
|
-
include: {
|
|
368
|
-
responses: true,
|
|
349
|
+
status: GenerationStatus.CANCELLED,
|
|
369
350
|
},
|
|
370
351
|
});
|
|
371
|
-
|
|
372
|
-
// For now, we'll just mark all answers as pending review
|
|
373
|
-
// You could integrate with an AI service to auto-grade certain question types
|
|
374
|
-
return submittedWorksheet;
|
|
352
|
+
return updatedQuestion;
|
|
375
353
|
}),
|
|
376
354
|
// Grade a student's answer
|
|
377
355
|
gradeAnswer: protectedProcedure
|
|
@@ -470,4 +448,4 @@ export const worksheetRouter = createTRPCRouter({
|
|
|
470
448
|
}),
|
|
471
449
|
});
|
|
472
450
|
//# sourceMappingURL=worksheet.js.map
|
|
473
|
-
//# debugId=
|
|
451
|
+
//# debugId=8ce7e00a-a700-5561-86f2-98c6c27ff6d8
|