@studious-lms/server 1.2.44 → 1.2.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/.env.example +45 -0
  2. package/.env.test.example +37 -0
  3. package/README.md +34 -7
  4. package/coverage/base.css +224 -0
  5. package/coverage/block-navigation.js +87 -0
  6. package/coverage/clover.xml +12110 -0
  7. package/coverage/coverage-final.json +44 -0
  8. package/coverage/favicon.png +0 -0
  9. package/coverage/index.html +221 -0
  10. package/coverage/prettify.css +1 -0
  11. package/coverage/prettify.js +2 -0
  12. package/coverage/server/index.html +116 -0
  13. package/coverage/server/src/exportType.ts.html +109 -0
  14. package/coverage/server/src/index.html +161 -0
  15. package/coverage/server/src/index.ts.html +1702 -0
  16. package/coverage/server/src/instrument.ts.html +130 -0
  17. package/coverage/server/src/lib/config/env.ts.html +448 -0
  18. package/coverage/server/src/lib/config/index.html +116 -0
  19. package/coverage/server/src/lib/fileUpload.ts.html +1138 -0
  20. package/coverage/server/src/lib/googleCloudStorage.ts.html +334 -0
  21. package/coverage/server/src/lib/index.html +206 -0
  22. package/coverage/server/src/lib/jsonConversion.ts.html +2323 -0
  23. package/coverage/server/src/lib/jsonStyles.ts.html +193 -0
  24. package/coverage/server/src/lib/notificationHandler.ts.html +193 -0
  25. package/coverage/server/src/lib/pusher.ts.html +121 -0
  26. package/coverage/server/src/lib/thumbnailGenerator.ts.html +592 -0
  27. package/coverage/server/src/middleware/auth.ts.html +646 -0
  28. package/coverage/server/src/middleware/index.html +146 -0
  29. package/coverage/server/src/middleware/logging.ts.html +244 -0
  30. package/coverage/server/src/middleware/security.ts.html +271 -0
  31. package/coverage/server/src/routers/_app.ts.html +232 -0
  32. package/coverage/server/src/routers/agenda.ts.html +319 -0
  33. package/coverage/server/src/routers/announcement.ts.html +3481 -0
  34. package/coverage/server/src/routers/assignment.ts.html +7633 -0
  35. package/coverage/server/src/routers/attendance.ts.html +1030 -0
  36. package/coverage/server/src/routers/auth.ts.html +1081 -0
  37. package/coverage/server/src/routers/class.ts.html +3535 -0
  38. package/coverage/server/src/routers/comment.ts.html +991 -0
  39. package/coverage/server/src/routers/conversation.ts.html +982 -0
  40. package/coverage/server/src/routers/event.ts.html +1609 -0
  41. package/coverage/server/src/routers/file.ts.html +1144 -0
  42. package/coverage/server/src/routers/folder.ts.html +2797 -0
  43. package/coverage/server/src/routers/index.html +386 -0
  44. package/coverage/server/src/routers/labChat.ts.html +3073 -0
  45. package/coverage/server/src/routers/marketing.ts.html +340 -0
  46. package/coverage/server/src/routers/message.ts.html +1912 -0
  47. package/coverage/server/src/routers/notifications.ts.html +364 -0
  48. package/coverage/server/src/routers/section.ts.html +1120 -0
  49. package/coverage/server/src/routers/user.ts.html +862 -0
  50. package/coverage/server/src/routers/worksheet.ts.html +1729 -0
  51. package/coverage/server/src/trpc.ts.html +397 -0
  52. package/coverage/server/src/types/index.html +116 -0
  53. package/coverage/server/src/types/trpc.ts.html +127 -0
  54. package/coverage/server/src/utils/aiUser.ts.html +280 -0
  55. package/coverage/server/src/utils/email.ts.html +121 -0
  56. package/coverage/server/src/utils/generateInviteCode.ts.html +106 -0
  57. package/coverage/server/src/utils/index.html +206 -0
  58. package/coverage/server/src/utils/inference.ts.html +709 -0
  59. package/coverage/server/src/utils/logger.ts.html +664 -0
  60. package/coverage/server/src/utils/prismaErrorHandler.ts.html +907 -0
  61. package/coverage/server/src/utils/prismaWrapper.ts.html +355 -0
  62. package/coverage/server/vitest.config.ts.html +196 -0
  63. package/coverage/sort-arrow-sprite.png +0 -0
  64. package/coverage/sorter.js +210 -0
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +83 -52
  67. package/dist/index.js.map +1 -1
  68. package/dist/instrument.js +15 -8
  69. package/dist/instrument.js.map +1 -1
  70. package/dist/lib/config/env.d.ts +169 -0
  71. package/dist/lib/config/env.d.ts.map +1 -0
  72. package/dist/lib/config/env.js +115 -0
  73. package/dist/lib/config/env.js.map +1 -0
  74. package/dist/lib/fileUpload.d.ts.map +1 -1
  75. package/dist/lib/fileUpload.js +5 -4
  76. package/dist/lib/fileUpload.js.map +1 -1
  77. package/dist/lib/googleCloudStorage.d.ts.map +1 -1
  78. package/dist/lib/googleCloudStorage.js +7 -8
  79. package/dist/lib/googleCloudStorage.js.map +1 -1
  80. package/dist/lib/jsonConversion.d.ts.map +1 -1
  81. package/dist/lib/jsonConversion.js +14 -16
  82. package/dist/lib/jsonConversion.js.map +1 -1
  83. package/dist/lib/notificationHandler.d.ts +2 -2
  84. package/dist/lib/prisma.d.ts +2 -2
  85. package/dist/lib/prisma.d.ts.map +1 -1
  86. package/dist/lib/prisma.js +22 -3
  87. package/dist/lib/prisma.js.map +1 -1
  88. package/dist/lib/pusher.d.ts.map +1 -1
  89. package/dist/lib/pusher.js +8 -7
  90. package/dist/lib/pusher.js.map +1 -1
  91. package/dist/middleware/auth.d.ts.map +1 -1
  92. package/dist/middleware/auth.js +6 -5
  93. package/dist/middleware/auth.js.map +1 -1
  94. package/dist/middleware/security.d.ts +5 -0
  95. package/dist/middleware/security.d.ts.map +1 -0
  96. package/dist/middleware/security.js +77 -0
  97. package/dist/middleware/security.js.map +1 -0
  98. package/dist/routers/_app.d.ts +304 -98
  99. package/dist/routers/_app.d.ts.map +1 -1
  100. package/dist/routers/_app.js +4 -2
  101. package/dist/routers/_app.js.map +1 -1
  102. package/dist/routers/agenda.d.ts.map +1 -1
  103. package/dist/routers/agenda.js +12 -9
  104. package/dist/routers/agenda.js.map +1 -1
  105. package/dist/routers/announcement.d.ts +8 -0
  106. package/dist/routers/announcement.d.ts.map +1 -1
  107. package/dist/routers/announcement.js +6 -4
  108. package/dist/routers/announcement.js.map +1 -1
  109. package/dist/routers/assignment.d.ts +7 -4
  110. package/dist/routers/assignment.d.ts.map +1 -1
  111. package/dist/routers/assignment.js +35 -18
  112. package/dist/routers/assignment.js.map +1 -1
  113. package/dist/routers/attendance.d.ts +1 -0
  114. package/dist/routers/attendance.d.ts.map +1 -1
  115. package/dist/routers/attendance.js +4 -4
  116. package/dist/routers/attendance.js.map +1 -1
  117. package/dist/routers/auth.d.ts +20 -0
  118. package/dist/routers/auth.d.ts.map +1 -1
  119. package/dist/routers/auth.js +132 -15
  120. package/dist/routers/auth.js.map +1 -1
  121. package/dist/routers/class.d.ts +10 -0
  122. package/dist/routers/class.d.ts.map +1 -1
  123. package/dist/routers/class.js +49 -5
  124. package/dist/routers/class.js.map +1 -1
  125. package/dist/routers/comment.d.ts +7 -0
  126. package/dist/routers/comment.d.ts.map +1 -1
  127. package/dist/routers/comment.js +9 -2
  128. package/dist/routers/comment.js.map +1 -1
  129. package/dist/routers/conversation.d.ts +1 -0
  130. package/dist/routers/conversation.d.ts.map +1 -1
  131. package/dist/routers/conversation.js +46 -31
  132. package/dist/routers/conversation.js.map +1 -1
  133. package/dist/routers/file.d.ts.map +1 -1
  134. package/dist/routers/file.js +30 -7
  135. package/dist/routers/file.js.map +1 -1
  136. package/dist/routers/labChat.d.ts +1 -0
  137. package/dist/routers/labChat.d.ts.map +1 -1
  138. package/dist/routers/labChat.js +2 -3
  139. package/dist/routers/labChat.js.map +1 -1
  140. package/dist/routers/marketing.d.ts +1 -1
  141. package/dist/routers/newtonChat.d.ts +55 -0
  142. package/dist/routers/newtonChat.d.ts.map +1 -0
  143. package/dist/routers/newtonChat.js +438 -0
  144. package/dist/routers/newtonChat.js.map +1 -0
  145. package/dist/routers/notifications.d.ts +4 -4
  146. package/dist/routers/section.d.ts +9 -4
  147. package/dist/routers/section.d.ts.map +1 -1
  148. package/dist/routers/section.js +8 -8
  149. package/dist/routers/section.js.map +1 -1
  150. package/dist/routers/user.d.ts.map +1 -1
  151. package/dist/routers/user.js +5 -4
  152. package/dist/routers/user.js.map +1 -1
  153. package/dist/routers/worksheet.d.ts +30 -36
  154. package/dist/routers/worksheet.d.ts.map +1 -1
  155. package/dist/routers/worksheet.js +11 -33
  156. package/dist/routers/worksheet.js.map +1 -1
  157. package/dist/seedDatabase.d.ts +1 -1
  158. package/dist/seedDatabase.js +275 -284
  159. package/dist/seedDatabase.js.map +1 -1
  160. package/dist/server/pipelines/aiLabChat.d.ts +10 -0
  161. package/dist/server/pipelines/aiLabChat.d.ts.map +1 -0
  162. package/dist/server/pipelines/aiLabChat.js +83 -0
  163. package/dist/server/pipelines/aiLabChat.js.map +1 -0
  164. package/dist/server/pipelines/gradeWorksheet.d.ts +2 -0
  165. package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -0
  166. package/dist/server/pipelines/gradeWorksheet.js +138 -0
  167. package/dist/server/pipelines/gradeWorksheet.js.map +1 -0
  168. package/dist/trpc.d.ts.map +1 -1
  169. package/dist/trpc.js +2 -2
  170. package/dist/trpc.js.map +1 -1
  171. package/dist/utils/email.d.ts +9 -1
  172. package/dist/utils/email.d.ts.map +1 -1
  173. package/dist/utils/email.js +20 -5
  174. package/dist/utils/email.js.map +1 -1
  175. package/dist/utils/inference.d.ts +3 -0
  176. package/dist/utils/inference.d.ts.map +1 -1
  177. package/dist/utils/inference.js +41 -7
  178. package/dist/utils/inference.js.map +1 -1
  179. package/dist/utils/logger.d.ts.map +1 -1
  180. package/dist/utils/logger.js +3 -3
  181. package/dist/utils/logger.js.map +1 -1
  182. package/docker-compose.yml +14 -0
  183. package/package.json +13 -4
  184. package/prisma/schema.prisma +32 -5
  185. package/scripts/test-pre-push.ts +14 -0
  186. package/src/index.ts +98 -54
  187. package/src/instrument.ts +13 -6
  188. package/src/lib/config/env.ts +126 -0
  189. package/src/lib/fileUpload.ts +3 -2
  190. package/src/lib/googleCloudStorage.ts +6 -6
  191. package/src/lib/jsonConversion.ts +12 -14
  192. package/src/lib/prisma.ts +23 -2
  193. package/src/lib/pusher.ts +6 -5
  194. package/src/middleware/auth.ts +4 -3
  195. package/src/middleware/security.ts +80 -0
  196. package/src/routers/_app.ts +2 -0
  197. package/src/routers/agenda.ts +10 -7
  198. package/src/routers/announcement.ts +4 -2
  199. package/src/routers/assignment.ts +58 -40
  200. package/src/routers/attendance.ts +2 -2
  201. package/src/routers/auth.ts +143 -14
  202. package/src/routers/class.ts +52 -3
  203. package/src/routers/comment.ts +7 -0
  204. package/src/routers/conversation.ts +49 -29
  205. package/src/routers/file.ts +29 -5
  206. package/src/routers/labChat.ts +0 -1
  207. package/src/routers/newtonChat.ts +520 -0
  208. package/src/routers/section.ts +6 -6
  209. package/src/routers/user.ts +3 -2
  210. package/src/routers/worksheet.ts +9 -37
  211. package/src/seedDatabase.ts +290 -283
  212. package/src/server/pipelines/aiLabChat.ts +92 -0
  213. package/src/server/pipelines/gradeWorksheet.ts +152 -0
  214. package/src/trpc.ts +2 -0
  215. package/src/utils/email.ts +30 -3
  216. package/src/utils/inference.ts +50 -5
  217. package/src/utils/logger.ts +2 -1
  218. package/tests/announcement.test.ts +164 -0
  219. package/tests/assignment.test.ts +296 -0
  220. package/tests/attendance.test.ts +168 -0
  221. package/tests/auth.test.ts +33 -10
  222. package/tests/class.test.ts +34 -9
  223. package/tests/event.test.ts +228 -0
  224. package/tests/section.test.ts +216 -0
  225. package/tests/setup.ts +70 -16
  226. package/tests/user.test.ts +158 -0
  227. package/vitest.config.ts +26 -0
  228. package/API_SPECIFICATION.md +0 -1597
  229. package/BASE64_REMOVAL_SUMMARY.md +0 -164
  230. package/CHAT_API_SPEC.md +0 -579
  231. package/LAB_CHAT_API_SPEC.md +0 -518
  232. package/dist/routers/school.d.ts +0 -208
  233. package/dist/routers/school.d.ts.map +0 -1
  234. package/dist/routers/school.js +0 -483
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="98db11d4-da3a-5c7c-8f67-c604c660ab92")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="09930a12-9a9b-58e3-b149-ce107a08a4b0")}catch(e){}}();
3
3
  import { prisma } from "./lib/prisma.js";
4
4
  import { hash } from "bcryptjs";
5
5
  import { logger } from "./utils/logger.js";
@@ -848,8 +848,22 @@ export const seedDatabase = async () => {
848
848
  });
849
849
  }
850
850
  }
851
- // Create all submissions
852
- await Promise.all(submissionsToCreate.map(submission => prisma.submission.create({ data: submission })));
851
+ // Create all submissions in batches to avoid connection pool exhaustion
852
+ const BATCH_SIZE = 15; // Create 15 at a time to avoid overwhelming Supabase connection pool
853
+ logger.info(`Creating ${submissionsToCreate.length} submissions in batches of ${BATCH_SIZE}`);
854
+ for (let i = 0; i < submissionsToCreate.length; i += BATCH_SIZE) {
855
+ const batch = submissionsToCreate.slice(i, i + BATCH_SIZE);
856
+ await Promise.all(batch.map(submission => prisma.submission.create({ data: submission })));
857
+ // Small delay between batches to avoid overwhelming the connection pool
858
+ if (i + BATCH_SIZE < submissionsToCreate.length) {
859
+ await new Promise(resolve => setTimeout(resolve, 100)); // 100ms delay
860
+ }
861
+ // Log progress every 30 submissions or at the end
862
+ if ((i + BATCH_SIZE) % 30 === 0 || i + BATCH_SIZE >= submissionsToCreate.length) {
863
+ logger.info(`Created ${Math.min(i + BATCH_SIZE, submissionsToCreate.length)}/${submissionsToCreate.length} submissions`);
864
+ }
865
+ }
866
+ logger.info(`Successfully created all ${submissionsToCreate.length} submissions`);
853
867
  // 11. Create announcements
854
868
  await Promise.all([
855
869
  prisma.announcement.create({
@@ -883,285 +897,250 @@ export const seedDatabase = async () => {
883
897
  const oct9 = new Date('2025-10-09T08:00:00');
884
898
  const oct10 = new Date('2025-10-10T08:00:00');
885
899
  const oct11 = new Date('2025-10-11T08:00:00');
886
- await Promise.all([
900
+ // Build events array first, then batch create them
901
+ const eventsToCreate = [
887
902
  // Monday Oct 7 - Michael Chen's busy day
888
- prisma.event.create({
889
- data: {
890
- name: 'AP Calculus BC - Period 2',
891
- startTime: new Date('2025-10-07T09:15:00'),
892
- endTime: new Date('2025-10-07T10:05:00'),
893
- location: 'Room 156',
894
- remarks: 'Derivatives unit test review',
895
- userId: teachers[1].id,
896
- classId: mathClass.id,
897
- color: '#3B82F6',
898
- }
899
- }),
900
- prisma.event.create({
901
- data: {
902
- name: 'Department Head Meeting',
903
- startTime: new Date('2025-10-07T10:30:00'),
904
- endTime: new Date('2025-10-07T11:30:00'),
905
- location: 'Conference Room A',
906
- remarks: 'Monthly math department meeting - curriculum planning',
907
- userId: teachers[1].id,
908
- color: '#8B5CF6',
909
- }
910
- }),
911
- prisma.event.create({
912
- data: {
913
- name: 'AP Statistics - Period 5',
914
- startTime: new Date('2025-10-07T13:45:00'),
915
- endTime: new Date('2025-10-07T14:35:00'),
916
- location: 'Room 156',
917
- remarks: 'Hypothesis testing introduction',
918
- userId: teachers[1].id,
919
- color: '#3B82F6',
920
- }
921
- }),
922
- prisma.event.create({
923
- data: {
924
- name: 'Parent Conference - Williams Family',
925
- startTime: new Date('2025-10-07T15:00:00'),
926
- endTime: new Date('2025-10-07T15:30:00'),
927
- location: 'Room 156',
928
- remarks: 'Discuss Sophia\'s progress in AP Calculus',
929
- userId: teachers[1].id,
930
- color: '#F59E0B',
931
- }
932
- }),
933
- prisma.event.create({
934
- data: {
935
- name: 'Math Tutoring Session',
936
- startTime: new Date('2025-10-07T15:45:00'),
937
- endTime: new Date('2025-10-07T16:45:00'),
938
- location: 'Room 156',
939
- remarks: 'Extra help for struggling students',
940
- userId: teachers[1].id,
941
- color: '#10B981',
942
- }
943
- }),
903
+ {
904
+ name: 'AP Calculus BC - Period 2',
905
+ startTime: new Date('2025-10-07T09:15:00'),
906
+ endTime: new Date('2025-10-07T10:05:00'),
907
+ location: 'Room 156',
908
+ remarks: 'Derivatives unit test review',
909
+ userId: teachers[1].id,
910
+ classId: mathClass.id,
911
+ color: '#3B82F6',
912
+ },
913
+ {
914
+ name: 'Department Head Meeting',
915
+ startTime: new Date('2025-10-07T10:30:00'),
916
+ endTime: new Date('2025-10-07T11:30:00'),
917
+ location: 'Conference Room A',
918
+ remarks: 'Monthly math department meeting - curriculum planning',
919
+ userId: teachers[1].id,
920
+ color: '#8B5CF6',
921
+ },
922
+ {
923
+ name: 'AP Statistics - Period 5',
924
+ startTime: new Date('2025-10-07T13:45:00'),
925
+ endTime: new Date('2025-10-07T14:35:00'),
926
+ location: 'Room 156',
927
+ remarks: 'Hypothesis testing introduction',
928
+ userId: teachers[1].id,
929
+ color: '#3B82F6',
930
+ },
931
+ {
932
+ name: 'Parent Conference - Williams Family',
933
+ startTime: new Date('2025-10-07T15:00:00'),
934
+ endTime: new Date('2025-10-07T15:30:00'),
935
+ location: 'Room 156',
936
+ remarks: 'Discuss Sophia\'s progress in AP Calculus',
937
+ userId: teachers[1].id,
938
+ color: '#F59E0B',
939
+ },
940
+ {
941
+ name: 'Math Tutoring Session',
942
+ startTime: new Date('2025-10-07T15:45:00'),
943
+ endTime: new Date('2025-10-07T16:45:00'),
944
+ location: 'Room 156',
945
+ remarks: 'Extra help for struggling students',
946
+ userId: teachers[1].id,
947
+ color: '#10B981',
948
+ },
944
949
  // Tuesday Oct 8
945
- prisma.event.create({
946
- data: {
947
- name: 'AP Calculus BC - Period 2',
948
- startTime: new Date('2025-10-08T09:15:00'),
949
- endTime: new Date('2025-10-08T10:05:00'),
950
- location: 'Room 156',
951
- remarks: 'Derivatives unit test',
952
- userId: teachers[1].id,
953
- classId: mathClass.id,
954
- color: '#3B82F6',
955
- }
956
- }),
957
- prisma.event.create({
958
- data: {
959
- name: 'Faculty Meeting',
960
- startTime: new Date('2025-10-08T12:00:00'),
961
- endTime: new Date('2025-10-08T13:00:00'),
962
- location: 'Main Auditorium',
963
- remarks: 'All-school faculty meeting',
964
- userId: teachers[1].id,
965
- color: '#6B7280',
966
- }
967
- }),
968
- prisma.event.create({
969
- data: {
970
- name: 'AP Statistics - Period 5',
971
- startTime: new Date('2025-10-08T13:45:00'),
972
- endTime: new Date('2025-10-08T14:35:00'),
973
- location: 'Room 156',
974
- remarks: 'Hypothesis testing practice problems',
975
- userId: teachers[1].id,
976
- color: '#3B82F6',
977
- }
978
- }),
979
- prisma.event.create({
980
- data: {
981
- name: 'Grade Level Team Meeting',
982
- startTime: new Date('2025-10-08T15:00:00'),
983
- endTime: new Date('2025-10-08T16:00:00'),
984
- location: 'Room 201',
985
- remarks: '11th grade team coordination',
986
- userId: teachers[1].id,
987
- color: '#8B5CF6',
988
- }
989
- }),
950
+ {
951
+ name: 'AP Calculus BC - Period 2',
952
+ startTime: new Date('2025-10-08T09:15:00'),
953
+ endTime: new Date('2025-10-08T10:05:00'),
954
+ location: 'Room 156',
955
+ remarks: 'Derivatives unit test',
956
+ userId: teachers[1].id,
957
+ classId: mathClass.id,
958
+ color: '#3B82F6',
959
+ },
960
+ {
961
+ name: 'Faculty Meeting',
962
+ startTime: new Date('2025-10-08T12:00:00'),
963
+ endTime: new Date('2025-10-08T13:00:00'),
964
+ location: 'Main Auditorium',
965
+ remarks: 'All-school faculty meeting',
966
+ userId: teachers[1].id,
967
+ color: '#6B7280',
968
+ },
969
+ {
970
+ name: 'AP Statistics - Period 5',
971
+ startTime: new Date('2025-10-08T13:45:00'),
972
+ endTime: new Date('2025-10-08T14:35:00'),
973
+ location: 'Room 156',
974
+ remarks: 'Hypothesis testing practice problems',
975
+ userId: teachers[1].id,
976
+ color: '#3B82F6',
977
+ },
978
+ {
979
+ name: 'Grade Level Team Meeting',
980
+ startTime: new Date('2025-10-08T15:00:00'),
981
+ endTime: new Date('2025-10-08T16:00:00'),
982
+ location: 'Room 201',
983
+ remarks: '11th grade team coordination',
984
+ userId: teachers[1].id,
985
+ color: '#8B5CF6',
986
+ },
990
987
  // Wednesday Oct 9
991
- prisma.event.create({
992
- data: {
993
- name: 'AP Calculus BC - Period 2',
994
- startTime: new Date('2025-10-09T09:15:00'),
995
- endTime: new Date('2025-10-09T10:05:00'),
996
- location: 'Room 156',
997
- remarks: 'Integration introduction',
998
- userId: teachers[1].id,
999
- classId: mathClass.id,
1000
- color: '#3B82F6',
1001
- }
1002
- }),
1003
- prisma.event.create({
1004
- data: {
1005
- name: 'Professional Development',
1006
- startTime: new Date('2025-10-09T11:00:00'),
1007
- endTime: new Date('2025-10-09T12:30:00'),
1008
- location: 'Library Conference Room',
1009
- remarks: 'Technology in Mathematics Education workshop',
1010
- userId: teachers[1].id,
1011
- color: '#059669',
1012
- }
1013
- }),
1014
- prisma.event.create({
1015
- data: {
1016
- name: 'AP Statistics - Period 5',
1017
- startTime: new Date('2025-10-09T13:45:00'),
1018
- endTime: new Date('2025-10-09T14:35:00'),
1019
- location: 'Room 156',
1020
- remarks: 'Chi-square tests',
1021
- userId: teachers[1].id,
1022
- color: '#3B82F6',
1023
- }
1024
- }),
1025
- prisma.event.create({
1026
- data: {
1027
- name: 'Student Council Advisory',
1028
- startTime: new Date('2025-10-09T15:00:00'),
1029
- endTime: new Date('2025-10-09T16:00:00'),
1030
- location: 'Room 105',
1031
- remarks: 'Advisor meeting for student council',
1032
- userId: teachers[1].id,
1033
- color: '#DC2626',
1034
- }
1035
- }),
988
+ {
989
+ name: 'AP Calculus BC - Period 2',
990
+ startTime: new Date('2025-10-09T09:15:00'),
991
+ endTime: new Date('2025-10-09T10:05:00'),
992
+ location: 'Room 156',
993
+ remarks: 'Integration introduction',
994
+ userId: teachers[1].id,
995
+ classId: mathClass.id,
996
+ color: '#3B82F6',
997
+ },
998
+ {
999
+ name: 'Professional Development',
1000
+ startTime: new Date('2025-10-09T11:00:00'),
1001
+ endTime: new Date('2025-10-09T12:30:00'),
1002
+ location: 'Library Conference Room',
1003
+ remarks: 'Technology in Mathematics Education workshop',
1004
+ userId: teachers[1].id,
1005
+ color: '#059669',
1006
+ },
1007
+ {
1008
+ name: 'AP Statistics - Period 5',
1009
+ startTime: new Date('2025-10-09T13:45:00'),
1010
+ endTime: new Date('2025-10-09T14:35:00'),
1011
+ location: 'Room 156',
1012
+ remarks: 'Chi-square tests',
1013
+ userId: teachers[1].id,
1014
+ color: '#3B82F6',
1015
+ },
1016
+ {
1017
+ name: 'Student Council Advisory',
1018
+ startTime: new Date('2025-10-09T15:00:00'),
1019
+ endTime: new Date('2025-10-09T16:00:00'),
1020
+ location: 'Room 105',
1021
+ remarks: 'Advisor meeting for student council',
1022
+ userId: teachers[1].id,
1023
+ color: '#DC2626',
1024
+ },
1036
1025
  // Thursday Oct 10
1037
- prisma.event.create({
1038
- data: {
1039
- name: 'AP Calculus BC - Period 2',
1040
- startTime: new Date('2025-10-10T09:15:00'),
1041
- endTime: new Date('2025-10-10T10:05:00'),
1042
- location: 'Room 156',
1043
- remarks: 'Integration by substitution',
1044
- userId: teachers[1].id,
1045
- classId: mathClass.id,
1046
- color: '#3B82F6',
1047
- }
1048
- }),
1049
- prisma.event.create({
1050
- data: {
1051
- name: 'Curriculum Committee',
1052
- startTime: new Date('2025-10-10T11:00:00'),
1053
- endTime: new Date('2025-10-10T12:00:00'),
1054
- location: 'Principal\'s Office',
1055
- remarks: 'Review new AP curriculum standards',
1056
- userId: teachers[1].id,
1057
- color: '#8B5CF6',
1058
- }
1059
- }),
1060
- prisma.event.create({
1061
- data: {
1062
- name: 'AP Statistics - Period 5',
1063
- startTime: new Date('2025-10-10T13:45:00'),
1064
- endTime: new Date('2025-10-10T14:35:00'),
1065
- location: 'Room 156',
1066
- remarks: 'ANOVA introduction',
1067
- userId: teachers[1].id,
1068
- color: '#3B82F6',
1069
- }
1070
- }),
1071
- prisma.event.create({
1072
- data: {
1073
- name: 'Parent Conference - Anderson Family',
1074
- startTime: new Date('2025-10-10T15:00:00'),
1075
- endTime: new Date('2025-10-10T15:30:00'),
1076
- location: 'Room 156',
1077
- remarks: 'Discuss Ethan\'s improvement strategies',
1078
- userId: teachers[1].id,
1079
- color: '#F59E0B',
1080
- }
1081
- }),
1082
- prisma.event.create({
1083
- data: {
1084
- name: 'Math Club Meeting',
1085
- startTime: new Date('2025-10-10T15:45:00'),
1086
- endTime: new Date('2025-10-10T16:45:00'),
1087
- location: 'Room 156',
1088
- remarks: 'Preparing for state math competition',
1089
- userId: teachers[1].id,
1090
- color: '#10B981',
1091
- }
1092
- }),
1026
+ {
1027
+ name: 'AP Calculus BC - Period 2',
1028
+ startTime: new Date('2025-10-10T09:15:00'),
1029
+ endTime: new Date('2025-10-10T10:05:00'),
1030
+ location: 'Room 156',
1031
+ remarks: 'Integration by substitution',
1032
+ userId: teachers[1].id,
1033
+ classId: mathClass.id,
1034
+ color: '#3B82F6',
1035
+ },
1036
+ {
1037
+ name: 'Curriculum Committee',
1038
+ startTime: new Date('2025-10-10T11:00:00'),
1039
+ endTime: new Date('2025-10-10T12:00:00'),
1040
+ location: 'Principal\'s Office',
1041
+ remarks: 'Review new AP curriculum standards',
1042
+ userId: teachers[1].id,
1043
+ color: '#8B5CF6',
1044
+ },
1045
+ {
1046
+ name: 'AP Statistics - Period 5',
1047
+ startTime: new Date('2025-10-10T13:45:00'),
1048
+ endTime: new Date('2025-10-10T14:35:00'),
1049
+ location: 'Room 156',
1050
+ remarks: 'ANOVA introduction',
1051
+ userId: teachers[1].id,
1052
+ color: '#3B82F6',
1053
+ },
1054
+ {
1055
+ name: 'Parent Conference - Anderson Family',
1056
+ startTime: new Date('2025-10-10T15:00:00'),
1057
+ endTime: new Date('2025-10-10T15:30:00'),
1058
+ location: 'Room 156',
1059
+ remarks: 'Discuss Ethan\'s improvement strategies',
1060
+ userId: teachers[1].id,
1061
+ color: '#F59E0B',
1062
+ },
1063
+ {
1064
+ name: 'Math Club Meeting',
1065
+ startTime: new Date('2025-10-10T15:45:00'),
1066
+ endTime: new Date('2025-10-10T16:45:00'),
1067
+ location: 'Room 156',
1068
+ remarks: 'Preparing for state math competition',
1069
+ userId: teachers[1].id,
1070
+ color: '#10B981',
1071
+ },
1093
1072
  // Friday Oct 11
1094
- prisma.event.create({
1095
- data: {
1096
- name: 'AP Calculus BC - Period 2',
1097
- startTime: new Date('2025-10-11T09:15:00'),
1098
- endTime: new Date('2025-10-11T10:05:00'),
1099
- location: 'Room 156',
1100
- remarks: 'Integration by parts',
1101
- userId: teachers[1].id,
1102
- classId: mathClass.id,
1103
- color: '#3B82F6',
1104
- }
1105
- }),
1106
- prisma.event.create({
1107
- data: {
1108
- name: 'IEP Meeting - Student Support',
1109
- startTime: new Date('2025-10-11T10:30:00'),
1110
- endTime: new Date('2025-10-11T11:30:00'),
1111
- location: 'Special Services Office',
1112
- remarks: 'Individualized Education Plan review',
1113
- userId: teachers[1].id,
1114
- color: '#F59E0B',
1115
- }
1116
- }),
1117
- prisma.event.create({
1118
- data: {
1119
- name: 'AP Statistics - Period 5',
1120
- startTime: new Date('2025-10-11T13:45:00'),
1121
- endTime: new Date('2025-10-11T14:35:00'),
1122
- location: 'Room 156',
1123
- remarks: 'ANOVA practice and review',
1124
- userId: teachers[1].id,
1125
- color: '#3B82F6',
1126
- }
1127
- }),
1128
- prisma.event.create({
1129
- data: {
1130
- name: 'Weekend Prep Session',
1131
- startTime: new Date('2025-10-11T15:00:00'),
1132
- endTime: new Date('2025-10-11T17:00:00'),
1133
- location: 'Room 156',
1134
- remarks: 'Voluntary AP exam prep session',
1135
- userId: teachers[1].id,
1136
- color: '#059669',
1137
- }
1138
- }),
1073
+ {
1074
+ name: 'AP Calculus BC - Period 2',
1075
+ startTime: new Date('2025-10-11T09:15:00'),
1076
+ endTime: new Date('2025-10-11T10:05:00'),
1077
+ location: 'Room 156',
1078
+ remarks: 'Integration by parts',
1079
+ userId: teachers[1].id,
1080
+ classId: mathClass.id,
1081
+ color: '#3B82F6',
1082
+ },
1083
+ {
1084
+ name: 'IEP Meeting - Student Support',
1085
+ startTime: new Date('2025-10-11T10:30:00'),
1086
+ endTime: new Date('2025-10-11T11:30:00'),
1087
+ location: 'Special Services Office',
1088
+ remarks: 'Individualized Education Plan review',
1089
+ userId: teachers[1].id,
1090
+ color: '#F59E0B',
1091
+ },
1092
+ {
1093
+ name: 'AP Statistics - Period 5',
1094
+ startTime: new Date('2025-10-11T13:45:00'),
1095
+ endTime: new Date('2025-10-11T14:35:00'),
1096
+ location: 'Room 156',
1097
+ remarks: 'ANOVA practice and review',
1098
+ userId: teachers[1].id,
1099
+ color: '#3B82F6',
1100
+ },
1101
+ {
1102
+ name: 'Weekend Prep Session',
1103
+ startTime: new Date('2025-10-11T15:00:00'),
1104
+ endTime: new Date('2025-10-11T17:00:00'),
1105
+ location: 'Room 156',
1106
+ remarks: 'Voluntary AP exam prep session',
1107
+ userId: teachers[1].id,
1108
+ color: '#059669',
1109
+ },
1139
1110
  // Some events for other teachers too
1140
- prisma.event.create({
1141
- data: {
1142
- name: 'Cell Biology Lab',
1143
- startTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000),
1144
- endTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000 + 90 * 60 * 1000), // 90 minutes
1145
- location: 'Science Lab Room 204',
1146
- remarks: 'Bring lab notebooks and safety goggles',
1147
- userId: teachers[0].id,
1148
- classId: biologyClass.id,
1149
- color: '#10B981',
1150
- }
1151
- }),
1152
- prisma.event.create({
1153
- data: {
1154
- name: 'Poetry Reading',
1155
- startTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000),
1156
- endTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000 + 60 * 60 * 1000),
1157
- location: 'Library',
1158
- remarks: 'Students will present their original poetry',
1159
- userId: teachers[2].id,
1160
- classId: englishClass.id,
1161
- color: '#8B5CF6',
1162
- }
1163
- }),
1164
- ]);
1111
+ {
1112
+ name: 'Cell Biology Lab',
1113
+ startTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000),
1114
+ endTime: new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000 + 90 * 60 * 1000), // 90 minutes
1115
+ location: 'Science Lab Room 204',
1116
+ remarks: 'Bring lab notebooks and safety goggles',
1117
+ userId: teachers[0].id,
1118
+ classId: biologyClass.id,
1119
+ color: '#10B981',
1120
+ },
1121
+ {
1122
+ name: 'Poetry Reading',
1123
+ startTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000),
1124
+ endTime: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000 + 60 * 60 * 1000),
1125
+ location: 'Library',
1126
+ remarks: 'Students will present their original poetry',
1127
+ userId: teachers[2].id,
1128
+ classId: englishClass.id,
1129
+ color: '#8B5CF6',
1130
+ },
1131
+ ];
1132
+ // Create events in batches to avoid connection pool exhaustion
1133
+ const EVENT_BATCH_SIZE = 10;
1134
+ logger.info(`Creating ${eventsToCreate.length} events in batches of ${EVENT_BATCH_SIZE}`);
1135
+ for (let i = 0; i < eventsToCreate.length; i += EVENT_BATCH_SIZE) {
1136
+ const batch = eventsToCreate.slice(i, i + EVENT_BATCH_SIZE);
1137
+ await Promise.all(batch.map(event => prisma.event.create({ data: event })));
1138
+ // Small delay between batches
1139
+ if (i + EVENT_BATCH_SIZE < eventsToCreate.length) {
1140
+ await new Promise(resolve => setTimeout(resolve, 100));
1141
+ }
1142
+ }
1143
+ logger.info(`Successfully created all ${eventsToCreate.length} events`);
1165
1144
  // 13. Create attendance records
1166
1145
  const attendanceDate = new Date(now.getTime() - 24 * 60 * 60 * 1000);
1167
1146
  await Promise.all([
@@ -1449,8 +1428,14 @@ export const seedDatabase = async () => {
1449
1428
  createdAt: new Date('2024-10-11T12:30:00'),
1450
1429
  },
1451
1430
  ];
1452
- // Create all messages
1453
- await Promise.all(chatMessages.map(message => prisma.message.create({ data: message })));
1431
+ // Create all messages in batches to avoid connection pool exhaustion
1432
+ const MESSAGE_BATCH_SIZE = 10;
1433
+ logger.info(`Creating ${chatMessages.length} chat messages in batches of ${MESSAGE_BATCH_SIZE}`);
1434
+ for (let i = 0; i < chatMessages.length; i += MESSAGE_BATCH_SIZE) {
1435
+ const batch = chatMessages.slice(i, i + MESSAGE_BATCH_SIZE);
1436
+ await Promise.all(batch.map(message => prisma.message.create({ data: message })));
1437
+ }
1438
+ logger.info(`Successfully created all ${chatMessages.length} chat messages`);
1454
1439
  // 16. Create file structure for classes
1455
1440
  await Promise.all([
1456
1441
  prisma.folder.create({
@@ -1506,10 +1491,16 @@ export const seedDatabase = async () => {
1506
1491
  logger.info(' English Teacher: emma.davis@riverside.edu / demo123');
1507
1492
  logger.info(' Student: alex.martinez@student.riverside.edu / student123');
1508
1493
  };
1509
- (async () => {
1510
- logger.info('Seeding database');
1511
- await seedDatabase();
1512
- logger.info('Database seeded');
1513
- })();
1494
+ // Only run seedDatabase when executed directly (npm run seed)
1495
+ // Not when imported by other modules
1496
+ const isSeedScript = process.argv[1]?.includes('seedDatabase') ||
1497
+ process.argv.includes('seed');
1498
+ if (isSeedScript) {
1499
+ (async () => {
1500
+ logger.info('Seeding database');
1501
+ await seedDatabase();
1502
+ logger.info('Database seeded');
1503
+ })();
1504
+ }
1514
1505
  //# sourceMappingURL=seedDatabase.js.map
1515
- //# debugId=98db11d4-da3a-5c7c-8f67-c604c660ab92
1506
+ //# debugId=09930a12-9a9b-58e3-b149-ce107a08a4b0