@studious-lms/server 1.2.53 → 1.3.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.
Files changed (477) hide show
  1. package/.coderabbit.yaml +9 -0
  2. package/.env.example +9 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +102 -8
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/config/env.d.ts +21 -0
  7. package/dist/lib/config/env.d.ts.map +1 -1
  8. package/dist/lib/config/env.js +8 -2
  9. package/dist/lib/config/env.js.map +1 -1
  10. package/dist/lib/fileUpload.d.ts.map +1 -1
  11. package/dist/lib/fileUpload.js +2 -2
  12. package/dist/lib/fileUpload.js.map +1 -1
  13. package/dist/lib/googleCloudStorage.d.ts +6 -0
  14. package/dist/lib/googleCloudStorage.d.ts.map +1 -1
  15. package/dist/lib/googleCloudStorage.js +19 -2
  16. package/dist/lib/googleCloudStorage.js.map +1 -1
  17. package/dist/lib/pusher.d.ts +4 -1
  18. package/dist/lib/pusher.d.ts.map +1 -1
  19. package/dist/lib/pusher.js +6 -3
  20. package/dist/lib/pusher.js.map +1 -1
  21. package/dist/lib/redis.d.ts +5 -0
  22. package/dist/lib/redis.d.ts.map +1 -0
  23. package/dist/lib/redis.js +53 -0
  24. package/dist/lib/redis.js.map +1 -0
  25. package/dist/lib/thumbnailGenerator.d.ts +0 -21
  26. package/dist/lib/thumbnailGenerator.d.ts.map +1 -1
  27. package/dist/lib/thumbnailGenerator.js +157 -160
  28. package/dist/lib/thumbnailGenerator.js.map +1 -1
  29. package/dist/middleware/auth.d.ts.map +1 -1
  30. package/dist/middleware/auth.js +33 -95
  31. package/dist/middleware/auth.js.map +1 -1
  32. package/dist/models/agenda.d.ts +97 -0
  33. package/dist/models/agenda.d.ts.map +1 -0
  34. package/dist/models/agenda.js +40 -0
  35. package/dist/models/agenda.js.map +1 -0
  36. package/dist/models/announcement.d.ts +223 -0
  37. package/dist/models/announcement.d.ts.map +1 -0
  38. package/dist/models/announcement.js +120 -0
  39. package/dist/models/announcement.js.map +1 -0
  40. package/dist/models/assignment.d.ts +1292 -0
  41. package/dist/models/assignment.d.ts.map +1 -0
  42. package/dist/models/assignment.js +309 -0
  43. package/dist/models/assignment.js.map +1 -0
  44. package/dist/models/attendance.d.ts +180 -0
  45. package/dist/models/attendance.d.ts.map +1 -0
  46. package/dist/models/attendance.js +188 -0
  47. package/dist/models/attendance.js.map +1 -0
  48. package/dist/models/auth.d.ts +153 -0
  49. package/dist/models/auth.d.ts.map +1 -0
  50. package/dist/models/auth.js +217 -0
  51. package/dist/models/auth.js.map +1 -0
  52. package/dist/models/class.d.ts +439 -0
  53. package/dist/models/class.d.ts.map +1 -0
  54. package/dist/models/class.js +546 -0
  55. package/dist/models/class.js.map +1 -0
  56. package/dist/models/comment.d.ts +171 -0
  57. package/dist/models/comment.d.ts.map +1 -0
  58. package/dist/models/comment.js +138 -0
  59. package/dist/models/comment.js.map +1 -0
  60. package/dist/models/conversation.d.ts +164 -0
  61. package/dist/models/conversation.d.ts.map +1 -0
  62. package/dist/models/conversation.js +175 -0
  63. package/dist/models/conversation.js.map +1 -0
  64. package/dist/models/event.d.ts +295 -0
  65. package/dist/models/event.d.ts.map +1 -0
  66. package/dist/models/event.js +145 -0
  67. package/dist/models/event.js.map +1 -0
  68. package/dist/models/file.d.ts +536 -0
  69. package/dist/models/file.d.ts.map +1 -0
  70. package/dist/models/file.js +126 -0
  71. package/dist/models/file.js.map +1 -0
  72. package/dist/models/folder.d.ts +295 -0
  73. package/dist/models/folder.d.ts.map +1 -0
  74. package/dist/models/folder.js +202 -0
  75. package/dist/models/folder.js.map +1 -0
  76. package/dist/models/labChat.d.ts +243 -0
  77. package/dist/models/labChat.d.ts.map +1 -0
  78. package/dist/models/labChat.js +204 -0
  79. package/dist/models/labChat.js.map +1 -0
  80. package/dist/models/marketing.d.ts +72 -0
  81. package/dist/models/marketing.d.ts.map +1 -0
  82. package/dist/models/marketing.js +26 -0
  83. package/dist/models/marketing.js.map +1 -0
  84. package/dist/models/message.d.ts +100 -0
  85. package/dist/models/message.d.ts.map +1 -0
  86. package/dist/models/message.js +131 -0
  87. package/dist/models/message.js.map +1 -0
  88. package/dist/models/newtonChat.d.ts +72 -0
  89. package/dist/models/newtonChat.d.ts.map +1 -0
  90. package/dist/models/newtonChat.js +61 -0
  91. package/dist/models/newtonChat.js.map +1 -0
  92. package/dist/models/notification.d.ts +65 -0
  93. package/dist/models/notification.d.ts.map +1 -0
  94. package/dist/models/notification.js +46 -0
  95. package/dist/models/notification.js.map +1 -0
  96. package/dist/models/section.d.ts +102 -0
  97. package/dist/models/section.d.ts.map +1 -0
  98. package/dist/models/section.js +83 -0
  99. package/dist/models/section.js.map +1 -0
  100. package/dist/models/user.d.ts +39 -0
  101. package/dist/models/user.d.ts.map +1 -0
  102. package/dist/models/user.js +38 -0
  103. package/dist/models/user.js.map +1 -0
  104. package/dist/models/worksheet.d.ts +460 -0
  105. package/dist/models/worksheet.d.ts.map +1 -0
  106. package/dist/models/worksheet.js +200 -0
  107. package/dist/models/worksheet.js.map +1 -0
  108. package/dist/pipelines/aiLabChat.d.ts +21 -0
  109. package/dist/pipelines/aiLabChat.d.ts.map +1 -0
  110. package/dist/pipelines/aiLabChat.js +460 -0
  111. package/dist/pipelines/aiLabChat.js.map +1 -0
  112. package/dist/pipelines/aiNewtonChat.d.ts +30 -0
  113. package/dist/pipelines/aiNewtonChat.d.ts.map +1 -0
  114. package/dist/pipelines/aiNewtonChat.js +289 -0
  115. package/dist/pipelines/aiNewtonChat.js.map +1 -0
  116. package/dist/pipelines/gradeWorksheet.d.ts +30 -0
  117. package/dist/pipelines/gradeWorksheet.d.ts.map +1 -0
  118. package/dist/pipelines/gradeWorksheet.js +252 -0
  119. package/dist/pipelines/gradeWorksheet.js.map +1 -0
  120. package/dist/routers/_app.d.ts +1393 -1267
  121. package/dist/routers/_app.d.ts.map +1 -1
  122. package/dist/routers/agenda.d.ts +22 -22
  123. package/dist/routers/agenda.d.ts.map +1 -1
  124. package/dist/routers/agenda.js +4 -65
  125. package/dist/routers/agenda.js.map +1 -1
  126. package/dist/routers/announcement.d.ts +16 -16
  127. package/dist/routers/announcement.d.ts.map +1 -1
  128. package/dist/routers/announcement.js +37 -446
  129. package/dist/routers/announcement.js.map +1 -1
  130. package/dist/routers/assignment.d.ts +300 -378
  131. package/dist/routers/assignment.d.ts.map +1 -1
  132. package/dist/routers/assignment.js +78 -1868
  133. package/dist/routers/assignment.js.map +1 -1
  134. package/dist/routers/attendance.d.ts +19 -9
  135. package/dist/routers/attendance.d.ts.map +1 -1
  136. package/dist/routers/attendance.js +7 -264
  137. package/dist/routers/attendance.js.map +1 -1
  138. package/dist/routers/auth.d.ts +2 -2
  139. package/dist/routers/auth.d.ts.map +1 -1
  140. package/dist/routers/auth.js +29 -354
  141. package/dist/routers/auth.js.map +1 -1
  142. package/dist/routers/class.d.ts +139 -68
  143. package/dist/routers/class.d.ts.map +1 -1
  144. package/dist/routers/class.js +82 -1052
  145. package/dist/routers/class.js.map +1 -1
  146. package/dist/routers/comment.d.ts +6 -42
  147. package/dist/routers/comment.d.ts.map +1 -1
  148. package/dist/routers/comment.js +24 -244
  149. package/dist/routers/comment.js.map +1 -1
  150. package/dist/routers/conversation.d.ts +45 -7
  151. package/dist/routers/conversation.d.ts.map +1 -1
  152. package/dist/routers/conversation.js +19 -327
  153. package/dist/routers/conversation.js.map +1 -1
  154. package/dist/routers/event.d.ts +36 -36
  155. package/dist/routers/event.d.ts.map +1 -1
  156. package/dist/routers/event.js +13 -433
  157. package/dist/routers/event.js.map +1 -1
  158. package/dist/routers/file.d.ts +2 -2
  159. package/dist/routers/file.d.ts.map +1 -1
  160. package/dist/routers/file.js +9 -323
  161. package/dist/routers/file.js.map +1 -1
  162. package/dist/routers/folder.d.ts +21 -14
  163. package/dist/routers/folder.d.ts.map +1 -1
  164. package/dist/routers/folder.js +34 -745
  165. package/dist/routers/folder.js.map +1 -1
  166. package/dist/routers/labChat.d.ts +11 -10
  167. package/dist/routers/labChat.d.ts.map +1 -1
  168. package/dist/routers/labChat.js +19 -570
  169. package/dist/routers/labChat.js.map +1 -1
  170. package/dist/routers/marketing.d.ts +1 -1
  171. package/dist/routers/marketing.d.ts.map +1 -1
  172. package/dist/routers/marketing.js +7 -56
  173. package/dist/routers/marketing.js.map +1 -1
  174. package/dist/routers/message.d.ts +2 -2
  175. package/dist/routers/message.d.ts.map +1 -1
  176. package/dist/routers/message.js +27 -522
  177. package/dist/routers/message.js.map +1 -1
  178. package/dist/routers/newtonChat.d.ts +1 -1
  179. package/dist/routers/newtonChat.d.ts.map +1 -1
  180. package/dist/routers/newtonChat.js +7 -246
  181. package/dist/routers/newtonChat.js.map +1 -1
  182. package/dist/routers/notifications.d.ts +4 -4
  183. package/dist/routers/notifications.d.ts.map +1 -1
  184. package/dist/routers/notifications.js +18 -83
  185. package/dist/routers/notifications.js.map +1 -1
  186. package/dist/routers/section.d.ts +4 -4
  187. package/dist/routers/section.d.ts.map +1 -1
  188. package/dist/routers/section.js +14 -286
  189. package/dist/routers/section.js.map +1 -1
  190. package/dist/routers/user.d.ts +1 -1
  191. package/dist/routers/user.d.ts.map +1 -1
  192. package/dist/routers/user.js +32 -207
  193. package/dist/routers/user.js.map +1 -1
  194. package/dist/routers/worksheet.d.ts +51 -38
  195. package/dist/routers/worksheet.d.ts.map +1 -1
  196. package/dist/routers/worksheet.js +79 -394
  197. package/dist/routers/worksheet.js.map +1 -1
  198. package/dist/seedDatabase.d.ts +1 -1
  199. package/dist/server/pipelines/gradeWorksheet.d.ts +6 -6
  200. package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -1
  201. package/dist/server/pipelines/gradeWorksheet.js +12 -5
  202. package/dist/server/pipelines/gradeWorksheet.js.map +1 -1
  203. package/dist/services/agenda.d.ts +100 -0
  204. package/dist/services/agenda.d.ts.map +1 -0
  205. package/dist/services/agenda.js +21 -0
  206. package/dist/services/agenda.js.map +1 -0
  207. package/dist/services/announcement.d.ts +135 -0
  208. package/dist/services/announcement.d.ts.map +1 -0
  209. package/dist/services/announcement.js +223 -0
  210. package/dist/services/announcement.js.map +1 -0
  211. package/dist/services/assignment.d.ts +1462 -0
  212. package/dist/services/assignment.d.ts.map +1 -0
  213. package/dist/services/assignment.js +898 -0
  214. package/dist/services/assignment.js.map +1 -0
  215. package/dist/services/attendance.d.ts +93 -0
  216. package/dist/services/attendance.d.ts.map +1 -0
  217. package/dist/services/attendance.js +61 -0
  218. package/dist/services/attendance.js.map +1 -0
  219. package/dist/services/auth.d.ts +68 -0
  220. package/dist/services/auth.d.ts.map +1 -0
  221. package/dist/services/auth.js +218 -0
  222. package/dist/services/auth.js.map +1 -0
  223. package/dist/services/class.d.ts +621 -0
  224. package/dist/services/class.d.ts.map +1 -0
  225. package/dist/services/class.js +474 -0
  226. package/dist/services/class.js.map +1 -0
  227. package/dist/services/comment.d.ts +100 -0
  228. package/dist/services/comment.d.ts.map +1 -0
  229. package/dist/services/comment.js +83 -0
  230. package/dist/services/comment.js.map +1 -0
  231. package/dist/services/conversation.d.ts +159 -0
  232. package/dist/services/conversation.d.ts.map +1 -0
  233. package/dist/services/conversation.js +138 -0
  234. package/dist/services/conversation.js.map +1 -0
  235. package/dist/services/event.d.ts +216 -0
  236. package/dist/services/event.d.ts.map +1 -0
  237. package/dist/services/event.js +168 -0
  238. package/dist/services/event.js.map +1 -0
  239. package/dist/services/file.d.ts +74 -0
  240. package/dist/services/file.d.ts.map +1 -0
  241. package/dist/services/file.js +133 -0
  242. package/dist/services/file.js.map +1 -0
  243. package/dist/services/folder.d.ts +239 -0
  244. package/dist/services/folder.d.ts.map +1 -0
  245. package/dist/services/folder.js +248 -0
  246. package/dist/services/folder.js.map +1 -0
  247. package/dist/services/labChat.d.ts +165 -0
  248. package/dist/services/labChat.d.ts.map +1 -0
  249. package/dist/services/labChat.js +289 -0
  250. package/dist/services/labChat.js.map +1 -0
  251. package/dist/services/marketing.d.ts +50 -0
  252. package/dist/services/marketing.d.ts.map +1 -0
  253. package/dist/services/marketing.js +32 -0
  254. package/dist/services/marketing.js.map +1 -0
  255. package/dist/services/message.d.ts +95 -0
  256. package/dist/services/message.d.ts.map +1 -0
  257. package/dist/services/message.js +350 -0
  258. package/dist/services/message.js.map +1 -0
  259. package/dist/services/newtonChat.d.ts +22 -0
  260. package/dist/services/newtonChat.d.ts.map +1 -0
  261. package/dist/services/newtonChat.js +174 -0
  262. package/dist/services/newtonChat.js.map +1 -0
  263. package/dist/services/notification.d.ts +65 -0
  264. package/dist/services/notification.d.ts.map +1 -0
  265. package/dist/services/notification.js +33 -0
  266. package/dist/services/notification.js.map +1 -0
  267. package/dist/services/section.d.ts +53 -0
  268. package/dist/services/section.d.ts.map +1 -0
  269. package/dist/services/section.js +199 -0
  270. package/dist/services/section.js.map +1 -0
  271. package/dist/services/user.d.ts +48 -0
  272. package/dist/services/user.d.ts.map +1 -0
  273. package/dist/services/user.js +141 -0
  274. package/dist/services/user.js.map +1 -0
  275. package/dist/services/worksheet.d.ts +239 -0
  276. package/dist/services/worksheet.d.ts.map +1 -0
  277. package/dist/services/worksheet.js +235 -0
  278. package/dist/services/worksheet.js.map +1 -0
  279. package/dist/utils/aiUser.d.ts +1 -3
  280. package/dist/utils/aiUser.d.ts.map +1 -1
  281. package/dist/utils/aiUser.js +6 -5
  282. package/dist/utils/aiUser.js.map +1 -1
  283. package/dist/utils/email.d.ts +3 -0
  284. package/dist/utils/email.d.ts.map +1 -1
  285. package/dist/utils/email.js +7 -4
  286. package/dist/utils/email.js.map +1 -1
  287. package/dist/utils/generateInviteCode.d.ts +1 -2
  288. package/dist/utils/generateInviteCode.d.ts.map +1 -1
  289. package/dist/utils/generateInviteCode.js +3 -4
  290. package/dist/utils/generateInviteCode.js.map +1 -1
  291. package/dist/utils/inference.d.ts +3 -0
  292. package/dist/utils/inference.d.ts.map +1 -1
  293. package/dist/utils/inference.js +7 -4
  294. package/dist/utils/inference.js.map +1 -1
  295. package/dist/utils/logger.d.ts +3 -0
  296. package/dist/utils/logger.d.ts.map +1 -1
  297. package/dist/utils/logger.js +5 -2
  298. package/dist/utils/logger.js.map +1 -1
  299. package/dist/utils/prismaErrorHandler.d.ts.map +1 -1
  300. package/dist/utils/prismaErrorHandler.js +5 -2
  301. package/dist/utils/prismaErrorHandler.js.map +1 -1
  302. package/dist/utils/prismaWrapper.d.ts +1 -0
  303. package/dist/utils/prismaWrapper.d.ts.map +1 -1
  304. package/dist/utils/prismaWrapper.js +6 -2
  305. package/dist/utils/prismaWrapper.js.map +1 -1
  306. package/docker-compose.yml +5 -0
  307. package/package.json +4 -3
  308. package/src/index.ts +119 -12
  309. package/src/lib/config/env.ts +6 -0
  310. package/src/lib/fileUpload.ts +0 -1
  311. package/src/lib/googleCloudStorage.ts +17 -0
  312. package/src/lib/pusher.ts +5 -1
  313. package/src/lib/redis.ts +56 -0
  314. package/src/lib/thumbnailGenerator.ts +170 -168
  315. package/src/middleware/auth.ts +80 -137
  316. package/src/models/agenda.ts +46 -0
  317. package/src/models/announcement.ts +134 -0
  318. package/src/models/assignment.ts +322 -0
  319. package/src/models/attendance.ts +208 -0
  320. package/src/models/auth.ts +247 -0
  321. package/src/models/class.ts +598 -0
  322. package/src/models/comment.ts +152 -0
  323. package/src/models/conversation.ts +200 -0
  324. package/src/models/event.ts +177 -0
  325. package/src/models/file.ts +129 -0
  326. package/src/models/folder.ts +225 -0
  327. package/src/models/labChat.ts +213 -0
  328. package/src/models/marketing.ts +45 -0
  329. package/src/models/message.ts +153 -0
  330. package/src/models/newtonChat.ts +70 -0
  331. package/src/models/notification.ts +54 -0
  332. package/src/models/section.ts +98 -0
  333. package/src/models/user.ts +47 -0
  334. package/src/models/worksheet.ts +294 -0
  335. package/src/{server/pipelines → pipelines}/aiLabChat.ts +11 -7
  336. package/src/{server/pipelines → pipelines}/aiNewtonChat.ts +9 -5
  337. package/src/{server/pipelines → pipelines}/gradeWorksheet.ts +25 -14
  338. package/src/routers/agenda.ts +3 -66
  339. package/src/routers/announcement.ts +54 -495
  340. package/src/routers/assignment.ts +126 -2018
  341. package/src/routers/attendance.ts +15 -276
  342. package/src/routers/auth.ts +79 -442
  343. package/src/routers/class.ts +263 -1187
  344. package/src/routers/comment.ts +61 -288
  345. package/src/routers/conversation.ts +51 -360
  346. package/src/routers/event.ts +50 -481
  347. package/src/routers/file.ts +45 -368
  348. package/src/routers/folder.ts +107 -836
  349. package/src/routers/labChat.ts +29 -605
  350. package/src/routers/marketing.ts +35 -77
  351. package/src/routers/message.ts +45 -571
  352. package/src/routers/newtonChat.ts +17 -278
  353. package/src/routers/notifications.ts +32 -82
  354. package/src/routers/section.ts +46 -330
  355. package/src/routers/user.ts +49 -227
  356. package/src/routers/worksheet.ts +215 -503
  357. package/src/services/agenda.ts +21 -0
  358. package/src/services/announcement.ts +290 -0
  359. package/src/services/assignment.ts +1198 -0
  360. package/src/services/attendance.ts +85 -0
  361. package/src/services/auth.ts +277 -0
  362. package/src/services/class.ts +622 -0
  363. package/src/services/comment.ts +106 -0
  364. package/src/services/conversation.ts +213 -0
  365. package/src/services/event.ts +231 -0
  366. package/src/services/file.ts +167 -0
  367. package/src/services/folder.ts +316 -0
  368. package/src/services/labChat.ts +352 -0
  369. package/src/services/marketing.ts +57 -0
  370. package/src/services/message.ts +461 -0
  371. package/src/services/newtonChat.ts +222 -0
  372. package/src/services/notification.ts +50 -0
  373. package/src/services/section.ts +283 -0
  374. package/src/services/user.ts +172 -0
  375. package/src/services/worksheet.ts +358 -0
  376. package/src/utils/aiUser.ts +4 -3
  377. package/src/utils/email.ts +5 -3
  378. package/src/utils/generateInviteCode.ts +1 -3
  379. package/src/utils/inference.ts +5 -2
  380. package/src/utils/logger.ts +3 -1
  381. package/src/utils/prismaErrorHandler.ts +3 -0
  382. package/src/utils/prismaWrapper.ts +4 -0
  383. package/tests/globalSetup.ts +62 -0
  384. package/tests/helpers.ts +22 -0
  385. package/tests/middleware/security.test.ts +42 -0
  386. package/tests/routers/agenda.test.ts +138 -0
  387. package/tests/routers/announcement.test.ts +490 -0
  388. package/tests/routers/assignment.test.ts +837 -0
  389. package/tests/{attendance.test.ts → routers/attendance.test.ts} +6 -14
  390. package/tests/routers/auth.test.ts +171 -0
  391. package/tests/{class.test.ts → routers/class.test.ts} +131 -85
  392. package/tests/routers/comment.test.ts +126 -0
  393. package/tests/routers/conversation.test.ts +145 -0
  394. package/tests/{event.test.ts → routers/event.test.ts} +93 -32
  395. package/tests/routers/folder.test.ts +178 -0
  396. package/tests/routers/labChat.test.ts +115 -0
  397. package/tests/routers/marketing.test.ts +59 -0
  398. package/tests/routers/message.test.ts +123 -0
  399. package/tests/routers/notification.test.ts +69 -0
  400. package/tests/{section.test.ts → routers/section.test.ts} +5 -13
  401. package/tests/server/rateLimit.test.ts +73 -0
  402. package/tests/setup.ts +18 -92
  403. package/tests/user.test.ts +9 -31
  404. package/tests/utils/aiUser.test.ts +22 -0
  405. package/tests/utils/generateInviteCode.test.ts +24 -0
  406. package/tests/utils/logger.test.ts +74 -0
  407. package/tests/utils/prismaErrorHandler.test.ts +101 -0
  408. package/tests/utils/prismaWrapper.test.ts +82 -0
  409. package/tests/worksheet.test.ts +181 -0
  410. package/vitest.config.ts +6 -3
  411. package/vitest.unit.config.ts +21 -0
  412. package/TODO.md +0 -2
  413. package/coverage/base.css +0 -224
  414. package/coverage/block-navigation.js +0 -87
  415. package/coverage/clover.xml +0 -12110
  416. package/coverage/coverage-final.json +0 -44
  417. package/coverage/favicon.png +0 -0
  418. package/coverage/index.html +0 -221
  419. package/coverage/prettify.css +0 -1
  420. package/coverage/prettify.js +0 -2
  421. package/coverage/server/index.html +0 -116
  422. package/coverage/server/src/exportType.ts.html +0 -109
  423. package/coverage/server/src/index.html +0 -161
  424. package/coverage/server/src/index.ts.html +0 -1702
  425. package/coverage/server/src/instrument.ts.html +0 -130
  426. package/coverage/server/src/lib/config/env.ts.html +0 -448
  427. package/coverage/server/src/lib/config/index.html +0 -116
  428. package/coverage/server/src/lib/fileUpload.ts.html +0 -1138
  429. package/coverage/server/src/lib/googleCloudStorage.ts.html +0 -334
  430. package/coverage/server/src/lib/index.html +0 -206
  431. package/coverage/server/src/lib/jsonConversion.ts.html +0 -2323
  432. package/coverage/server/src/lib/jsonStyles.ts.html +0 -193
  433. package/coverage/server/src/lib/notificationHandler.ts.html +0 -193
  434. package/coverage/server/src/lib/pusher.ts.html +0 -121
  435. package/coverage/server/src/lib/thumbnailGenerator.ts.html +0 -592
  436. package/coverage/server/src/middleware/auth.ts.html +0 -646
  437. package/coverage/server/src/middleware/index.html +0 -146
  438. package/coverage/server/src/middleware/logging.ts.html +0 -244
  439. package/coverage/server/src/middleware/security.ts.html +0 -271
  440. package/coverage/server/src/routers/_app.ts.html +0 -232
  441. package/coverage/server/src/routers/agenda.ts.html +0 -319
  442. package/coverage/server/src/routers/announcement.ts.html +0 -3481
  443. package/coverage/server/src/routers/assignment.ts.html +0 -7633
  444. package/coverage/server/src/routers/attendance.ts.html +0 -1030
  445. package/coverage/server/src/routers/auth.ts.html +0 -1081
  446. package/coverage/server/src/routers/class.ts.html +0 -3535
  447. package/coverage/server/src/routers/comment.ts.html +0 -991
  448. package/coverage/server/src/routers/conversation.ts.html +0 -982
  449. package/coverage/server/src/routers/event.ts.html +0 -1609
  450. package/coverage/server/src/routers/file.ts.html +0 -1144
  451. package/coverage/server/src/routers/folder.ts.html +0 -2797
  452. package/coverage/server/src/routers/index.html +0 -386
  453. package/coverage/server/src/routers/labChat.ts.html +0 -3073
  454. package/coverage/server/src/routers/marketing.ts.html +0 -340
  455. package/coverage/server/src/routers/message.ts.html +0 -1912
  456. package/coverage/server/src/routers/notifications.ts.html +0 -364
  457. package/coverage/server/src/routers/section.ts.html +0 -1120
  458. package/coverage/server/src/routers/user.ts.html +0 -862
  459. package/coverage/server/src/routers/worksheet.ts.html +0 -1729
  460. package/coverage/server/src/trpc.ts.html +0 -397
  461. package/coverage/server/src/types/index.html +0 -116
  462. package/coverage/server/src/types/trpc.ts.html +0 -127
  463. package/coverage/server/src/utils/aiUser.ts.html +0 -280
  464. package/coverage/server/src/utils/email.ts.html +0 -121
  465. package/coverage/server/src/utils/generateInviteCode.ts.html +0 -106
  466. package/coverage/server/src/utils/index.html +0 -206
  467. package/coverage/server/src/utils/inference.ts.html +0 -709
  468. package/coverage/server/src/utils/logger.ts.html +0 -664
  469. package/coverage/server/src/utils/prismaErrorHandler.ts.html +0 -907
  470. package/coverage/server/src/utils/prismaWrapper.ts.html +0 -355
  471. package/coverage/server/vitest.config.ts.html +0 -196
  472. package/coverage/sort-arrow-sprite.png +0 -0
  473. package/coverage/sorter.js +0 -210
  474. package/src/lib/notificationHandler.ts +0 -36
  475. package/tests/announcement.test.ts +0 -164
  476. package/tests/assignment.test.ts +0 -296
  477. package/tests/auth.test.ts +0 -48
@@ -0,0 +1,622 @@
1
+ /**
2
+ * Class service – CRUD for classes, members, grades, mark schemes, grading boundaries,
3
+ * syllabus, lab drafts, and invite codes.
4
+ */
5
+ import { TRPCError } from "@trpc/server";
6
+ import { prisma } from "../lib/prisma.js";
7
+ import { generateInviteCode } from "../utils/generateInviteCode.js";
8
+ import {
9
+ findTeacherClasses,
10
+ findStudentClasses,
11
+ isTeacherInClass,
12
+ findClassWithAssignments,
13
+ findSectionsByClassId,
14
+ findUserById,
15
+ findSessionByClassCode,
16
+ findSessionByClassId,
17
+ findSubmissionsForGrades,
18
+ findEventsByClassId,
19
+ findMarkSchemesByClassId,
20
+ findGradingBoundariesByClassId,
21
+ findClassSyllabus,
22
+ findLabDraftsByClass,
23
+ findAssignmentsWithFiles,
24
+ findFullExportableClass,
25
+ createClassByImport,
26
+ } from "../models/class.js";
27
+ import { Class, Folder } from "@prisma/client";
28
+
29
+ /** Get all classes where user is teacher or student, with assignments and members. */
30
+ export async function getAllClasses(userId: string) {
31
+ const [teacherClasses, studentClasses] = await Promise.all([
32
+ findTeacherClasses(userId),
33
+ findStudentClasses(userId),
34
+ ]);
35
+
36
+ return {
37
+ teacherInClass: teacherClasses.map((cls) => ({
38
+ id: cls.id,
39
+ name: cls.name,
40
+ section: cls.section,
41
+ subject: cls.subject,
42
+ dueToday: cls.assignments,
43
+ assignments: cls.assignments,
44
+ members: [...cls.students, ...cls.teachers],
45
+ color: cls.color,
46
+ })),
47
+ studentInClass: studentClasses.map((cls) => ({
48
+ id: cls.id,
49
+ name: cls.name,
50
+ section: cls.section,
51
+ subject: cls.subject,
52
+ dueToday: cls.assignments,
53
+ assignments: cls.assignments,
54
+ members: [...cls.students, ...cls.teachers],
55
+ color: cls.color,
56
+ })),
57
+ };
58
+ }
59
+
60
+ /** Get single class with assignments, sections, and submission status. */
61
+ export async function getClass(userId: string, classId: string) {
62
+ const isTeacher = await isTeacherInClass(classId, userId ?? "");
63
+
64
+ const classData = await findClassWithAssignments(classId, {
65
+ isTeacher: !!isTeacher,
66
+ userId: userId ?? undefined,
67
+ });
68
+
69
+ if (!classData) {
70
+ throw new Error("Class not found");
71
+ }
72
+
73
+ const formattedClassData = {
74
+ ...classData,
75
+ assignments: classData.assignments.map((assignment) => ({
76
+ ...assignment,
77
+ late: assignment.dueDate < new Date(),
78
+ submitted: assignment.submissions.find(
79
+ (s) => s.studentId === userId
80
+ )?.submitted,
81
+ returned: assignment.submissions.find(
82
+ (s) => s.studentId === userId
83
+ )?.returned,
84
+ })),
85
+ };
86
+
87
+ const sections = await findSectionsByClassId(classId);
88
+
89
+ return {
90
+ class: {
91
+ ...formattedClassData,
92
+ sections,
93
+ },
94
+ };
95
+ }
96
+
97
+ export async function updateClass(
98
+ classId: string,
99
+ data: { name?: string; section?: string; subject?: string }
100
+ ) {
101
+ const updatedClass = await prisma.class.update({
102
+ where: { id: classId },
103
+ data,
104
+ select: {
105
+ id: true,
106
+ name: true,
107
+ section: true,
108
+ subject: true,
109
+ },
110
+ });
111
+ return { updatedClass };
112
+ }
113
+
114
+ export async function createClass(
115
+ userId: string,
116
+ input: {
117
+ students?: string[];
118
+ teachers?: string[];
119
+ name: string;
120
+ section: string;
121
+ subject: string;
122
+ color?: string;
123
+ }
124
+ ) {
125
+ const { students, teachers, name, section, subject, color } = input;
126
+
127
+ if (teachers && teachers.length > 0 && students && students.length > 0) {
128
+ return prisma.class.create({
129
+ data: {
130
+ name,
131
+ section,
132
+ subject,
133
+ color,
134
+ teachers: { connect: teachers.map((id) => ({ id })) },
135
+ students: { connect: students.map((id) => ({ id })) },
136
+ },
137
+ include: { teachers: true, students: true },
138
+ });
139
+ }
140
+
141
+ return prisma.class.create({
142
+ data: {
143
+ name,
144
+ section,
145
+ subject,
146
+ color,
147
+ teachers: { connect: { id: userId } },
148
+ },
149
+ });
150
+ }
151
+
152
+ export async function deleteClass(classId: string) {
153
+ const classToDelete = await prisma.class.findFirst({
154
+ where: { id: classId },
155
+ });
156
+
157
+ if (!classToDelete) {
158
+ throw new Error("Class not found or you don't have permission to delete it");
159
+ }
160
+
161
+ await prisma.class.delete({
162
+ where: { id: classId },
163
+ });
164
+
165
+ return { deletedClass: { id: classId } };
166
+ }
167
+
168
+ export async function addStudent(classId: string, studentId: string) {
169
+ const student = await findUserById(studentId);
170
+ if (!student) {
171
+ throw new Error("Student not found");
172
+ }
173
+
174
+ const updatedClass = await prisma.class.update({
175
+ where: { id: classId },
176
+ data: {
177
+ students: { connect: { id: studentId } },
178
+ },
179
+ select: {
180
+ id: true,
181
+ name: true,
182
+ section: true,
183
+ subject: true,
184
+ },
185
+ });
186
+
187
+ return { updatedClass, newStudent: student };
188
+ }
189
+
190
+ export async function changeRole(
191
+ classId: string,
192
+ userId: string,
193
+ type: "teacher" | "student"
194
+ ) {
195
+ const user = await findUserById(userId);
196
+ if (!user) {
197
+ throw new Error("User not found");
198
+ }
199
+
200
+ const updatedClass = await prisma.class.update({
201
+ where: { id: classId },
202
+ data: {
203
+ [type === "teacher" ? "teachers" : "students"]: {
204
+ connect: { id: userId },
205
+ },
206
+ [type === "teacher" ? "students" : "teachers"]: {
207
+ disconnect: { id: userId },
208
+ },
209
+ },
210
+ });
211
+
212
+ return {
213
+ updatedClass,
214
+ user: { ...user, type },
215
+ };
216
+ }
217
+
218
+ export async function removeMember(classId: string, userId: string) {
219
+ const updatedClass = await prisma.class.update({
220
+ where: { id: classId },
221
+ data: {
222
+ teachers: { disconnect: { id: userId } },
223
+ students: { disconnect: { id: userId } },
224
+ },
225
+ });
226
+ return { updatedClass, removedUserId: userId };
227
+ }
228
+
229
+ export async function leaveClass(userId: string, classId: string) {
230
+ const classData = await prisma.class.findFirst({
231
+ where: {
232
+ id: classId,
233
+ students: { some: { id: userId } },
234
+ },
235
+ });
236
+
237
+ if (!classData) {
238
+ throw new TRPCError({
239
+ code: "NOT_FOUND",
240
+ message: "Class not found or you are not a student in this class",
241
+ });
242
+ }
243
+
244
+ await prisma.class.update({
245
+ where: { id: classId },
246
+ data: {
247
+ students: { disconnect: { id: userId } },
248
+ },
249
+ });
250
+
251
+ return { success: true, leftClassId: classId };
252
+ }
253
+
254
+ export async function joinClass(userId: string, classCode: string) {
255
+ const session = await findSessionByClassCode(classCode);
256
+
257
+ if (!session || !session.classId) {
258
+ throw new Error("Class not found");
259
+ }
260
+
261
+ if (session.expiresAt && session.expiresAt < new Date()) {
262
+ throw new Error("Session expired");
263
+ }
264
+
265
+ const updatedClass = await prisma.class.update({
266
+ where: { id: session.classId },
267
+ data: {
268
+ students: { connect: { id: userId } },
269
+ },
270
+ select: {
271
+ id: true,
272
+ name: true,
273
+ section: true,
274
+ subject: true,
275
+ },
276
+ });
277
+
278
+ return { joinedClass: updatedClass };
279
+ }
280
+
281
+ export async function getInviteCode(classId: string) {
282
+ const session = await findSessionByClassId(classId);
283
+
284
+ if ((session?.expiresAt && session.expiresAt < new Date()) || !session) {
285
+ const newSession = await prisma.session.create({
286
+ data: {
287
+ id: generateInviteCode(),
288
+ classId,
289
+ expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),
290
+ },
291
+ });
292
+ return { code: newSession.id };
293
+ }
294
+
295
+ return { code: session?.id };
296
+ }
297
+
298
+ export async function createInviteCode(classId: string) {
299
+ await prisma.session.deleteMany({
300
+ where: { classId },
301
+ });
302
+
303
+ const session = await prisma.session.create({
304
+ data: {
305
+ id: generateInviteCode(),
306
+ classId,
307
+ expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),
308
+ },
309
+ });
310
+
311
+ return { code: session.id };
312
+ }
313
+
314
+ export async function getGrades(
315
+ userId: string,
316
+ classId: string,
317
+ targetUserId: string
318
+ ) {
319
+ const isTeacher = await isTeacherInClass(classId, userId);
320
+ if (userId !== targetUserId && !isTeacher) {
321
+ throw new TRPCError({
322
+ code: "UNAUTHORIZED",
323
+ message: "You can only view your own grades",
324
+ });
325
+ }
326
+
327
+ const grades = await findSubmissionsForGrades(targetUserId, classId);
328
+ return { grades };
329
+ }
330
+
331
+ export async function updateGrade(
332
+ assignmentId: string,
333
+ submissionId: string,
334
+ gradeReceived: number | null
335
+ ) {
336
+ const updatedSubmission = await prisma.submission.update({
337
+ where: { id: submissionId, assignmentId },
338
+ data: { gradeReceived },
339
+ include: {
340
+ assignment: {
341
+ select: {
342
+ id: true,
343
+ title: true,
344
+ maxGrade: true,
345
+ weight: true,
346
+ },
347
+ },
348
+ },
349
+ });
350
+ return updatedSubmission;
351
+ }
352
+
353
+ export async function getEvents(classId: string) {
354
+ return findEventsByClassId(classId);
355
+ }
356
+
357
+ export async function listMarkSchemes(classId: string) {
358
+ return findMarkSchemesByClassId(classId);
359
+ }
360
+
361
+ export async function createMarkScheme(classId: string, structure: string) {
362
+ const validatedStructure = structure.replace(/\\n/g, "\n");
363
+ return prisma.markScheme.create({
364
+ data: {
365
+ class: { connect: { id: classId } },
366
+ structured: validatedStructure,
367
+ },
368
+ });
369
+ }
370
+
371
+ export async function updateMarkScheme(
372
+ markSchemeId: string,
373
+ classId: string,
374
+ structure: string
375
+ ) {
376
+ const validatedStructure = structure.replace(/\\n/g, "\n");
377
+ return prisma.markScheme.update({
378
+ where: { id: markSchemeId },
379
+ data: {
380
+ class: { connect: { id: classId } },
381
+ structured: validatedStructure,
382
+ },
383
+ });
384
+ }
385
+
386
+ export async function deleteMarkScheme(markSchemeId: string) {
387
+ return prisma.markScheme.delete({
388
+ where: { id: markSchemeId },
389
+ });
390
+ }
391
+
392
+ export async function listGradingBoundaries(classId: string) {
393
+ return findGradingBoundariesByClassId(classId);
394
+ }
395
+
396
+ export async function createGradingBoundary(classId: string, structure: string) {
397
+ const validatedStructure = structure.replace(/\\n/g, "\n");
398
+ return prisma.gradingBoundary.create({
399
+ data: {
400
+ class: { connect: { id: classId } },
401
+ structured: validatedStructure,
402
+ },
403
+ });
404
+ }
405
+
406
+ export async function updateGradingBoundary(
407
+ gradingBoundaryId: string,
408
+ classId: string,
409
+ structure: string
410
+ ) {
411
+ const validatedStructure = structure.replace(/\\n/g, "\n");
412
+ return prisma.gradingBoundary.update({
413
+ where: { id: gradingBoundaryId },
414
+ data: {
415
+ class: { connect: { id: classId } },
416
+ structured: validatedStructure,
417
+ },
418
+ });
419
+ }
420
+
421
+ export async function deleteGradingBoundary(gradingBoundaryId: string) {
422
+ return prisma.gradingBoundary.delete({
423
+ where: { id: gradingBoundaryId },
424
+ });
425
+ }
426
+
427
+ export async function getSyllabus(classId: string) {
428
+ const classData = await findClassSyllabus(classId);
429
+ const markSchemes = await findMarkSchemesByClassId(classId);
430
+ const gradingBoundaries = await findGradingBoundariesByClassId(classId);
431
+ return {
432
+ syllabus: classData?.syllabus,
433
+ gradingBoundaries,
434
+ markSchemes,
435
+ };
436
+ }
437
+
438
+ export async function updateSyllabus(classId: string, contents: string) {
439
+ if (!contents) {
440
+ throw new TRPCError({
441
+ code: "BAD_REQUEST",
442
+ message: "Missing key contents",
443
+ });
444
+ }
445
+ return prisma.class.update({
446
+ where: { id: classId },
447
+ data: { syllabus: contents },
448
+ });
449
+ }
450
+
451
+ export async function listLabDrafts(classId: string, teacherId: string) {
452
+ return findLabDraftsByClass(classId, teacherId);
453
+ }
454
+
455
+ export async function createLabDraft(
456
+ classId: string,
457
+ teacherId: string,
458
+ input: {
459
+ title: string;
460
+ type: string;
461
+ instructions: string;
462
+ dueDate?: Date;
463
+ maxGrade?: number;
464
+ weight?: number;
465
+ graded?: boolean;
466
+ sectionId?: string;
467
+ markSchemeId?: string;
468
+ gradingBoundaryId?: string;
469
+ }
470
+ ) {
471
+ return prisma.assignment.create({
472
+ data: {
473
+ classId,
474
+ teacherId,
475
+ inProgress: true,
476
+ graded: input.graded ?? false,
477
+ maxGrade: input.maxGrade ?? 0,
478
+ weight: input.weight ?? 1,
479
+ dueDate:
480
+ input.dueDate ||
481
+ new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
482
+ title: input.title,
483
+ instructions: input.instructions,
484
+ type: input.type as any,
485
+ ...(input.sectionId && { sectionId: input.sectionId }),
486
+ ...(input.markSchemeId && { markSchemeId: input.markSchemeId }),
487
+ ...(input.gradingBoundaryId && {
488
+ gradingBoundaryId: input.gradingBoundaryId,
489
+ }),
490
+ },
491
+ });
492
+ }
493
+
494
+ export async function updateLabDraft(
495
+ classId: string,
496
+ teacherId: string,
497
+ draftId: string,
498
+ input: Record<string, unknown>
499
+ ) {
500
+ const updateData: Record<string, unknown> = {
501
+ modifiedAt: new Date(),
502
+ };
503
+ if (input.title !== undefined) updateData.title = input.title;
504
+ if (input.instructions !== undefined)
505
+ updateData.instructions = input.instructions;
506
+ if (input.dueDate !== undefined) updateData.dueDate = input.dueDate;
507
+ if (input.maxGrade !== undefined) updateData.maxGrade = input.maxGrade;
508
+ if (input.weight !== undefined) updateData.weight = input.weight;
509
+ if (input.graded !== undefined) updateData.graded = input.graded;
510
+ if (input.sectionId !== undefined) updateData.sectionId = input.sectionId;
511
+ if (input.markSchemeId !== undefined)
512
+ updateData.markSchemeId = input.markSchemeId;
513
+ if (input.gradingBoundaryId !== undefined)
514
+ updateData.gradingBoundaryId = input.gradingBoundaryId;
515
+
516
+ return prisma.assignment.update({
517
+ where: {
518
+ id: draftId,
519
+ classId,
520
+ teacherId,
521
+ inProgress: true,
522
+ },
523
+ data: updateData as any,
524
+ });
525
+ }
526
+
527
+ export async function deleteLabDraft(
528
+ classId: string,
529
+ teacherId: string,
530
+ draftId: string
531
+ ) {
532
+ return prisma.assignment.delete({
533
+ where: {
534
+ id: draftId,
535
+ classId,
536
+ teacherId,
537
+ inProgress: true,
538
+ },
539
+ });
540
+ }
541
+
542
+ export async function publishLabDraft(
543
+ classId: string,
544
+ teacherId: string,
545
+ draftId: string,
546
+ input: {
547
+ dueDate?: Date;
548
+ maxGrade?: number;
549
+ weight?: number;
550
+ graded?: boolean;
551
+ }
552
+ ) {
553
+ const labDraft = await prisma.assignment.findUnique({
554
+ where: {
555
+ id: draftId,
556
+ classId,
557
+ teacherId,
558
+ inProgress: true,
559
+ },
560
+ });
561
+
562
+ if (!labDraft) {
563
+ throw new TRPCError({
564
+ code: "NOT_FOUND",
565
+ message: "Lab draft not found",
566
+ });
567
+ }
568
+
569
+ return prisma.assignment.update({
570
+ where: { id: draftId },
571
+ data: {
572
+ inProgress: false,
573
+ dueDate: input.dueDate || labDraft.dueDate,
574
+ maxGrade: input.maxGrade || labDraft.maxGrade || 100,
575
+ weight: input.weight || labDraft.weight || 1,
576
+ graded: input.graded !== undefined ? input.graded : true,
577
+ modifiedAt: new Date(),
578
+ },
579
+ });
580
+ }
581
+
582
+ export async function getFiles(classId: string) {
583
+ const assignments = await findAssignmentsWithFiles(classId);
584
+ return assignments.map((assignment) => ({
585
+ id: assignment.id,
586
+ title: assignment.title,
587
+ teacher: assignment.teacher,
588
+ teacherAttachments: assignment.attachments,
589
+ students: assignment.submissions.map((submission) => ({
590
+ id: submission.student.id,
591
+ username: submission.student.username,
592
+ attachments: submission.attachments,
593
+ annotations: submission.annotations,
594
+ })),
595
+ }));
596
+ }
597
+
598
+ export async function exportClass(classId: string, userId: string) {
599
+ const classExport = await findFullExportableClass(classId);
600
+ if (!classExport) {
601
+ throw new TRPCError({
602
+ code: "INTERNAL_SERVER_ERROR",
603
+ message: "Failed to export class",
604
+ });
605
+ }
606
+
607
+ return classExport;
608
+ }
609
+
610
+ export async function importClass(classId: string, userId: string, year: number, classData: Class & { classFiles: Folder | null }) {
611
+ const newClassId = await createClassByImport(classId, userId, year, classData);
612
+
613
+
614
+ if (!newClassId) {
615
+ throw new TRPCError({
616
+ code: "INTERNAL_SERVER_ERROR",
617
+ message: "Failed to import class",
618
+ });
619
+ }
620
+
621
+ return newClassId;
622
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Comment service – get comments, replies, and reactions. Used for announcements and worksheets.
3
+ */
4
+ import { TRPCError } from "@trpc/server";
5
+ import {
6
+ findCommentById,
7
+ findRepliesByCommentId,
8
+ createComment,
9
+ findReactionByUserAndComment,
10
+ upsertReaction,
11
+ deleteReactionById,
12
+ findCommentWithAnnouncement,
13
+ getReactionCountsByCommentId,
14
+ } from "../models/comment.js";
15
+
16
+ /** Get a comment by ID. */
17
+ export async function getComment(id: string) {
18
+ const comment = await findCommentById(id);
19
+ if (!comment) {
20
+ throw new TRPCError({
21
+ code: "NOT_FOUND",
22
+ message: "Comment not found",
23
+ });
24
+ }
25
+ return comment;
26
+ }
27
+
28
+ /** Get all replies to a comment. */
29
+ export async function getReplies(commentId: string) {
30
+ return findRepliesByCommentId(commentId);
31
+ }
32
+
33
+ /** Create a reply to an existing comment. */
34
+ export async function replyToComment(
35
+ userId: string,
36
+ parentCommentId: string,
37
+ content: string
38
+ ) {
39
+ return createComment({
40
+ parentCommentId,
41
+ content,
42
+ authorId: userId,
43
+ });
44
+ }
45
+
46
+ /** Add or update a reaction (emoji) on a comment. */
47
+ export async function addReaction(
48
+ userId: string,
49
+ commentId: string,
50
+ type: string
51
+ ) {
52
+ const comment = await findCommentById(commentId);
53
+ if (!comment) {
54
+ throw new TRPCError({
55
+ code: "INTERNAL_SERVER_ERROR",
56
+ message: "Unexpected error",
57
+ });
58
+ }
59
+
60
+ const reaction = await upsertReaction({ userId, commentId, type });
61
+ return { reaction };
62
+ }
63
+
64
+ /** Remove user's reaction from a comment. */
65
+ export async function removeReaction(userId: string, commentId: string) {
66
+ const reaction = await findReactionByUserAndComment(userId, commentId);
67
+ if (!reaction) {
68
+ throw new TRPCError({
69
+ code: "NOT_FOUND",
70
+ message: "Reaction not found",
71
+ });
72
+ }
73
+ await deleteReactionById(reaction.id);
74
+ return { success: true };
75
+ }
76
+
77
+ export async function getReactions(userId: string, commentId: string) {
78
+ const comment = await findCommentWithAnnouncement(commentId);
79
+ if (!comment) {
80
+ throw new TRPCError({
81
+ code: "NOT_FOUND",
82
+ message: "Comment not found",
83
+ });
84
+ }
85
+
86
+ const reactionCounts = await getReactionCountsByCommentId(commentId);
87
+ const userReaction = await findReactionByUserAndComment(userId, commentId);
88
+
89
+ const counts = {
90
+ THUMBSUP: 0,
91
+ CELEBRATE: 0,
92
+ CARE: 0,
93
+ HEART: 0,
94
+ IDEA: 0,
95
+ HAPPY: 0,
96
+ };
97
+ reactionCounts.forEach((item) => {
98
+ counts[item.type as keyof typeof counts] = item._count.type;
99
+ });
100
+
101
+ return {
102
+ counts,
103
+ userReaction: userReaction?.type || null,
104
+ total: reactionCounts.reduce((sum, item) => sum + item._count.type, 0),
105
+ };
106
+ }