@hed-hog/lms 0.0.304 → 0.0.306

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 (458) hide show
  1. package/README.md +413 -401
  2. package/dist/certificate/certificate.controller.d.ts +90 -0
  3. package/dist/certificate/certificate.controller.d.ts.map +1 -0
  4. package/dist/certificate/certificate.controller.js +121 -0
  5. package/dist/certificate/certificate.controller.js.map +1 -0
  6. package/dist/certificate/certificate.module.d.ts +3 -0
  7. package/dist/certificate/certificate.module.d.ts.map +1 -0
  8. package/dist/certificate/certificate.module.js +26 -0
  9. package/dist/certificate/certificate.module.js.map +1 -0
  10. package/dist/certificate/certificate.service.d.ts +115 -0
  11. package/dist/certificate/certificate.service.d.ts.map +1 -0
  12. package/dist/certificate/certificate.service.js +343 -0
  13. package/dist/certificate/certificate.service.js.map +1 -0
  14. package/dist/certificate/dto/create-certificate-template.dto.d.ts +8 -0
  15. package/dist/certificate/dto/create-certificate-template.dto.d.ts.map +1 -0
  16. package/dist/certificate/dto/create-certificate-template.dto.js +44 -0
  17. package/dist/certificate/dto/create-certificate-template.dto.js.map +1 -0
  18. package/dist/certificate/dto/update-certificate-template.dto.d.ts +6 -0
  19. package/dist/certificate/dto/update-certificate-template.dto.d.ts.map +1 -0
  20. package/dist/certificate/dto/update-certificate-template.dto.js +9 -0
  21. package/dist/certificate/dto/update-certificate-template.dto.js.map +1 -0
  22. package/dist/class-group/class-group.controller.d.ts +305 -0
  23. package/dist/class-group/class-group.controller.d.ts.map +1 -0
  24. package/dist/class-group/class-group.controller.js +257 -0
  25. package/dist/class-group/class-group.controller.js.map +1 -0
  26. package/dist/class-group/class-group.module.d.ts +3 -0
  27. package/dist/class-group/class-group.module.d.ts.map +1 -0
  28. package/dist/class-group/class-group.module.js +25 -0
  29. package/dist/class-group/class-group.module.js.map +1 -0
  30. package/dist/class-group/class-group.service.d.ts +354 -0
  31. package/dist/class-group/class-group.service.d.ts.map +1 -0
  32. package/dist/class-group/class-group.service.js +1356 -0
  33. package/dist/class-group/class-group.service.js.map +1 -0
  34. package/dist/class-group/dto/create-class-group.dto.d.ts +33 -0
  35. package/dist/class-group/dto/create-class-group.dto.d.ts.map +1 -0
  36. package/dist/class-group/dto/create-class-group.dto.js +165 -0
  37. package/dist/class-group/dto/create-class-group.dto.js.map +1 -0
  38. package/dist/class-group/dto/create-session.dto.d.ts +22 -0
  39. package/dist/class-group/dto/create-session.dto.d.ts.map +1 -0
  40. package/dist/class-group/dto/create-session.dto.js +117 -0
  41. package/dist/class-group/dto/create-session.dto.js.map +1 -0
  42. package/dist/class-group/dto/enrollment.dto.d.ts +22 -0
  43. package/dist/class-group/dto/enrollment.dto.d.ts.map +1 -0
  44. package/dist/class-group/dto/enrollment.dto.js +89 -0
  45. package/dist/class-group/dto/enrollment.dto.js.map +1 -0
  46. package/dist/class-group/dto/update-class-group.dto.d.ts +6 -0
  47. package/dist/class-group/dto/update-class-group.dto.d.ts.map +1 -0
  48. package/dist/class-group/dto/update-class-group.dto.js +9 -0
  49. package/dist/class-group/dto/update-class-group.dto.js.map +1 -0
  50. package/dist/class-group/dto/update-session.dto.d.ts +7 -0
  51. package/dist/class-group/dto/update-session.dto.d.ts.map +1 -0
  52. package/dist/class-group/dto/update-session.dto.js +24 -0
  53. package/dist/class-group/dto/update-session.dto.js.map +1 -0
  54. package/dist/course/course-structure.controller.d.ts +127 -0
  55. package/dist/course/course-structure.controller.d.ts.map +1 -0
  56. package/dist/course/course-structure.controller.js +115 -0
  57. package/dist/course/course-structure.controller.js.map +1 -0
  58. package/dist/course/course-structure.service.d.ts +142 -0
  59. package/dist/course/course-structure.service.d.ts.map +1 -0
  60. package/dist/course/course-structure.service.js +445 -0
  61. package/dist/course/course-structure.service.js.map +1 -0
  62. package/dist/course/course.controller.d.ts +195 -0
  63. package/dist/course/course.controller.d.ts.map +1 -0
  64. package/dist/course/course.controller.js +104 -0
  65. package/dist/course/course.controller.js.map +1 -0
  66. package/dist/course/course.module.d.ts +3 -0
  67. package/dist/course/course.module.d.ts.map +1 -0
  68. package/dist/course/course.module.js +28 -0
  69. package/dist/course/course.module.js.map +1 -0
  70. package/dist/course/course.service.d.ts +215 -0
  71. package/dist/course/course.service.d.ts.map +1 -0
  72. package/dist/course/course.service.js +743 -0
  73. package/dist/course/course.service.js.map +1 -0
  74. package/dist/course/dto/create-course-structure-lesson.dto.d.ts +24 -0
  75. package/dist/course/dto/create-course-structure-lesson.dto.d.ts.map +1 -0
  76. package/dist/course/dto/create-course-structure-lesson.dto.js +118 -0
  77. package/dist/course/dto/create-course-structure-lesson.dto.js.map +1 -0
  78. package/dist/course/dto/create-course-structure-session.dto.d.ts +7 -0
  79. package/dist/course/dto/create-course-structure-session.dto.d.ts.map +1 -0
  80. package/dist/course/dto/create-course-structure-session.dto.js +40 -0
  81. package/dist/course/dto/create-course-structure-session.dto.js.map +1 -0
  82. package/dist/course/dto/create-course.dto.d.ts +26 -0
  83. package/dist/course/dto/create-course.dto.d.ts.map +1 -0
  84. package/dist/course/dto/create-course.dto.js +138 -0
  85. package/dist/course/dto/create-course.dto.js.map +1 -0
  86. package/dist/course/dto/update-course-structure-lesson.dto.d.ts +6 -0
  87. package/dist/course/dto/update-course-structure-lesson.dto.d.ts.map +1 -0
  88. package/dist/course/dto/update-course-structure-lesson.dto.js +9 -0
  89. package/dist/course/dto/update-course-structure-lesson.dto.js.map +1 -0
  90. package/dist/course/dto/update-course-structure-session.dto.d.ts +6 -0
  91. package/dist/course/dto/update-course-structure-session.dto.d.ts.map +1 -0
  92. package/dist/course/dto/update-course-structure-session.dto.js +9 -0
  93. package/dist/course/dto/update-course-structure-session.dto.js.map +1 -0
  94. package/dist/course/dto/update-course.dto.d.ts +6 -0
  95. package/dist/course/dto/update-course.dto.d.ts.map +1 -0
  96. package/dist/course/dto/update-course.dto.js +9 -0
  97. package/dist/course/dto/update-course.dto.js.map +1 -0
  98. package/dist/dashboard/dashboard.controller.d.ts +101 -0
  99. package/dist/dashboard/dashboard.controller.d.ts.map +1 -0
  100. package/dist/dashboard/dashboard.controller.js +40 -0
  101. package/dist/dashboard/dashboard.controller.js.map +1 -0
  102. package/dist/dashboard/dashboard.module.d.ts +3 -0
  103. package/dist/dashboard/dashboard.module.d.ts.map +1 -0
  104. package/dist/dashboard/dashboard.module.js +25 -0
  105. package/dist/dashboard/dashboard.module.js.map +1 -0
  106. package/dist/dashboard/dashboard.service.d.ts +130 -0
  107. package/dist/dashboard/dashboard.service.d.ts.map +1 -0
  108. package/dist/dashboard/dashboard.service.js +626 -0
  109. package/dist/dashboard/dashboard.service.js.map +1 -0
  110. package/dist/enterprise/dto/add-enterprise-class-group.dto.d.ts +4 -0
  111. package/dist/enterprise/dto/add-enterprise-class-group.dto.d.ts.map +1 -0
  112. package/dist/enterprise/dto/add-enterprise-class-group.dto.js +22 -0
  113. package/dist/enterprise/dto/add-enterprise-class-group.dto.js.map +1 -0
  114. package/dist/enterprise/dto/add-enterprise-course.dto.d.ts +5 -0
  115. package/dist/enterprise/dto/add-enterprise-course.dto.d.ts.map +1 -0
  116. package/dist/enterprise/dto/add-enterprise-course.dto.js +27 -0
  117. package/dist/enterprise/dto/add-enterprise-course.dto.js.map +1 -0
  118. package/dist/enterprise/dto/add-enterprise-student.dto.d.ts +5 -0
  119. package/dist/enterprise/dto/add-enterprise-student.dto.d.ts.map +1 -0
  120. package/dist/enterprise/dto/add-enterprise-student.dto.js +27 -0
  121. package/dist/enterprise/dto/add-enterprise-student.dto.js.map +1 -0
  122. package/dist/enterprise/dto/add-enterprise-user.dto.d.ts +7 -0
  123. package/dist/enterprise/dto/add-enterprise-user.dto.d.ts.map +1 -0
  124. package/dist/enterprise/dto/add-enterprise-user.dto.js +36 -0
  125. package/dist/enterprise/dto/add-enterprise-user.dto.js.map +1 -0
  126. package/dist/enterprise/dto/create-enterprise.dto.d.ts +10 -0
  127. package/dist/enterprise/dto/create-enterprise.dto.d.ts.map +1 -0
  128. package/dist/enterprise/dto/create-enterprise.dto.js +54 -0
  129. package/dist/enterprise/dto/create-enterprise.dto.js.map +1 -0
  130. package/dist/enterprise/dto/update-enterprise-student.dto.d.ts +4 -0
  131. package/dist/enterprise/dto/update-enterprise-student.dto.d.ts.map +1 -0
  132. package/dist/enterprise/dto/update-enterprise-student.dto.js +22 -0
  133. package/dist/enterprise/dto/update-enterprise-student.dto.js.map +1 -0
  134. package/dist/enterprise/dto/update-enterprise-user.dto.d.ts +5 -0
  135. package/dist/enterprise/dto/update-enterprise-user.dto.d.ts.map +1 -0
  136. package/dist/enterprise/dto/update-enterprise-user.dto.js +27 -0
  137. package/dist/enterprise/dto/update-enterprise-user.dto.js.map +1 -0
  138. package/dist/enterprise/dto/update-enterprise.dto.d.ts +6 -0
  139. package/dist/enterprise/dto/update-enterprise.dto.d.ts.map +1 -0
  140. package/dist/enterprise/dto/update-enterprise.dto.js +9 -0
  141. package/dist/enterprise/dto/update-enterprise.dto.js.map +1 -0
  142. package/dist/enterprise/enterprise.controller.d.ts +269 -0
  143. package/dist/enterprise/enterprise.controller.d.ts.map +1 -0
  144. package/dist/enterprise/enterprise.controller.js +311 -0
  145. package/dist/enterprise/enterprise.controller.js.map +1 -0
  146. package/dist/enterprise/enterprise.module.d.ts +3 -0
  147. package/dist/enterprise/enterprise.module.d.ts.map +1 -0
  148. package/dist/enterprise/enterprise.module.js +25 -0
  149. package/dist/enterprise/enterprise.module.js.map +1 -0
  150. package/dist/enterprise/enterprise.service.d.ts +282 -0
  151. package/dist/enterprise/enterprise.service.d.ts.map +1 -0
  152. package/dist/enterprise/enterprise.service.js +627 -0
  153. package/dist/enterprise/enterprise.service.js.map +1 -0
  154. package/dist/evaluation/evaluation.controller.d.ts +56 -0
  155. package/dist/evaluation/evaluation.controller.d.ts.map +1 -0
  156. package/dist/evaluation/evaluation.controller.js +76 -0
  157. package/dist/evaluation/evaluation.controller.js.map +1 -0
  158. package/dist/evaluation/evaluation.module.d.ts +3 -0
  159. package/dist/evaluation/evaluation.module.d.ts.map +1 -0
  160. package/dist/evaluation/evaluation.module.js +25 -0
  161. package/dist/evaluation/evaluation.module.js.map +1 -0
  162. package/dist/evaluation/evaluation.service.d.ts +67 -0
  163. package/dist/evaluation/evaluation.service.d.ts.map +1 -0
  164. package/dist/evaluation/evaluation.service.js +378 -0
  165. package/dist/evaluation/evaluation.service.js.map +1 -0
  166. package/dist/exam/dto/create-exam-question.dto.d.ts +25 -0
  167. package/dist/exam/dto/create-exam-question.dto.d.ts.map +1 -0
  168. package/dist/exam/dto/create-exam-question.dto.js +117 -0
  169. package/dist/exam/dto/create-exam-question.dto.js.map +1 -0
  170. package/dist/exam/dto/create-exam.dto.d.ts +11 -0
  171. package/dist/exam/dto/create-exam.dto.d.ts.map +1 -0
  172. package/dist/exam/dto/create-exam.dto.js +63 -0
  173. package/dist/exam/dto/create-exam.dto.js.map +1 -0
  174. package/dist/exam/dto/reorder-exam-questions.dto.d.ts +4 -0
  175. package/dist/exam/dto/reorder-exam-questions.dto.d.ts.map +1 -0
  176. package/dist/exam/dto/reorder-exam-questions.dto.js +23 -0
  177. package/dist/exam/dto/reorder-exam-questions.dto.js.map +1 -0
  178. package/dist/exam/dto/save-exam-attempt-answers.dto.d.ts +14 -0
  179. package/dist/exam/dto/save-exam-attempt-answers.dto.d.ts.map +1 -0
  180. package/dist/exam/dto/save-exam-attempt-answers.dto.js +68 -0
  181. package/dist/exam/dto/save-exam-attempt-answers.dto.js.map +1 -0
  182. package/dist/exam/dto/start-exam-attempt.dto.d.ts +4 -0
  183. package/dist/exam/dto/start-exam-attempt.dto.d.ts.map +1 -0
  184. package/dist/exam/dto/start-exam-attempt.dto.js +23 -0
  185. package/dist/exam/dto/start-exam-attempt.dto.js.map +1 -0
  186. package/dist/exam/dto/submit-exam-attempt.dto.d.ts +5 -0
  187. package/dist/exam/dto/submit-exam-attempt.dto.d.ts.map +1 -0
  188. package/dist/exam/dto/submit-exam-attempt.dto.js +23 -0
  189. package/dist/exam/dto/submit-exam-attempt.dto.js.map +1 -0
  190. package/dist/exam/dto/update-exam-question.dto.d.ts +6 -0
  191. package/dist/exam/dto/update-exam-question.dto.d.ts.map +1 -0
  192. package/dist/exam/dto/update-exam-question.dto.js +9 -0
  193. package/dist/exam/dto/update-exam-question.dto.js.map +1 -0
  194. package/dist/exam/dto/update-exam.dto.d.ts +6 -0
  195. package/dist/exam/dto/update-exam.dto.d.ts.map +1 -0
  196. package/dist/exam/dto/update-exam.dto.js +9 -0
  197. package/dist/exam/dto/update-exam.dto.js.map +1 -0
  198. package/dist/exam/exam-attempt.controller.d.ts +273 -0
  199. package/dist/exam/exam-attempt.controller.d.ts.map +1 -0
  200. package/dist/exam/exam-attempt.controller.js +84 -0
  201. package/dist/exam/exam-attempt.controller.js.map +1 -0
  202. package/dist/exam/exam-attempt.service.d.ts +302 -0
  203. package/dist/exam/exam-attempt.service.d.ts.map +1 -0
  204. package/dist/exam/exam-attempt.service.js +776 -0
  205. package/dist/exam/exam-attempt.service.js.map +1 -0
  206. package/dist/exam/exam.controller.d.ts +162 -0
  207. package/dist/exam/exam.controller.d.ts.map +1 -0
  208. package/dist/exam/exam.controller.js +158 -0
  209. package/dist/exam/exam.controller.js.map +1 -0
  210. package/dist/exam/exam.module.d.ts +3 -0
  211. package/dist/exam/exam.module.d.ts.map +1 -0
  212. package/dist/exam/exam.module.js +27 -0
  213. package/dist/exam/exam.module.js.map +1 -0
  214. package/dist/exam/exam.service.d.ts +179 -0
  215. package/dist/exam/exam.service.d.ts.map +1 -0
  216. package/dist/exam/exam.service.js +597 -0
  217. package/dist/exam/exam.service.js.map +1 -0
  218. package/dist/index.d.ts +28 -0
  219. package/dist/index.d.ts.map +1 -1
  220. package/dist/index.js +28 -0
  221. package/dist/index.js.map +1 -1
  222. package/dist/instructor/dto/create-instructor.dto.d.ts +10 -0
  223. package/dist/instructor/dto/create-instructor.dto.d.ts.map +1 -0
  224. package/dist/instructor/dto/create-instructor.dto.js +55 -0
  225. package/dist/instructor/dto/create-instructor.dto.js.map +1 -0
  226. package/dist/instructor/dto/update-instructor.dto.d.ts +9 -0
  227. package/dist/instructor/dto/update-instructor.dto.d.ts.map +1 -0
  228. package/dist/instructor/dto/update-instructor.dto.js +51 -0
  229. package/dist/instructor/dto/update-instructor.dto.js.map +1 -0
  230. package/dist/instructor/instructor.controller.d.ts +52 -0
  231. package/dist/instructor/instructor.controller.d.ts.map +1 -0
  232. package/dist/instructor/instructor.controller.js +98 -0
  233. package/dist/instructor/instructor.controller.js.map +1 -0
  234. package/dist/instructor/instructor.module.d.ts +3 -0
  235. package/dist/instructor/instructor.module.d.ts.map +1 -0
  236. package/dist/instructor/instructor.module.js +25 -0
  237. package/dist/instructor/instructor.module.js.map +1 -0
  238. package/dist/instructor/instructor.service.d.ts +79 -0
  239. package/dist/instructor/instructor.service.d.ts.map +1 -0
  240. package/dist/instructor/instructor.service.js +528 -0
  241. package/dist/instructor/instructor.service.js.map +1 -0
  242. package/dist/lms.module.d.ts.map +1 -1
  243. package/dist/lms.module.js +36 -4
  244. package/dist/lms.module.js.map +1 -1
  245. package/dist/reports/reports.controller.d.ts +69 -0
  246. package/dist/reports/reports.controller.d.ts.map +1 -0
  247. package/dist/reports/reports.controller.js +40 -0
  248. package/dist/reports/reports.controller.js.map +1 -0
  249. package/dist/reports/reports.module.d.ts +3 -0
  250. package/dist/reports/reports.module.d.ts.map +1 -0
  251. package/dist/reports/reports.module.js +25 -0
  252. package/dist/reports/reports.module.js.map +1 -0
  253. package/dist/reports/reports.service.d.ts +80 -0
  254. package/dist/reports/reports.service.d.ts.map +1 -0
  255. package/dist/reports/reports.service.js +366 -0
  256. package/dist/reports/reports.service.js.map +1 -0
  257. package/dist/training/dto/create-training.dto.d.ts +19 -0
  258. package/dist/training/dto/create-training.dto.d.ts.map +1 -0
  259. package/dist/training/dto/create-training.dto.js +98 -0
  260. package/dist/training/dto/create-training.dto.js.map +1 -0
  261. package/dist/training/dto/update-training.dto.d.ts +6 -0
  262. package/dist/training/dto/update-training.dto.d.ts.map +1 -0
  263. package/dist/training/dto/update-training.dto.js +9 -0
  264. package/dist/training/dto/update-training.dto.js.map +1 -0
  265. package/dist/training/training.controller.d.ts +195 -0
  266. package/dist/training/training.controller.d.ts.map +1 -0
  267. package/dist/training/training.controller.js +104 -0
  268. package/dist/training/training.controller.js.map +1 -0
  269. package/dist/training/training.module.d.ts +3 -0
  270. package/dist/training/training.module.d.ts.map +1 -0
  271. package/dist/training/training.module.js +25 -0
  272. package/dist/training/training.module.js.map +1 -0
  273. package/dist/training/training.service.d.ts +213 -0
  274. package/dist/training/training.service.d.ts.map +1 -0
  275. package/dist/training/training.service.js +497 -0
  276. package/dist/training/training.service.js.map +1 -0
  277. package/hedhog/data/dashboard.yaml +6 -0
  278. package/hedhog/data/dashboard_component.yaml +153 -0
  279. package/hedhog/data/dashboard_component_role.yaml +97 -0
  280. package/hedhog/data/dashboard_item.yaml +167 -0
  281. package/hedhog/data/dashboard_role.yaml +6 -0
  282. package/hedhog/data/instructor_qualification.yaml +16 -0
  283. package/hedhog/data/menu.yaml +129 -19
  284. package/hedhog/data/role.yaml +25 -1
  285. package/hedhog/data/route.yaml +867 -0
  286. package/hedhog/frontend/app/_components/class-form-sheet.tsx.ejs +1992 -0
  287. package/hedhog/frontend/app/_components/course-form-sheet.tsx.ejs +480 -0
  288. package/hedhog/frontend/app/_components/create-lms-instructor-sheet.tsx.ejs +591 -0
  289. package/hedhog/frontend/app/_components/create-lms-person-sheet.tsx.ejs +164 -0
  290. package/hedhog/frontend/app/_components/create-lms-student-person-sheet.tsx.ejs +120 -0
  291. package/hedhog/frontend/app/_components/lms-class-calendar.tsx.ejs +272 -0
  292. package/hedhog/frontend/app/_components/mobile-calendar.tsx.ejs +277 -0
  293. package/hedhog/frontend/app/_lib/editor/canvasInstance.ts.ejs +48 -0
  294. package/hedhog/frontend/app/_lib/editor/pctHelpers.ts.ejs +50 -0
  295. package/hedhog/frontend/app/_lib/editor/templateSerializer.ts.ejs +268 -0
  296. package/hedhog/frontend/app/_lib/editor/types.ts.ejs +94 -0
  297. package/hedhog/frontend/app/_lib/store/useTemplateStore.ts.ejs +284 -0
  298. package/hedhog/frontend/app/certificates/issued/page.tsx.ejs +638 -0
  299. package/hedhog/frontend/app/certificates/models/CanvasStage.tsx.ejs +916 -0
  300. package/hedhog/frontend/app/certificates/models/LeftPanel.tsx.ejs +200 -0
  301. package/hedhog/frontend/app/certificates/models/RightPanel.tsx.ejs +769 -0
  302. package/hedhog/frontend/app/certificates/models/TemplateEditorPage.tsx.ejs +104 -0
  303. package/hedhog/frontend/app/certificates/models/TopBar.tsx.ejs +354 -0
  304. package/hedhog/frontend/app/certificates/models/editor/page.tsx.ejs +5 -0
  305. package/hedhog/frontend/app/certificates/models/page.tsx.ejs +883 -0
  306. package/hedhog/frontend/app/classes/[id]/_components/event-summary-popover.tsx.ejs +279 -0
  307. package/hedhog/frontend/app/classes/[id]/_components/quick-create-session-popover.tsx.ejs +1027 -0
  308. package/hedhog/frontend/app/classes/[id]/page.tsx.ejs +3130 -993
  309. package/hedhog/frontend/app/classes/page.tsx.ejs +2731 -759
  310. package/hedhog/frontend/app/courses/[id]/_components/CourseCertificateCard.tsx.ejs +80 -0
  311. package/hedhog/frontend/app/courses/[id]/_components/CourseClassificationCard.tsx.ejs +226 -0
  312. package/hedhog/frontend/app/courses/[id]/_components/CourseContentCard.tsx.ejs +71 -0
  313. package/hedhog/frontend/app/courses/[id]/_components/CourseDangerZoneCard.tsx.ejs +42 -0
  314. package/hedhog/frontend/app/courses/[id]/_components/CourseFlagsCard.tsx.ejs +111 -0
  315. package/hedhog/frontend/app/courses/[id]/_components/CourseMainInfoCard.tsx.ejs +113 -0
  316. package/hedhog/frontend/app/courses/[id]/_components/CourseMediaCard.tsx.ejs +215 -0
  317. package/hedhog/frontend/app/courses/[id]/_components/CourseMultiEntityPicker.tsx.ejs +236 -0
  318. package/hedhog/frontend/app/courses/[id]/_components/CourseRelationsCard.tsx.ejs +141 -0
  319. package/hedhog/frontend/app/courses/[id]/_components/CourseSectionCard.tsx.ejs +57 -0
  320. package/hedhog/frontend/app/courses/[id]/_components/CourseSummaryCard.tsx.ejs +60 -0
  321. package/hedhog/frontend/app/courses/[id]/_components/course-edit-types.ts.ejs +33 -0
  322. package/hedhog/frontend/app/courses/[id]/page.tsx.ejs +933 -1103
  323. package/hedhog/frontend/app/courses/[id]/structure/page.tsx.ejs +699 -117
  324. package/hedhog/frontend/app/courses/page.tsx.ejs +1018 -1042
  325. package/hedhog/frontend/app/enterprise/[id]/page.tsx.ejs +317 -0
  326. package/hedhog/frontend/app/enterprise/_components/enterprise-activity-panel.tsx.ejs +88 -0
  327. package/hedhog/frontend/app/enterprise/_components/enterprise-admin-create-sheet.tsx.ejs +318 -0
  328. package/hedhog/frontend/app/enterprise/_components/enterprise-administrators-tab.tsx.ejs +332 -0
  329. package/hedhog/frontend/app/enterprise/_components/enterprise-class-create-sheet.tsx.ejs +58 -0
  330. package/hedhog/frontend/app/enterprise/_components/enterprise-classes-tab.tsx.ejs +390 -0
  331. package/hedhog/frontend/app/enterprise/_components/enterprise-company-identity-card.tsx.ejs +112 -0
  332. package/hedhog/frontend/app/enterprise/_components/enterprise-course-create-sheet.tsx.ejs +183 -0
  333. package/hedhog/frontend/app/enterprise/_components/enterprise-courses-tab.tsx.ejs +363 -0
  334. package/hedhog/frontend/app/enterprise/_components/enterprise-detail-constants.ts.ejs +88 -0
  335. package/hedhog/frontend/app/enterprise/_components/enterprise-detail-sheet.tsx.ejs +548 -0
  336. package/hedhog/frontend/app/enterprise/_components/enterprise-detail-utils.ts.ejs +33 -0
  337. package/hedhog/frontend/app/enterprise/_components/enterprise-mocks.ts.ejs +277 -0
  338. package/hedhog/frontend/app/enterprise/_components/enterprise-person-picker.ts.ejs +31 -0
  339. package/hedhog/frontend/app/enterprise/_components/enterprise-progress-bar.tsx.ejs +21 -0
  340. package/hedhog/frontend/app/enterprise/_components/enterprise-related-tab.tsx.ejs +224 -0
  341. package/hedhog/frontend/app/enterprise/_components/enterprise-sheet.tsx.ejs +397 -0
  342. package/hedhog/frontend/app/enterprise/_components/enterprise-student-create-sheet.tsx.ejs +167 -0
  343. package/hedhog/frontend/app/enterprise/_components/enterprise-students-tab.tsx.ejs +267 -0
  344. package/hedhog/frontend/app/enterprise/_components/enterprise-system-user-picker.ts.ejs +42 -0
  345. package/hedhog/frontend/app/enterprise/_components/enterprise-types.ts.ejs +96 -0
  346. package/hedhog/frontend/app/enterprise/_components/enterprise-user-create-sheet.tsx.ejs +207 -0
  347. package/hedhog/frontend/app/enterprise/_components/enterprise-user-distribution-chart.tsx.ejs +149 -0
  348. package/hedhog/frontend/app/enterprise/page.tsx.ejs +596 -0
  349. package/hedhog/frontend/app/evaluations/page.tsx.ejs +1250 -0
  350. package/hedhog/frontend/app/exams/[id]/attempt/page.tsx.ejs +642 -196
  351. package/hedhog/frontend/app/exams/[id]/page.tsx.ejs +11 -0
  352. package/hedhog/frontend/app/exams/[id]/questions/page.tsx.ejs +1316 -436
  353. package/hedhog/frontend/app/exams/page.tsx.ejs +799 -546
  354. package/hedhog/frontend/app/layout.tsx.ejs +5 -0
  355. package/hedhog/frontend/app/page.tsx.ejs +3 -1220
  356. package/hedhog/frontend/app/reports/courses/page.tsx.ejs +843 -0
  357. package/hedhog/frontend/app/reports/dashboard/page.tsx.ejs +890 -0
  358. package/hedhog/frontend/app/reports/page.tsx.ejs +802 -808
  359. package/hedhog/frontend/app/reports/students/page.tsx.ejs +772 -0
  360. package/hedhog/frontend/app/training/page.tsx.ejs +1873 -628
  361. package/hedhog/frontend/messages/en.json +1606 -111
  362. package/hedhog/frontend/messages/pt.json +1636 -134
  363. package/hedhog/frontend/widgets/active-classes-kpi.tsx.ejs +74 -0
  364. package/hedhog/frontend/widgets/active-courses-kpi.tsx.ejs +74 -0
  365. package/hedhog/frontend/widgets/approval-rate-kpi.tsx.ejs +81 -0
  366. package/hedhog/frontend/widgets/category-distribution-chart.tsx.ejs +119 -0
  367. package/hedhog/frontend/widgets/class-calendar.tsx.ejs +440 -0
  368. package/hedhog/frontend/widgets/completion-rate-kpi.tsx.ejs +81 -0
  369. package/hedhog/frontend/widgets/engagement-chart.tsx.ejs +120 -0
  370. package/hedhog/frontend/widgets/footer-summary.tsx.ejs +80 -0
  371. package/hedhog/frontend/widgets/issued-certificates-kpi.tsx.ejs +74 -0
  372. package/hedhog/frontend/widgets/latest-enrollments.tsx.ejs +166 -0
  373. package/hedhog/frontend/widgets/student-growth-chart.tsx.ejs +89 -0
  374. package/hedhog/frontend/widgets/top-courses-chart.tsx.ejs +104 -0
  375. package/hedhog/frontend/widgets/total-students-kpi.tsx.ejs +78 -0
  376. package/hedhog/frontend/widgets/upcoming-classes.tsx.ejs +152 -0
  377. package/hedhog/table/course.yaml +19 -1
  378. package/hedhog/table/course_class_group.yaml +8 -0
  379. package/hedhog/table/course_class_session.yaml +33 -0
  380. package/hedhog/table/course_instructor.yaml +27 -0
  381. package/hedhog/table/enterprise.yaml +29 -0
  382. package/hedhog/table/enterprise_class_group.yaml +20 -0
  383. package/hedhog/table/enterprise_course.yaml +23 -0
  384. package/hedhog/table/enterprise_student.yaml +24 -0
  385. package/hedhog/table/enterprise_user.yaml +35 -0
  386. package/hedhog/table/instructor_qualification.yaml +26 -0
  387. package/hedhog/table/instructor_qualification_assignment.yaml +22 -0
  388. package/hedhog/table/question.yaml +6 -0
  389. package/package.json +6 -6
  390. package/src/certificate/certificate.controller.ts +83 -0
  391. package/src/certificate/certificate.module.ts +13 -0
  392. package/src/certificate/certificate.service.ts +413 -0
  393. package/src/certificate/dto/create-certificate-template.dto.ts +25 -0
  394. package/src/certificate/dto/update-certificate-template.dto.ts +6 -0
  395. package/src/class-group/class-group.controller.ts +189 -0
  396. package/src/class-group/class-group.module.ts +12 -0
  397. package/src/class-group/class-group.service.ts +1802 -0
  398. package/src/class-group/dto/create-class-group.dto.ts +139 -0
  399. package/src/class-group/dto/create-session.dto.ts +102 -0
  400. package/src/class-group/dto/enrollment.dto.ts +70 -0
  401. package/src/class-group/dto/update-class-group.dto.ts +4 -0
  402. package/src/class-group/dto/update-session.dto.ts +9 -0
  403. package/src/course/course-structure.controller.ts +85 -0
  404. package/src/course/course-structure.service.ts +525 -0
  405. package/src/course/course.controller.ts +69 -0
  406. package/src/course/course.module.ts +15 -0
  407. package/src/course/course.service.ts +920 -0
  408. package/src/course/dto/create-course-structure-lesson.dto.ts +97 -0
  409. package/src/course/dto/create-course-structure-session.dto.ts +22 -0
  410. package/src/course/dto/create-course.dto.ts +111 -0
  411. package/src/course/dto/update-course-structure-lesson.dto.ts +6 -0
  412. package/src/course/dto/update-course-structure-session.dto.ts +6 -0
  413. package/src/course/dto/update-course.dto.ts +4 -0
  414. package/src/dashboard/dashboard.controller.ts +14 -0
  415. package/src/dashboard/dashboard.module.ts +12 -0
  416. package/src/dashboard/dashboard.service.ts +726 -0
  417. package/src/enterprise/dto/add-enterprise-class-group.dto.ts +7 -0
  418. package/src/enterprise/dto/add-enterprise-course.dto.ts +11 -0
  419. package/src/enterprise/dto/add-enterprise-student.dto.ts +16 -0
  420. package/src/enterprise/dto/add-enterprise-user.dto.ts +23 -0
  421. package/src/enterprise/dto/create-enterprise.dto.ts +41 -0
  422. package/src/enterprise/dto/update-enterprise-student.dto.ts +7 -0
  423. package/src/enterprise/dto/update-enterprise-user.dto.ts +11 -0
  424. package/src/enterprise/dto/update-enterprise.dto.ts +4 -0
  425. package/src/enterprise/enterprise.controller.ts +233 -0
  426. package/src/enterprise/enterprise.module.ts +12 -0
  427. package/src/enterprise/enterprise.service.ts +712 -0
  428. package/src/evaluation/evaluation.controller.ts +44 -0
  429. package/src/evaluation/evaluation.module.ts +12 -0
  430. package/src/evaluation/evaluation.service.ts +394 -0
  431. package/src/exam/dto/create-exam-question.dto.ts +103 -0
  432. package/src/exam/dto/create-exam.dto.ts +41 -0
  433. package/src/exam/dto/reorder-exam-questions.dto.ts +8 -0
  434. package/src/exam/dto/save-exam-attempt-answers.dto.ts +55 -0
  435. package/src/exam/dto/start-exam-attempt.dto.ts +8 -0
  436. package/src/exam/dto/submit-exam-attempt.dto.ts +8 -0
  437. package/src/exam/dto/update-exam-question.dto.ts +4 -0
  438. package/src/exam/dto/update-exam.dto.ts +4 -0
  439. package/src/exam/exam-attempt.controller.ts +65 -0
  440. package/src/exam/exam-attempt.service.ts +1008 -0
  441. package/src/exam/exam.controller.ts +102 -0
  442. package/src/exam/exam.module.ts +14 -0
  443. package/src/exam/exam.service.ts +784 -0
  444. package/src/index.ts +29 -0
  445. package/src/instructor/dto/create-instructor.dto.ts +43 -0
  446. package/src/instructor/dto/update-instructor.dto.ts +38 -0
  447. package/src/instructor/instructor.controller.ts +73 -0
  448. package/src/instructor/instructor.module.ts +12 -0
  449. package/src/instructor/instructor.service.ts +646 -0
  450. package/src/lms.module.ts +36 -4
  451. package/src/reports/reports.controller.ts +14 -0
  452. package/src/reports/reports.module.ts +12 -0
  453. package/src/reports/reports.service.ts +485 -0
  454. package/src/training/dto/create-training.dto.ts +81 -0
  455. package/src/training/dto/update-training.dto.ts +4 -0
  456. package/src/training/training.controller.ts +68 -0
  457. package/src/training/training.module.ts +12 -0
  458. package/src/training/training.service.ts +574 -0
@@ -0,0 +1,1356 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var ClassGroupService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ClassGroupService = void 0;
14
+ const api_prisma_1 = require("@hed-hog/api-prisma");
15
+ const common_1 = require("@nestjs/common");
16
+ const library_1 = require("@prisma/client/runtime/library");
17
+ const node_crypto_1 = require("node:crypto");
18
+ let ClassGroupService = ClassGroupService_1 = class ClassGroupService {
19
+ constructor(prisma) {
20
+ this.prisma = prisma;
21
+ }
22
+ isEmailCode(code) {
23
+ return (code !== null && code !== void 0 ? code : '').toLowerCase() === 'email';
24
+ }
25
+ isPhoneCode(code) {
26
+ const normalized = (code !== null && code !== void 0 ? code : '').toLowerCase();
27
+ return normalized === 'phone' || normalized === 'mobile';
28
+ }
29
+ getClassGroupInclude() {
30
+ const include = {
31
+ course: {
32
+ select: {
33
+ id: true,
34
+ title: true,
35
+ primary_color: true,
36
+ },
37
+ },
38
+ _count: {
39
+ select: {
40
+ course_enrollment: {
41
+ where: {
42
+ status: { not: 'cancelled' },
43
+ },
44
+ },
45
+ course_class_session: true,
46
+ },
47
+ },
48
+ instructor: {
49
+ select: {
50
+ id: true,
51
+ person: {
52
+ select: {
53
+ name: true,
54
+ },
55
+ },
56
+ },
57
+ },
58
+ };
59
+ return include;
60
+ }
61
+ getSessionInclude() {
62
+ return {
63
+ course_class_session_instructor: {
64
+ orderBy: { id: 'asc' },
65
+ select: {
66
+ instructor_id: true,
67
+ role: true,
68
+ instructor: {
69
+ select: {
70
+ person: {
71
+ select: {
72
+ name: true,
73
+ },
74
+ },
75
+ },
76
+ },
77
+ },
78
+ },
79
+ };
80
+ }
81
+ async list(params) {
82
+ var _a;
83
+ const page = Math.max(Number(params.page) || 1, 1);
84
+ const pageSize = Math.max(Number(params.pageSize) || 12, 1);
85
+ const skip = (page - 1) * pageSize;
86
+ const where = {};
87
+ const status = this.normalizeStatus(params.status);
88
+ if (status) {
89
+ where.status = status;
90
+ }
91
+ const deliveryMode = this.normalizeDeliveryMode(params.deliveryMode);
92
+ if (deliveryMode) {
93
+ where.delivery_mode = deliveryMode;
94
+ }
95
+ if (params.courseId) {
96
+ where.course_id = params.courseId;
97
+ }
98
+ if ((_a = params.search) === null || _a === void 0 ? void 0 : _a.trim()) {
99
+ const search = params.search.trim();
100
+ where.OR = [
101
+ { code: { contains: search, mode: 'insensitive' } },
102
+ { title: { contains: search, mode: 'insensitive' } },
103
+ { course: { title: { contains: search, mode: 'insensitive' } } },
104
+ ];
105
+ }
106
+ const [classes, total] = await Promise.all([
107
+ this.prisma.course_class_group.findMany({
108
+ skip,
109
+ take: pageSize,
110
+ where,
111
+ orderBy: { created_at: 'desc' },
112
+ include: this.getClassGroupInclude(),
113
+ }),
114
+ this.prisma.course_class_group.count({ where }),
115
+ ]);
116
+ return {
117
+ total,
118
+ page,
119
+ pageSize,
120
+ lastPage: Math.max(1, Math.ceil(total / pageSize)),
121
+ data: classes.map((item) => this.mapClassGroup(item)),
122
+ };
123
+ }
124
+ async stats() {
125
+ const [totalClasses, ongoingClasses, classes] = await Promise.all([
126
+ this.prisma.course_class_group.count(),
127
+ this.prisma.course_class_group.count({ where: { status: 'ongoing' } }),
128
+ this.prisma.course_class_group.findMany({
129
+ select: {
130
+ id: true,
131
+ status: true,
132
+ capacity: true,
133
+ _count: {
134
+ select: {
135
+ course_enrollment: {
136
+ where: {
137
+ status: { not: 'cancelled' },
138
+ },
139
+ },
140
+ },
141
+ },
142
+ },
143
+ }),
144
+ ]);
145
+ const openVacancies = classes
146
+ .filter((item) => item.status === 'open')
147
+ .reduce((sum, item) => { var _a; return sum + Math.max(((_a = item.capacity) !== null && _a !== void 0 ? _a : 0) - item._count.course_enrollment, 0); }, 0);
148
+ const occupancyRate = classes.length > 0
149
+ ? Math.round((classes.reduce((sum, item) => {
150
+ var _a;
151
+ return sum +
152
+ item._count.course_enrollment / Math.max((_a = item.capacity) !== null && _a !== void 0 ? _a : 1, 1);
153
+ }, 0) /
154
+ classes.length) *
155
+ 100)
156
+ : 0;
157
+ return {
158
+ totalClasses,
159
+ ongoingClasses,
160
+ openVacancies,
161
+ occupancyRate,
162
+ };
163
+ }
164
+ async getById(id) {
165
+ var _a, _b;
166
+ const item = await this.prisma.course_class_group.findUnique({
167
+ where: { id },
168
+ include: this.getClassGroupInclude(),
169
+ });
170
+ if (!item) {
171
+ return null;
172
+ }
173
+ const sessionTemplateSummary = await this.getClassSessionTemplateSummary(id);
174
+ return Object.assign(Object.assign({}, this.mapClassGroup(item)), { sessionTitle: (_a = sessionTemplateSummary === null || sessionTemplateSummary === void 0 ? void 0 : sessionTemplateSummary.title) !== null && _a !== void 0 ? _a : null, sessionRecurrenceSummary: sessionTemplateSummary
175
+ ? Object.assign(Object.assign({}, ((_b = sessionTemplateSummary.recurrence) !== null && _b !== void 0 ? _b : {})), { isRecurring: sessionTemplateSummary.isRecurring }) : null });
176
+ }
177
+ async create(dto) {
178
+ await this.assertCourseExists(dto.courseId);
179
+ if (dto.instructorId) {
180
+ await this.assertInstructorExists(dto.instructorId);
181
+ }
182
+ this.assertDatesAndTimes({
183
+ startDate: dto.startDate,
184
+ endDate: dto.endDate,
185
+ startTime: dto.startTime,
186
+ endTime: dto.endTime,
187
+ });
188
+ try {
189
+ const created = await this.prisma.$transaction(async (tx) => {
190
+ var _a, _b;
191
+ const createdClass = await tx.course_class_group.create({
192
+ data: {
193
+ code: dto.code,
194
+ course_id: dto.courseId,
195
+ instructor_id: dto.instructorId,
196
+ title: dto.title,
197
+ description: dto.description,
198
+ delivery_mode: dto.deliveryMode,
199
+ status: (_a = dto.status) !== null && _a !== void 0 ? _a : 'open',
200
+ start_date: new Date(dto.startDate),
201
+ end_date: dto.endDate ? new Date(dto.endDate) : null,
202
+ start_time: dto.startTime,
203
+ end_time: dto.endTime,
204
+ week_days: dto.weekDays,
205
+ capacity: (_b = dto.capacity) !== null && _b !== void 0 ? _b : 30,
206
+ location: dto.location,
207
+ virtual_room_url: dto.virtualRoomUrl,
208
+ },
209
+ include: this.getClassGroupInclude(),
210
+ });
211
+ if (dto.sessionTemplate) {
212
+ await this.syncClassSessionsFromTemplate(tx, createdClass.id, createdClass, dto.sessionTemplate);
213
+ }
214
+ return createdClass;
215
+ });
216
+ return this.mapClassGroup(created);
217
+ }
218
+ catch (error) {
219
+ this.handlePrismaError(error);
220
+ }
221
+ }
222
+ async update(id, dto) {
223
+ var _a, _b, _c, _d, _e;
224
+ const existing = await this.prisma.course_class_group.findUnique({
225
+ where: { id },
226
+ select: {
227
+ id: true,
228
+ course_id: true,
229
+ code: true,
230
+ title: true,
231
+ description: true,
232
+ delivery_mode: true,
233
+ instructor_id: true,
234
+ start_date: true,
235
+ end_date: true,
236
+ start_time: true,
237
+ end_time: true,
238
+ location: true,
239
+ virtual_room_url: true,
240
+ },
241
+ });
242
+ if (!existing) {
243
+ throw new common_1.NotFoundException('Class not found');
244
+ }
245
+ const courseId = (_a = dto.courseId) !== null && _a !== void 0 ? _a : existing.course_id;
246
+ await this.assertCourseExists(courseId);
247
+ if (dto.instructorId) {
248
+ await this.assertInstructorExists(dto.instructorId);
249
+ }
250
+ this.assertDatesAndTimes({
251
+ startDate: (_b = dto.startDate) !== null && _b !== void 0 ? _b : existing.start_date.toISOString(),
252
+ endDate: dto.endDate !== undefined
253
+ ? dto.endDate
254
+ : (_c = existing.end_date) === null || _c === void 0 ? void 0 : _c.toISOString(),
255
+ startTime: dto.startTime !== undefined ? dto.startTime : (_d = existing.start_time) !== null && _d !== void 0 ? _d : undefined,
256
+ endTime: dto.endTime !== undefined ? dto.endTime : (_e = existing.end_time) !== null && _e !== void 0 ? _e : undefined,
257
+ });
258
+ const status = dto.status !== undefined ? this.normalizeStatus(dto.status) : undefined;
259
+ const deliveryMode = dto.deliveryMode !== undefined
260
+ ? this.normalizeDeliveryMode(dto.deliveryMode)
261
+ : undefined;
262
+ try {
263
+ const updated = await this.prisma.$transaction(async (tx) => {
264
+ const updatedClass = await tx.course_class_group.update({
265
+ where: { id },
266
+ data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (dto.code !== undefined && { code: dto.code })), (dto.courseId !== undefined && { course_id: dto.courseId })), (dto.instructorId !== undefined && {
267
+ instructor_id: dto.instructorId,
268
+ })), (dto.title !== undefined && { title: dto.title })), (dto.description !== undefined && { description: dto.description })), (deliveryMode !== undefined && { delivery_mode: deliveryMode })), (status !== undefined && { status })), (dto.startDate !== undefined && { start_date: new Date(dto.startDate) })), (dto.endDate !== undefined && {
269
+ end_date: dto.endDate ? new Date(dto.endDate) : null,
270
+ })), (dto.startTime !== undefined && { start_time: dto.startTime })), (dto.endTime !== undefined && { end_time: dto.endTime })), (dto.weekDays !== undefined && { week_days: dto.weekDays })), (dto.capacity !== undefined && { capacity: dto.capacity })), (dto.location !== undefined && { location: dto.location })), (dto.virtualRoomUrl !== undefined && {
271
+ virtual_room_url: dto.virtualRoomUrl,
272
+ })),
273
+ include: this.getClassGroupInclude(),
274
+ });
275
+ if (dto.sessionTemplate) {
276
+ await this.syncClassSessionsFromTemplate(tx, id, updatedClass, dto.sessionTemplate, { futureOnly: true });
277
+ }
278
+ return updatedClass;
279
+ });
280
+ return this.mapClassGroup(updated);
281
+ }
282
+ catch (error) {
283
+ this.handlePrismaError(error);
284
+ }
285
+ }
286
+ async remove(id) {
287
+ await this.prisma.course_class_group.delete({ where: { id } });
288
+ return { success: true };
289
+ }
290
+ async getClassSessionTemplateSummary(classGroupId) {
291
+ var _a;
292
+ const today = this.getSessionMutationFloorDate();
293
+ const session = (_a = (await this.prisma.course_class_session.findFirst({
294
+ where: {
295
+ course_class_group_id: classGroupId,
296
+ session_date: { gte: today },
297
+ status: { notIn: ['completed', 'cancelled'] },
298
+ },
299
+ orderBy: [{ session_date: 'asc' }, { occurrence_index: 'asc' }],
300
+ select: {
301
+ title: true,
302
+ recurrence_rule: true,
303
+ recurrence_id: true,
304
+ },
305
+ }))) !== null && _a !== void 0 ? _a : (await this.prisma.course_class_session.findFirst({
306
+ where: { course_class_group_id: classGroupId },
307
+ orderBy: [{ session_date: 'asc' }, { occurrence_index: 'asc' }],
308
+ select: {
309
+ title: true,
310
+ recurrence_rule: true,
311
+ recurrence_id: true,
312
+ },
313
+ }));
314
+ if (!session) {
315
+ return null;
316
+ }
317
+ return {
318
+ title: session.title,
319
+ recurrence: this.parseRecurrenceRule(session.recurrence_rule),
320
+ isRecurring: Boolean(session.recurrence_id),
321
+ };
322
+ }
323
+ getSessionMutationFloorDate() {
324
+ return this.normalizeSessionDate(new Date());
325
+ }
326
+ buildClassSessionDto(classGroup, sessionTemplate) {
327
+ var _a, _b, _c, _d, _e, _f, _g, _h;
328
+ if (!classGroup.start_date) {
329
+ throw new common_1.BadRequestException('Class start date is required to generate sessions');
330
+ }
331
+ if (!classGroup.start_time || !classGroup.end_time) {
332
+ throw new common_1.BadRequestException('Class start and end times are required to generate sessions');
333
+ }
334
+ const deliveryMode = classGroup.delivery_mode;
335
+ const isOnline = deliveryMode === 'online';
336
+ const isHybrid = deliveryMode === 'hybrid';
337
+ return {
338
+ title: sessionTemplate.title.trim(),
339
+ description: (_b = (_a = sessionTemplate.description) !== null && _a !== void 0 ? _a : classGroup.description) !== null && _b !== void 0 ? _b : undefined,
340
+ sessionDate: this.toDateKey(this.normalizeSessionDate(classGroup.start_date)),
341
+ startTime: classGroup.start_time,
342
+ endTime: classGroup.end_time,
343
+ location: isOnline && !isHybrid
344
+ ? undefined
345
+ : (_d = (_c = sessionTemplate.location) !== null && _c !== void 0 ? _c : classGroup.location) !== null && _d !== void 0 ? _d : undefined,
346
+ meetingUrl: !isOnline && !isHybrid
347
+ ? undefined
348
+ : (_f = (_e = sessionTemplate.meetingUrl) !== null && _e !== void 0 ? _e : classGroup.virtual_room_url) !== null && _f !== void 0 ? _f : undefined,
349
+ color: (_g = sessionTemplate.color) !== null && _g !== void 0 ? _g : undefined,
350
+ status: 'scheduled',
351
+ instructorId: (_h = classGroup.instructor_id) !== null && _h !== void 0 ? _h : undefined,
352
+ recurrence: sessionTemplate.recurrence
353
+ ? this.toSessionRecurrenceDto(sessionTemplate.recurrence)
354
+ : undefined,
355
+ };
356
+ }
357
+ toSessionRecurrenceDto(recurrence) {
358
+ return {
359
+ frequency: recurrence.frequency,
360
+ interval: recurrence.interval,
361
+ until: recurrence.until,
362
+ daysOfWeek: recurrence.daysOfWeek,
363
+ };
364
+ }
365
+ async syncClassSessionsFromTemplate(tx, classGroupId, classGroup, sessionTemplate, options) {
366
+ const createDto = this.buildClassSessionDto(classGroup, sessionTemplate);
367
+ const mutableWhere = {
368
+ course_class_group_id: classGroupId,
369
+ };
370
+ if (options === null || options === void 0 ? void 0 : options.futureOnly) {
371
+ mutableWhere.session_date = { gte: this.getSessionMutationFloorDate() };
372
+ mutableWhere.status = { notIn: ['completed', 'cancelled'] };
373
+ }
374
+ const mutableSessions = await tx.course_class_session.findMany({
375
+ where: mutableWhere,
376
+ select: { id: true },
377
+ });
378
+ if (mutableSessions.length > 0) {
379
+ const sessionIds = mutableSessions.map((session) => session.id);
380
+ await tx.course_class_attendance.deleteMany({
381
+ where: { course_class_session_id: { in: sessionIds } },
382
+ });
383
+ await tx.course_class_session_instructor.deleteMany({
384
+ where: { course_class_session_id: { in: sessionIds } },
385
+ });
386
+ await tx.course_class_session.deleteMany({
387
+ where: { id: { in: sessionIds } },
388
+ });
389
+ }
390
+ await this.createSessionSeriesInTransaction(tx, classGroupId, createDto, {
391
+ minDate: (options === null || options === void 0 ? void 0 : options.futureOnly) ? this.getSessionMutationFloorDate() : undefined,
392
+ });
393
+ }
394
+ mapClassGroup(item) {
395
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
396
+ const instructorName = (_k = (_g = (_d = (_c = (_b = (_a = item.instructor) === null || _a === void 0 ? void 0 : _a.person) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : (_f = (_e = item.instructorName) === null || _e === void 0 ? void 0 : _e.trim) === null || _f === void 0 ? void 0 : _f.call(_e)) !== null && _g !== void 0 ? _g : (_j = (_h = item.professorName) === null || _h === void 0 ? void 0 : _h.trim) === null || _j === void 0 ? void 0 : _j.call(_h)) !== null && _k !== void 0 ? _k : '';
397
+ return {
398
+ id: item.id,
399
+ code: item.code,
400
+ title: item.title,
401
+ description: (_l = item.description) !== null && _l !== void 0 ? _l : '',
402
+ deliveryMode: item.delivery_mode,
403
+ status: item.status,
404
+ startDate: item.start_date,
405
+ endDate: item.end_date,
406
+ startTime: item.start_time,
407
+ endTime: item.end_time,
408
+ weekDays: item.week_days,
409
+ capacity: item.capacity,
410
+ location: item.location,
411
+ virtualRoomUrl: item.virtual_room_url,
412
+ courseId: item.course_id,
413
+ instructorId: (_p = (_m = item.instructor_id) !== null && _m !== void 0 ? _m : (_o = item.instructor) === null || _o === void 0 ? void 0 : _o.id) !== null && _p !== void 0 ? _p : null,
414
+ instructorName,
415
+ instructor: instructorName,
416
+ professorName: instructorName,
417
+ professor: instructorName,
418
+ courseTitle: (_r = (_q = item.course) === null || _q === void 0 ? void 0 : _q.title) !== null && _r !== void 0 ? _r : '',
419
+ primaryColor: (_t = (_s = item.course) === null || _s === void 0 ? void 0 : _s.primary_color) !== null && _t !== void 0 ? _t : null,
420
+ enrolledCount: (_v = (_u = item._count) === null || _u === void 0 ? void 0 : _u.course_enrollment) !== null && _v !== void 0 ? _v : 0,
421
+ sessionCount: (_x = (_w = item._count) === null || _w === void 0 ? void 0 : _w.course_class_session) !== null && _x !== void 0 ? _x : 0,
422
+ occupancyRate: Math.round((((_z = (_y = item._count) === null || _y === void 0 ? void 0 : _y.course_enrollment) !== null && _z !== void 0 ? _z : 0) / Math.max((_0 = item.capacity) !== null && _0 !== void 0 ? _0 : 1, 1)) *
423
+ 100),
424
+ createdAt: item.created_at,
425
+ updatedAt: item.updated_at,
426
+ };
427
+ }
428
+ normalizeStatus(value) {
429
+ if (!value)
430
+ return undefined;
431
+ const normalized = value.trim().toLowerCase();
432
+ const valid = ['open', 'ongoing', 'completed', 'cancelled'];
433
+ if (!valid.includes(normalized)) {
434
+ throw new common_1.BadRequestException('Invalid status');
435
+ }
436
+ return normalized;
437
+ }
438
+ normalizeDeliveryMode(value) {
439
+ if (!value)
440
+ return undefined;
441
+ const normalized = value.trim().toLowerCase();
442
+ const valid = ['presential', 'online', 'hybrid'];
443
+ if (!valid.includes(normalized)) {
444
+ throw new common_1.BadRequestException('Invalid delivery mode');
445
+ }
446
+ return normalized;
447
+ }
448
+ assertDatesAndTimes(params) {
449
+ const startDate = new Date(params.startDate);
450
+ if (Number.isNaN(startDate.getTime())) {
451
+ throw new common_1.BadRequestException('Invalid start date');
452
+ }
453
+ if (params.endDate) {
454
+ const endDate = new Date(params.endDate);
455
+ if (Number.isNaN(endDate.getTime())) {
456
+ throw new common_1.BadRequestException('Invalid end date');
457
+ }
458
+ if (endDate.getTime() < startDate.getTime()) {
459
+ throw new common_1.BadRequestException('End date cannot be before start date');
460
+ }
461
+ }
462
+ if (params.startTime && params.endTime) {
463
+ const start = this.timeToMinutes(params.startTime);
464
+ const end = this.timeToMinutes(params.endTime);
465
+ if (start >= end) {
466
+ throw new common_1.BadRequestException('End time must be after start time');
467
+ }
468
+ }
469
+ }
470
+ timeToMinutes(value) {
471
+ const [hours, minutes] = value.split(':').map(Number);
472
+ return hours * 60 + minutes;
473
+ }
474
+ async assertCourseExists(courseId) {
475
+ const exists = await this.prisma.course.findUnique({
476
+ where: { id: courseId },
477
+ select: { id: true },
478
+ });
479
+ if (!exists) {
480
+ throw new common_1.NotFoundException('Course not found');
481
+ }
482
+ }
483
+ // ── Students ────────────────────────────────────────────────────────────────
484
+ async listStudents(classGroupId, search) {
485
+ const group = await this.prisma.course_class_group.findUnique({
486
+ where: { id: classGroupId },
487
+ select: { id: true, course_id: true },
488
+ });
489
+ if (!group)
490
+ throw new common_1.NotFoundException('Class not found');
491
+ const enrollments = await this.prisma.course_enrollment.findMany({
492
+ where: {
493
+ course_class_group_id: classGroupId,
494
+ status: { not: 'cancelled' },
495
+ },
496
+ include: {
497
+ person: {
498
+ select: {
499
+ id: true,
500
+ name: true,
501
+ contact: {
502
+ select: { value: true, contact_type: { select: { code: true } } },
503
+ },
504
+ },
505
+ },
506
+ },
507
+ orderBy: { enrolled_at: 'asc' },
508
+ });
509
+ const mapped = enrollments.map((e) => {
510
+ var _a, _b, _c, _d;
511
+ const contacts = e.person.contact;
512
+ const email = (_b = (_a = contacts.find((c) => this.isEmailCode(c.contact_type.code))) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
513
+ const phone = (_d = (_c = contacts.find((c) => this.isPhoneCode(c.contact_type.code))) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '';
514
+ return {
515
+ id: e.person.id,
516
+ enrollmentId: e.id,
517
+ nome: e.person.name,
518
+ email,
519
+ telefone: phone,
520
+ matriculadoEm: e.enrolled_at,
521
+ progresso: e.progress_percent,
522
+ status: e.status,
523
+ };
524
+ });
525
+ if (search === null || search === void 0 ? void 0 : search.trim()) {
526
+ const q = search.trim().toLowerCase();
527
+ return mapped.filter((s) => s.nome.toLowerCase().includes(q) ||
528
+ s.email.toLowerCase().includes(q));
529
+ }
530
+ return mapped;
531
+ }
532
+ async enrollStudent(classGroupId, personId) {
533
+ const group = await this.prisma.course_class_group.findUnique({
534
+ where: { id: classGroupId },
535
+ select: { id: true, course_id: true, capacity: true },
536
+ });
537
+ if (!group)
538
+ throw new common_1.NotFoundException('Class not found');
539
+ const existing = await this.prisma.course_enrollment.findFirst({
540
+ where: { course_class_group_id: classGroupId, person_id: personId },
541
+ });
542
+ if (existing) {
543
+ if (existing.status === 'cancelled') {
544
+ return this.prisma.course_enrollment.update({
545
+ where: { id: existing.id },
546
+ data: { status: 'active', enrolled_at: new Date() },
547
+ });
548
+ }
549
+ throw new common_1.ConflictException('Student already enrolled');
550
+ }
551
+ return this.prisma.course_enrollment.create({
552
+ data: {
553
+ person_id: personId,
554
+ course_class_group_id: classGroupId,
555
+ course_id: group.course_id,
556
+ status: 'active',
557
+ enrolled_at: new Date(),
558
+ },
559
+ });
560
+ }
561
+ async createAndEnrollStudent(classGroupId, dto) {
562
+ var _a, _b, _c, _d, _e;
563
+ const group = await this.prisma.course_class_group.findUnique({
564
+ where: { id: classGroupId },
565
+ select: { id: true },
566
+ });
567
+ if (!group) {
568
+ throw new common_1.NotFoundException('Class not found');
569
+ }
570
+ const name = dto.name.trim();
571
+ const email = (_a = dto.email) === null || _a === void 0 ? void 0 : _a.trim();
572
+ const phone = (_b = dto.phone) === null || _b === void 0 ? void 0 : _b.trim();
573
+ if (!name) {
574
+ throw new common_1.BadRequestException('Name is required');
575
+ }
576
+ let personId;
577
+ if (email) {
578
+ const existingByEmail = await this.prisma.person.findFirst({
579
+ where: {
580
+ contact: {
581
+ some: {
582
+ value: { equals: email, mode: 'insensitive' },
583
+ contact_type: { code: { in: ['email', 'EMAIL'] } },
584
+ },
585
+ },
586
+ },
587
+ select: { id: true },
588
+ });
589
+ if (existingByEmail) {
590
+ personId = existingByEmail.id;
591
+ }
592
+ }
593
+ if (!personId) {
594
+ const [emailType, phoneType] = await Promise.all([
595
+ this.prisma.contact_type.findFirst({
596
+ where: { code: { in: ['email', 'EMAIL'] } },
597
+ select: { id: true },
598
+ }),
599
+ this.prisma.contact_type.findFirst({
600
+ where: { code: { in: ['mobile', 'MOBILE', 'phone', 'PHONE'] } },
601
+ orderBy: { id: 'asc' },
602
+ select: { id: true },
603
+ }),
604
+ ]);
605
+ const createdPerson = await this.prisma.person.create({
606
+ data: {
607
+ name,
608
+ type: 'individual',
609
+ status: 'active',
610
+ },
611
+ select: { id: true },
612
+ });
613
+ personId = createdPerson.id;
614
+ const contactsToCreate = [];
615
+ if (email && emailType) {
616
+ contactsToCreate.push({
617
+ person_id: personId,
618
+ contact_type_id: emailType.id,
619
+ value: email,
620
+ is_primary: true,
621
+ });
622
+ }
623
+ if (phone && phoneType) {
624
+ contactsToCreate.push({
625
+ person_id: personId,
626
+ contact_type_id: phoneType.id,
627
+ value: phone,
628
+ is_primary: true,
629
+ });
630
+ }
631
+ if (contactsToCreate.length > 0) {
632
+ await this.prisma.contact.createMany({
633
+ data: contactsToCreate,
634
+ });
635
+ }
636
+ }
637
+ const person = await this.prisma.person.findUnique({
638
+ where: { id: personId },
639
+ include: {
640
+ contact: {
641
+ select: {
642
+ value: true,
643
+ contact_type: { select: { code: true } },
644
+ },
645
+ },
646
+ },
647
+ });
648
+ return {
649
+ id: person === null || person === void 0 ? void 0 : person.id,
650
+ nome: (_c = person === null || person === void 0 ? void 0 : person.name) !== null && _c !== void 0 ? _c : '',
651
+ email: (_e = (_d = person === null || person === void 0 ? void 0 : person.contact.find((c) => this.isEmailCode(c.contact_type.code))) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : '',
652
+ };
653
+ }
654
+ async removeStudent(classGroupId, personId) {
655
+ const enrollment = await this.prisma.course_enrollment.findFirst({
656
+ where: {
657
+ course_class_group_id: classGroupId,
658
+ person_id: personId,
659
+ status: { not: 'cancelled' },
660
+ },
661
+ });
662
+ if (!enrollment)
663
+ throw new common_1.NotFoundException('Enrollment not found');
664
+ await this.prisma.course_enrollment.update({
665
+ where: { id: enrollment.id },
666
+ data: { status: 'cancelled' },
667
+ });
668
+ return { success: true };
669
+ }
670
+ async getStudentProfile(classGroupId, personId) {
671
+ var _a, _b, _c, _d;
672
+ const enrollment = await this.prisma.course_enrollment.findFirst({
673
+ where: {
674
+ course_class_group_id: classGroupId,
675
+ person_id: personId,
676
+ status: { not: 'cancelled' },
677
+ },
678
+ include: {
679
+ person: {
680
+ select: {
681
+ id: true,
682
+ name: true,
683
+ contact: {
684
+ select: {
685
+ id: true,
686
+ value: true,
687
+ contact_type: { select: { code: true } },
688
+ },
689
+ },
690
+ },
691
+ },
692
+ },
693
+ });
694
+ if (!enrollment) {
695
+ throw new common_1.NotFoundException('Student not found in this class');
696
+ }
697
+ const email = (_b = (_a = enrollment.person.contact.find((c) => this.isEmailCode(c.contact_type.code))) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
698
+ const phone = (_d = (_c = enrollment.person.contact.find((c) => this.isPhoneCode(c.contact_type.code))) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '';
699
+ return {
700
+ id: enrollment.person.id,
701
+ enrollmentId: enrollment.id,
702
+ nome: enrollment.person.name,
703
+ email,
704
+ telefone: phone,
705
+ matriculadoEm: enrollment.enrolled_at,
706
+ progresso: enrollment.progress_percent,
707
+ status: enrollment.status,
708
+ };
709
+ }
710
+ async updateStudentProfile(classGroupId, personId, dto) {
711
+ var _a, _b, _c;
712
+ const enrollment = await this.prisma.course_enrollment.findFirst({
713
+ where: {
714
+ course_class_group_id: classGroupId,
715
+ person_id: personId,
716
+ status: { not: 'cancelled' },
717
+ },
718
+ select: { id: true },
719
+ });
720
+ if (!enrollment) {
721
+ throw new common_1.NotFoundException('Student not found in this class');
722
+ }
723
+ const name = (_a = dto.name) === null || _a === void 0 ? void 0 : _a.trim();
724
+ const email = (_b = dto.email) === null || _b === void 0 ? void 0 : _b.trim();
725
+ const phone = (_c = dto.phone) === null || _c === void 0 ? void 0 : _c.trim();
726
+ if (dto.name !== undefined && !name) {
727
+ throw new common_1.BadRequestException('Name is required');
728
+ }
729
+ if (name) {
730
+ await this.prisma.person.update({
731
+ where: { id: personId },
732
+ data: { name },
733
+ });
734
+ }
735
+ const [emailType, phoneType] = await Promise.all([
736
+ this.prisma.contact_type.findFirst({
737
+ where: { code: { in: ['email', 'EMAIL'] } },
738
+ select: { id: true },
739
+ }),
740
+ this.prisma.contact_type.findFirst({
741
+ where: { code: { in: ['mobile', 'MOBILE', 'phone', 'PHONE'] } },
742
+ orderBy: { id: 'asc' },
743
+ select: { id: true },
744
+ }),
745
+ ]);
746
+ if (dto.email !== undefined && emailType) {
747
+ const existingEmail = await this.prisma.contact.findFirst({
748
+ where: { person_id: personId, contact_type_id: emailType.id },
749
+ select: { id: true },
750
+ });
751
+ if (email) {
752
+ if (existingEmail) {
753
+ await this.prisma.contact.update({
754
+ where: { id: existingEmail.id },
755
+ data: { value: email },
756
+ });
757
+ }
758
+ else {
759
+ await this.prisma.contact.create({
760
+ data: {
761
+ person_id: personId,
762
+ contact_type_id: emailType.id,
763
+ value: email,
764
+ is_primary: true,
765
+ },
766
+ });
767
+ }
768
+ }
769
+ else if (existingEmail) {
770
+ await this.prisma.contact.delete({ where: { id: existingEmail.id } });
771
+ }
772
+ }
773
+ if (dto.phone !== undefined) {
774
+ const existingPhone = await this.prisma.contact.findFirst({
775
+ where: {
776
+ person_id: personId,
777
+ contact_type: { code: { in: ['mobile', 'MOBILE', 'phone', 'PHONE'] } },
778
+ },
779
+ orderBy: { id: 'asc' },
780
+ select: { id: true },
781
+ });
782
+ if (phone) {
783
+ if (existingPhone) {
784
+ await this.prisma.contact.update({
785
+ where: { id: existingPhone.id },
786
+ data: { value: phone },
787
+ });
788
+ }
789
+ else if (phoneType) {
790
+ await this.prisma.contact.create({
791
+ data: {
792
+ person_id: personId,
793
+ contact_type_id: phoneType.id,
794
+ value: phone,
795
+ is_primary: true,
796
+ },
797
+ });
798
+ }
799
+ }
800
+ else if (existingPhone) {
801
+ await this.prisma.contact.delete({ where: { id: existingPhone.id } });
802
+ }
803
+ }
804
+ return this.getStudentProfile(classGroupId, personId);
805
+ }
806
+ async searchPeople(search, classGroupId) {
807
+ const q = search.trim();
808
+ if (!q)
809
+ return [];
810
+ const enrolledIds = classGroupId
811
+ ? (await this.prisma.course_enrollment.findMany({
812
+ where: {
813
+ course_class_group_id: classGroupId,
814
+ status: { not: 'cancelled' },
815
+ },
816
+ select: { person_id: true },
817
+ })).map((e) => e.person_id)
818
+ : [];
819
+ const people = await this.prisma.person.findMany({
820
+ where: {
821
+ AND: [
822
+ {
823
+ OR: [
824
+ { name: { contains: q, mode: 'insensitive' } },
825
+ {
826
+ contact: {
827
+ some: {
828
+ value: { contains: q, mode: 'insensitive' },
829
+ contact_type: { code: { in: ['email', 'EMAIL'] } },
830
+ },
831
+ },
832
+ },
833
+ ],
834
+ },
835
+ enrolledIds.length > 0 ? { id: { notIn: enrolledIds } } : {},
836
+ ],
837
+ },
838
+ include: {
839
+ contact: {
840
+ select: { value: true, contact_type: { select: { code: true } } },
841
+ },
842
+ },
843
+ take: 20,
844
+ });
845
+ const personIds = people.map((person) => person.id);
846
+ const [instructors, enrolledPeople] = personIds.length > 0
847
+ ? await Promise.all([
848
+ this.prisma.instructor.findMany({
849
+ where: {
850
+ person_id: { in: personIds },
851
+ status: 'active',
852
+ },
853
+ select: {
854
+ person_id: true,
855
+ can_teach_courses: true,
856
+ },
857
+ }),
858
+ this.prisma.course_enrollment.findMany({
859
+ where: {
860
+ person_id: { in: personIds },
861
+ status: { not: 'cancelled' },
862
+ },
863
+ select: { person_id: true },
864
+ distinct: ['person_id'],
865
+ }),
866
+ ])
867
+ : [[], []];
868
+ const instructorByPersonId = new Map(instructors.map((instructor) => [instructor.person_id, instructor]));
869
+ const enrolledPersonIds = new Set(enrolledPeople.map((enrollment) => enrollment.person_id));
870
+ return people.map((p) => {
871
+ var _a, _b;
872
+ const instructor = instructorByPersonId.get(p.id);
873
+ const isInstructor = Boolean(instructor);
874
+ const canTeachCourses = Boolean(instructor === null || instructor === void 0 ? void 0 : instructor.can_teach_courses);
875
+ const isStudentByEnrollment = enrolledPersonIds.has(p.id);
876
+ return {
877
+ id: p.id,
878
+ nome: p.name,
879
+ email: (_b = (_a = p.contact.find((c) => this.isEmailCode(c.contact_type.code))) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '',
880
+ isInstructor,
881
+ canTeachCourses,
882
+ isStudentByEnrollment,
883
+ };
884
+ });
885
+ }
886
+ // ── Sessions ─────────────────────────────────────────────────────────────────
887
+ async listSessions(classGroupId) {
888
+ const group = await this.prisma.course_class_group.findUnique({
889
+ where: { id: classGroupId },
890
+ select: { id: true },
891
+ });
892
+ if (!group)
893
+ throw new common_1.NotFoundException('Class not found');
894
+ const sessions = await this.prisma.course_class_session.findMany({
895
+ where: { course_class_group_id: classGroupId },
896
+ orderBy: [{ session_date: 'asc' }, { occurrence_index: 'asc' }],
897
+ include: this.getSessionInclude(),
898
+ });
899
+ return sessions.map((s) => this.mapSession(s));
900
+ }
901
+ async createSession(classGroupId, dto) {
902
+ const group = await this.prisma.course_class_group.findUnique({
903
+ where: { id: classGroupId },
904
+ select: { id: true },
905
+ });
906
+ if (!group)
907
+ throw new common_1.NotFoundException('Class not found');
908
+ if (dto.instructorId) {
909
+ await this.assertInstructorExists(dto.instructorId);
910
+ }
911
+ const created = await this.prisma.$transaction((tx) => this.createSessionSeriesInTransaction(tx, classGroupId, dto));
912
+ if (!created) {
913
+ throw new common_1.BadRequestException('No sessions were generated for the provided recurrence');
914
+ }
915
+ return this.mapSession(created);
916
+ }
917
+ async createSessionSeriesInTransaction(tx, classGroupId, dto, options) {
918
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
919
+ const normalizedRecurrence = dto.recurrence
920
+ ? this.normalizeSessionRecurrence(dto.recurrence, dto.sessionDate)
921
+ : null;
922
+ const fullOccurrenceDates = normalizedRecurrence
923
+ ? this.buildRecurringSessionDates(dto.sessionDate, normalizedRecurrence)
924
+ : [this.toSessionDate(dto.sessionDate)];
925
+ const occurrenceDates = (options === null || options === void 0 ? void 0 : options.minDate)
926
+ ? fullOccurrenceDates.filter((date) => this.normalizeSessionDate(date).getTime() >=
927
+ this.normalizeSessionDate(options.minDate).getTime())
928
+ : fullOccurrenceDates;
929
+ if (occurrenceDates.length === 0) {
930
+ return null;
931
+ }
932
+ const recurrenceId = normalizedRecurrence ? (0, node_crypto_1.randomUUID)() : null;
933
+ const recurrenceRule = normalizedRecurrence
934
+ ? JSON.stringify(normalizedRecurrence)
935
+ : null;
936
+ const first = await tx.course_class_session.create({
937
+ data: Object.assign({ course_class_group_id: classGroupId, title: dto.title, description: (_a = dto.description) !== null && _a !== void 0 ? _a : null, session_date: occurrenceDates[0], start_time: dto.startTime, end_time: dto.endTime, location: (_b = dto.location) !== null && _b !== void 0 ? _b : null, meeting_url: (_c = dto.meetingUrl) !== null && _c !== void 0 ? _c : null, color: (_d = dto.color) !== null && _d !== void 0 ? _d : null, status: (_e = dto.status) !== null && _e !== void 0 ? _e : 'scheduled', recurrence_id: recurrenceId, recurrence_rule: recurrenceRule, occurrence_index: normalizedRecurrence ? 0 : null, is_exception: false }, (dto.instructorId && {
938
+ course_class_session_instructor: {
939
+ create: {
940
+ instructor_id: dto.instructorId,
941
+ role: 'lead',
942
+ },
943
+ },
944
+ })),
945
+ include: this.getSessionInclude(),
946
+ });
947
+ for (let index = 1; index < occurrenceDates.length; index += 1) {
948
+ await tx.course_class_session.create({
949
+ data: Object.assign({ course_class_group_id: classGroupId, title: dto.title, description: (_f = dto.description) !== null && _f !== void 0 ? _f : null, session_date: occurrenceDates[index], start_time: dto.startTime, end_time: dto.endTime, location: (_g = dto.location) !== null && _g !== void 0 ? _g : null, meeting_url: (_h = dto.meetingUrl) !== null && _h !== void 0 ? _h : null, color: (_j = dto.color) !== null && _j !== void 0 ? _j : null, status: (_k = dto.status) !== null && _k !== void 0 ? _k : 'scheduled', recurrence_id: recurrenceId, recurrence_rule: recurrenceRule, occurrence_index: normalizedRecurrence ? index : null, is_exception: false, parent_session_id: first.id }, (dto.instructorId && {
950
+ course_class_session_instructor: {
951
+ create: {
952
+ instructor_id: dto.instructorId,
953
+ role: 'lead',
954
+ },
955
+ },
956
+ })),
957
+ });
958
+ }
959
+ return first;
960
+ }
961
+ async updateSession(classGroupId, sessionId, dto) {
962
+ var _a, _b;
963
+ const session = await this.prisma.course_class_session.findFirst({
964
+ where: { id: sessionId, course_class_group_id: classGroupId },
965
+ });
966
+ if (!session)
967
+ throw new common_1.NotFoundException('Session not found');
968
+ if (dto.instructorId) {
969
+ await this.assertInstructorExists(dto.instructorId);
970
+ }
971
+ const scope = (_a = dto.applyScope) !== null && _a !== void 0 ? _a : 'single';
972
+ const normalizedRecurrence = dto.recurrence
973
+ ? this.normalizeSessionRecurrence(dto.recurrence, (_b = dto.sessionDate) !== null && _b !== void 0 ? _b : this.toDateKey(session.session_date))
974
+ : null;
975
+ const nextRecurrenceRule = normalizedRecurrence
976
+ ? JSON.stringify(normalizedRecurrence)
977
+ : dto.recurrence === undefined
978
+ ? undefined
979
+ : null;
980
+ if (scope === 'series' && session.recurrence_id) {
981
+ const seriesSessions = await this.prisma.course_class_session.findMany({
982
+ where: {
983
+ course_class_group_id: classGroupId,
984
+ recurrence_id: session.recurrence_id,
985
+ },
986
+ orderBy: [{ session_date: 'asc' }, { occurrence_index: 'asc' }],
987
+ });
988
+ const dayDelta = dto.sessionDate
989
+ ? this.diffInDays(this.toSessionDate(dto.sessionDate), this.normalizeSessionDate(session.session_date))
990
+ : 0;
991
+ await this.prisma.$transaction(async (tx) => {
992
+ for (const seriesSession of seriesSessions) {
993
+ await tx.course_class_session.update({
994
+ where: { id: seriesSession.id },
995
+ data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (dto.title !== undefined && { title: dto.title })), (dto.description !== undefined && {
996
+ description: dto.description,
997
+ })), (dto.startTime !== undefined && { start_time: dto.startTime })), (dto.endTime !== undefined && { end_time: dto.endTime })), (dto.location !== undefined && { location: dto.location })), (dto.meetingUrl !== undefined && {
998
+ meeting_url: dto.meetingUrl,
999
+ })), (dto.color !== undefined && { color: dto.color })), (dto.status !== undefined && { status: dto.status })), (dto.sessionDate !== undefined && {
1000
+ session_date: this.addDaysUtc(seriesSession.session_date, dayDelta),
1001
+ })), (nextRecurrenceRule !== undefined && {
1002
+ recurrence_rule: nextRecurrenceRule,
1003
+ })),
1004
+ });
1005
+ if (dto.instructorId !== undefined) {
1006
+ await tx.course_class_session_instructor.deleteMany({
1007
+ where: { course_class_session_id: seriesSession.id },
1008
+ });
1009
+ if (dto.instructorId) {
1010
+ await tx.course_class_session_instructor.create({
1011
+ data: {
1012
+ course_class_session_id: seriesSession.id,
1013
+ instructor_id: dto.instructorId,
1014
+ role: 'lead',
1015
+ },
1016
+ });
1017
+ }
1018
+ }
1019
+ }
1020
+ });
1021
+ const updated = await this.prisma.course_class_session.findUnique({
1022
+ where: { id: sessionId },
1023
+ include: this.getSessionInclude(),
1024
+ });
1025
+ if (!updated) {
1026
+ throw new common_1.NotFoundException('Session not found');
1027
+ }
1028
+ return this.mapSession(updated);
1029
+ }
1030
+ const updated = await this.prisma.course_class_session.update({
1031
+ where: { id: sessionId },
1032
+ data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (dto.title !== undefined && { title: dto.title })), (dto.description !== undefined && { description: dto.description })), (dto.sessionDate !== undefined && {
1033
+ session_date: this.toSessionDate(dto.sessionDate),
1034
+ })), (dto.startTime !== undefined && { start_time: dto.startTime })), (dto.endTime !== undefined && { end_time: dto.endTime })), (dto.location !== undefined && { location: dto.location })), (dto.meetingUrl !== undefined && { meeting_url: dto.meetingUrl })), (dto.color !== undefined && { color: dto.color })), (dto.status !== undefined && { status: dto.status })), (nextRecurrenceRule !== undefined && {
1035
+ recurrence_rule: nextRecurrenceRule,
1036
+ })), (session.recurrence_id && { is_exception: true })), (dto.instructorId !== undefined && {
1037
+ course_class_session_instructor: Object.assign({ deleteMany: {} }, (dto.instructorId
1038
+ ? {
1039
+ create: {
1040
+ instructor_id: dto.instructorId,
1041
+ role: 'lead',
1042
+ },
1043
+ }
1044
+ : {})),
1045
+ })),
1046
+ include: this.getSessionInclude(),
1047
+ });
1048
+ return this.mapSession(updated);
1049
+ }
1050
+ async deleteSession(classGroupId, sessionId, scope = 'single') {
1051
+ const session = await this.prisma.course_class_session.findFirst({
1052
+ where: { id: sessionId, course_class_group_id: classGroupId },
1053
+ });
1054
+ if (!session)
1055
+ throw new common_1.NotFoundException('Session not found');
1056
+ if (scope === 'series' && session.recurrence_id) {
1057
+ await this.prisma.course_class_session.deleteMany({
1058
+ where: {
1059
+ course_class_group_id: classGroupId,
1060
+ recurrence_id: session.recurrence_id,
1061
+ },
1062
+ });
1063
+ return { success: true };
1064
+ }
1065
+ await this.prisma.course_class_session.delete({ where: { id: sessionId } });
1066
+ return { success: true };
1067
+ }
1068
+ // ── Attendance ───────────────────────────────────────────────────────────────
1069
+ async getAttendance(classGroupId, sessionId) {
1070
+ const session = await this.prisma.course_class_session.findFirst({
1071
+ where: { id: sessionId, course_class_group_id: classGroupId },
1072
+ });
1073
+ if (!session)
1074
+ throw new common_1.NotFoundException('Session not found');
1075
+ return this.prisma.course_class_attendance.findMany({
1076
+ where: { course_class_session_id: sessionId },
1077
+ include: {
1078
+ person_course_class_attendance_student_idToperson: {
1079
+ select: { id: true, name: true },
1080
+ },
1081
+ },
1082
+ });
1083
+ }
1084
+ async saveAttendance(classGroupId, sessionId, entries) {
1085
+ const session = await this.prisma.course_class_session.findFirst({
1086
+ where: { id: sessionId, course_class_group_id: classGroupId },
1087
+ });
1088
+ if (!session)
1089
+ throw new common_1.NotFoundException('Session not found');
1090
+ await this.prisma.$transaction(async (tx) => {
1091
+ var _a, _b;
1092
+ const normalizedEntries = Array.from(new Map(entries.map((entry) => [entry.studentId, entry])).values());
1093
+ const selectedStudentIds = normalizedEntries.map((entry) => entry.studentId);
1094
+ if (selectedStudentIds.length > 0) {
1095
+ await tx.course_class_attendance.deleteMany({
1096
+ where: {
1097
+ course_class_session_id: sessionId,
1098
+ student_id: { notIn: selectedStudentIds },
1099
+ },
1100
+ });
1101
+ }
1102
+ else {
1103
+ await tx.course_class_attendance.deleteMany({
1104
+ where: { course_class_session_id: sessionId },
1105
+ });
1106
+ }
1107
+ for (const e of normalizedEntries) {
1108
+ const existing = await tx.course_class_attendance.findFirst({
1109
+ where: {
1110
+ course_class_session_id: sessionId,
1111
+ student_id: e.studentId,
1112
+ },
1113
+ select: { id: true },
1114
+ });
1115
+ if (existing) {
1116
+ await tx.course_class_attendance.update({
1117
+ where: { id: existing.id },
1118
+ data: {
1119
+ present: e.present,
1120
+ justification: (_a = e.justification) !== null && _a !== void 0 ? _a : null,
1121
+ },
1122
+ });
1123
+ continue;
1124
+ }
1125
+ await tx.course_class_attendance.create({
1126
+ data: {
1127
+ course_class_session_id: sessionId,
1128
+ student_id: e.studentId,
1129
+ present: e.present,
1130
+ justification: (_b = e.justification) !== null && _b !== void 0 ? _b : null,
1131
+ },
1132
+ });
1133
+ }
1134
+ });
1135
+ return { success: true };
1136
+ }
1137
+ mapSession(s) {
1138
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1139
+ const leadInstructor = (_a = s.course_class_session_instructor) === null || _a === void 0 ? void 0 : _a.find((entry) => entry.role === 'lead');
1140
+ const fallbackInstructor = (_b = s.course_class_session_instructor) === null || _b === void 0 ? void 0 : _b[0];
1141
+ const sessionInstructor = leadInstructor !== null && leadInstructor !== void 0 ? leadInstructor : fallbackInstructor;
1142
+ const recurrence = this.parseRecurrenceRule(s.recurrence_rule);
1143
+ return {
1144
+ id: s.id,
1145
+ titulo: s.title,
1146
+ descricao: (_c = s.description) !== null && _c !== void 0 ? _c : '',
1147
+ data: s.session_date,
1148
+ horaInicio: s.start_time,
1149
+ horaFim: s.end_time,
1150
+ local: (_d = s.location) !== null && _d !== void 0 ? _d : '',
1151
+ meetingUrl: (_e = s.meeting_url) !== null && _e !== void 0 ? _e : '',
1152
+ cor: (_f = s.color) !== null && _f !== void 0 ? _f : undefined,
1153
+ status: s.status,
1154
+ tipo: s.meeting_url ? 'online' : 'presencial',
1155
+ instructorId: (_g = sessionInstructor === null || sessionInstructor === void 0 ? void 0 : sessionInstructor.instructor_id) !== null && _g !== void 0 ? _g : null,
1156
+ instructorName: (_k = (_j = (_h = sessionInstructor === null || sessionInstructor === void 0 ? void 0 : sessionInstructor.instructor) === null || _h === void 0 ? void 0 : _h.person) === null || _j === void 0 ? void 0 : _j.name) !== null && _k !== void 0 ? _k : '',
1157
+ recurrenceId: (_l = s.recurrence_id) !== null && _l !== void 0 ? _l : null,
1158
+ occurrenceIndex: (_m = s.occurrence_index) !== null && _m !== void 0 ? _m : null,
1159
+ isException: Boolean(s.is_exception),
1160
+ recurrence,
1161
+ isRecurring: Boolean(s.recurrence_id),
1162
+ };
1163
+ }
1164
+ normalizeSessionRecurrence(recurrence, sessionDate) {
1165
+ var _a, _b;
1166
+ const startDate = this.toSessionDate(sessionDate);
1167
+ const untilDate = this.toSessionDate(recurrence.until);
1168
+ if (untilDate.getTime() < startDate.getTime()) {
1169
+ throw new common_1.BadRequestException('Recurrence end date must be on or after session date');
1170
+ }
1171
+ const normalizedDays = ((_a = recurrence.daysOfWeek) === null || _a === void 0 ? void 0 : _a.length)
1172
+ ? [...new Set(recurrence.daysOfWeek)].sort((left, right) => ClassGroupService_1.DAY_ORDER.indexOf(left) -
1173
+ ClassGroupService_1.DAY_ORDER.indexOf(right))
1174
+ : recurrence.frequency === 'weekly'
1175
+ ? [this.getDayCode(startDate)]
1176
+ : undefined;
1177
+ return Object.assign({ frequency: recurrence.frequency, interval: (_b = recurrence.interval) !== null && _b !== void 0 ? _b : 1, until: this.toDateKey(untilDate) }, ((normalizedDays === null || normalizedDays === void 0 ? void 0 : normalizedDays.length) ? { daysOfWeek: normalizedDays } : {}));
1178
+ }
1179
+ buildRecurringSessionDates(sessionDate, recurrence) {
1180
+ const startDate = this.toSessionDate(sessionDate);
1181
+ const untilDate = this.toSessionDate(recurrence.until);
1182
+ switch (recurrence.frequency) {
1183
+ case 'daily':
1184
+ return this.buildDailyOccurrences(startDate, untilDate, recurrence.interval);
1185
+ case 'weekly':
1186
+ return this.buildWeeklyOccurrences(startDate, untilDate, recurrence.interval, recurrence.daysOfWeek);
1187
+ case 'monthly':
1188
+ return this.buildMonthlyOccurrences(startDate, untilDate, recurrence.interval);
1189
+ case 'yearly':
1190
+ return this.buildYearlyOccurrences(startDate, untilDate, recurrence.interval);
1191
+ default:
1192
+ return [startDate];
1193
+ }
1194
+ }
1195
+ buildDailyOccurrences(startDate, untilDate, interval) {
1196
+ const dates = [];
1197
+ for (let current = startDate; current.getTime() <= untilDate.getTime(); current = this.addDaysUtc(current, interval)) {
1198
+ dates.push(current);
1199
+ }
1200
+ return dates;
1201
+ }
1202
+ buildWeeklyOccurrences(startDate, untilDate, interval, daysOfWeek) {
1203
+ const dates = [];
1204
+ const weekStart = this.startOfWeekMonday(startDate);
1205
+ const normalizedDays = (daysOfWeek === null || daysOfWeek === void 0 ? void 0 : daysOfWeek.length)
1206
+ ? daysOfWeek
1207
+ : [this.getDayCode(startDate)];
1208
+ for (let currentWeek = weekStart; currentWeek.getTime() <= untilDate.getTime(); currentWeek = this.addDaysUtc(currentWeek, interval * 7)) {
1209
+ for (const dayCode of normalizedDays) {
1210
+ const candidate = this.addDaysUtc(currentWeek, ClassGroupService_1.DAY_ORDER.indexOf(dayCode));
1211
+ if (candidate.getTime() < startDate.getTime()) {
1212
+ continue;
1213
+ }
1214
+ if (candidate.getTime() > untilDate.getTime()) {
1215
+ continue;
1216
+ }
1217
+ dates.push(candidate);
1218
+ }
1219
+ }
1220
+ return dates.sort((left, right) => left.getTime() - right.getTime());
1221
+ }
1222
+ buildMonthlyOccurrences(startDate, untilDate, interval) {
1223
+ const dates = [];
1224
+ for (let offset = 0;; offset += interval) {
1225
+ const candidate = this.addMonthsUtc(startDate, offset);
1226
+ if (!candidate) {
1227
+ continue;
1228
+ }
1229
+ if (candidate.getTime() > untilDate.getTime()) {
1230
+ break;
1231
+ }
1232
+ dates.push(candidate);
1233
+ }
1234
+ return dates;
1235
+ }
1236
+ buildYearlyOccurrences(startDate, untilDate, interval) {
1237
+ const dates = [];
1238
+ for (let offset = 0;; offset += interval) {
1239
+ const candidate = this.addYearsUtc(startDate, offset);
1240
+ if (!candidate) {
1241
+ continue;
1242
+ }
1243
+ if (candidate.getTime() > untilDate.getTime()) {
1244
+ break;
1245
+ }
1246
+ dates.push(candidate);
1247
+ }
1248
+ return dates;
1249
+ }
1250
+ parseRecurrenceRule(value) {
1251
+ if (!value) {
1252
+ return null;
1253
+ }
1254
+ try {
1255
+ const parsed = JSON.parse(value);
1256
+ return (parsed === null || parsed === void 0 ? void 0 : parsed.frequency) ? parsed : null;
1257
+ }
1258
+ catch (_a) {
1259
+ return null;
1260
+ }
1261
+ }
1262
+ toSessionDate(value) {
1263
+ if (value instanceof Date) {
1264
+ return this.normalizeSessionDate(value);
1265
+ }
1266
+ const match = /^(\d{4})-(\d{2})-(\d{2})/.exec(value !== null && value !== void 0 ? value : '');
1267
+ if (!match) {
1268
+ throw new common_1.BadRequestException('Invalid session date');
1269
+ }
1270
+ return new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), 12, 0, 0, 0));
1271
+ }
1272
+ normalizeSessionDate(value) {
1273
+ return new Date(Date.UTC(value.getUTCFullYear(), value.getUTCMonth(), value.getUTCDate(), 12, 0, 0, 0));
1274
+ }
1275
+ toDateKey(value) {
1276
+ return value.toISOString().slice(0, 10);
1277
+ }
1278
+ getDayCode(value) {
1279
+ return ClassGroupService_1.UTC_DAY_TO_CODE[value.getUTCDay()];
1280
+ }
1281
+ startOfWeekMonday(value) {
1282
+ const day = value.getUTCDay();
1283
+ const diff = day === 0 ? -6 : 1 - day;
1284
+ return this.addDaysUtc(value, diff);
1285
+ }
1286
+ addDaysUtc(value, amount) {
1287
+ const next = new Date(value.getTime());
1288
+ next.setUTCDate(next.getUTCDate() + amount);
1289
+ return this.normalizeSessionDate(next);
1290
+ }
1291
+ addMonthsUtc(value, amount) {
1292
+ const year = value.getUTCFullYear();
1293
+ const month = value.getUTCMonth() + amount;
1294
+ const day = value.getUTCDate();
1295
+ const candidate = new Date(Date.UTC(year, month, day, 12, 0, 0, 0));
1296
+ if (candidate.getUTCDate() !== day) {
1297
+ return null;
1298
+ }
1299
+ return candidate;
1300
+ }
1301
+ addYearsUtc(value, amount) {
1302
+ const year = value.getUTCFullYear() + amount;
1303
+ const month = value.getUTCMonth();
1304
+ const day = value.getUTCDate();
1305
+ const candidate = new Date(Date.UTC(year, month, day, 12, 0, 0, 0));
1306
+ if (candidate.getUTCMonth() !== month || candidate.getUTCDate() !== day) {
1307
+ return null;
1308
+ }
1309
+ return candidate;
1310
+ }
1311
+ diffInDays(left, right) {
1312
+ const msPerDay = 24 * 60 * 60 * 1000;
1313
+ return Math.round((this.normalizeSessionDate(left).getTime() - this.normalizeSessionDate(right).getTime()) /
1314
+ msPerDay);
1315
+ }
1316
+ async assertInstructorExists(instructorId) {
1317
+ const instructor = await this.prisma.instructor.findUnique({
1318
+ where: { id: instructorId },
1319
+ select: { id: true },
1320
+ });
1321
+ if (!instructor) {
1322
+ throw new common_1.NotFoundException('Instructor not found');
1323
+ }
1324
+ }
1325
+ handlePrismaError(error) {
1326
+ if (error instanceof library_1.PrismaClientKnownRequestError &&
1327
+ error.code === 'P2002') {
1328
+ throw new common_1.ConflictException('Class code already exists');
1329
+ }
1330
+ throw error;
1331
+ }
1332
+ };
1333
+ exports.ClassGroupService = ClassGroupService;
1334
+ ClassGroupService.DAY_ORDER = [
1335
+ 'MO',
1336
+ 'TU',
1337
+ 'WE',
1338
+ 'TH',
1339
+ 'FR',
1340
+ 'SA',
1341
+ 'SU',
1342
+ ];
1343
+ ClassGroupService.UTC_DAY_TO_CODE = [
1344
+ 'SU',
1345
+ 'MO',
1346
+ 'TU',
1347
+ 'WE',
1348
+ 'TH',
1349
+ 'FR',
1350
+ 'SA',
1351
+ ];
1352
+ exports.ClassGroupService = ClassGroupService = ClassGroupService_1 = __decorate([
1353
+ (0, common_1.Injectable)(),
1354
+ __metadata("design:paramtypes", [api_prisma_1.PrismaService])
1355
+ ], ClassGroupService);
1356
+ //# sourceMappingURL=class-group.service.js.map