@studious-lms/server 1.4.6 → 1.4.7

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 (148) hide show
  1. package/dist/models/access.d.ts +112 -0
  2. package/dist/models/access.d.ts.map +1 -0
  3. package/dist/models/access.js +49 -0
  4. package/dist/models/access.js.map +1 -0
  5. package/dist/models/announcement.d.ts +17 -2
  6. package/dist/models/announcement.d.ts.map +1 -1
  7. package/dist/models/announcement.js +21 -4
  8. package/dist/models/announcement.js.map +1 -1
  9. package/dist/models/assignment.d.ts +37 -37
  10. package/dist/models/assignment.d.ts.map +1 -1
  11. package/dist/models/assignment.js +15 -15
  12. package/dist/models/assignment.js.map +1 -1
  13. package/dist/models/attendance.d.ts +1 -1
  14. package/dist/models/attendance.d.ts.map +1 -1
  15. package/dist/models/attendance.js +6 -5
  16. package/dist/models/attendance.js.map +1 -1
  17. package/dist/models/auth.d.ts +5 -5
  18. package/dist/models/auth.d.ts.map +1 -1
  19. package/dist/models/auth.js +7 -11
  20. package/dist/models/auth.js.map +1 -1
  21. package/dist/models/class.d.ts +26 -26
  22. package/dist/models/class.d.ts.map +1 -1
  23. package/dist/models/class.js +7 -11
  24. package/dist/models/class.js.map +1 -1
  25. package/dist/models/comment.d.ts +134 -70
  26. package/dist/models/comment.d.ts.map +1 -1
  27. package/dist/models/comment.js +30 -42
  28. package/dist/models/comment.js.map +1 -1
  29. package/dist/models/conversation.d.ts +7 -7
  30. package/dist/models/event.d.ts +52 -3
  31. package/dist/models/event.d.ts.map +1 -1
  32. package/dist/models/event.js +56 -6
  33. package/dist/models/event.js.map +1 -1
  34. package/dist/models/file.d.ts +178 -103
  35. package/dist/models/file.d.ts.map +1 -1
  36. package/dist/models/file.js +54 -14
  37. package/dist/models/file.js.map +1 -1
  38. package/dist/models/folder.d.ts +22 -22
  39. package/dist/models/folder.d.ts.map +1 -1
  40. package/dist/models/folder.js +5 -4
  41. package/dist/models/folder.js.map +1 -1
  42. package/dist/models/labChat.d.ts +20 -20
  43. package/dist/models/labChat.d.ts.map +1 -1
  44. package/dist/models/labChat.js +8 -10
  45. package/dist/models/labChat.js.map +1 -1
  46. package/dist/models/marketing.d.ts +1 -1
  47. package/dist/models/message.d.ts +6 -6
  48. package/dist/models/newtonChat.d.ts +5 -5
  49. package/dist/models/school.d.ts +361 -0
  50. package/dist/models/school.d.ts.map +1 -0
  51. package/dist/models/school.js +314 -0
  52. package/dist/models/school.js.map +1 -0
  53. package/dist/models/section.d.ts +1 -1
  54. package/dist/models/section.d.ts.map +1 -1
  55. package/dist/models/section.js +5 -4
  56. package/dist/models/section.js.map +1 -1
  57. package/dist/models/user.d.ts +4 -4
  58. package/dist/models/worksheet.d.ts +65 -65
  59. package/dist/models/worksheet.d.ts.map +1 -1
  60. package/dist/models/worksheet.js +6 -14
  61. package/dist/models/worksheet.js.map +1 -1
  62. package/dist/pipelines/gradeWorksheet.d.ts +2 -2
  63. package/dist/pipelines/pdfToWorksheet.d.ts +1 -1
  64. package/dist/routers/_app.d.ts +2855 -2051
  65. package/dist/routers/_app.d.ts.map +1 -1
  66. package/dist/routers/_app.js +4 -2
  67. package/dist/routers/_app.js.map +1 -1
  68. package/dist/routers/announcement.d.ts +5 -5
  69. package/dist/routers/announcement.d.ts.map +1 -1
  70. package/dist/routers/announcement.js +25 -5
  71. package/dist/routers/announcement.js.map +1 -1
  72. package/dist/routers/assignment.d.ts +44 -44
  73. package/dist/routers/assignment.d.ts.map +1 -1
  74. package/dist/routers/assignment.js +24 -11
  75. package/dist/routers/assignment.js.map +1 -1
  76. package/dist/routers/class.d.ts +21 -20
  77. package/dist/routers/class.d.ts.map +1 -1
  78. package/dist/routers/class.js +3 -2
  79. package/dist/routers/class.js.map +1 -1
  80. package/dist/routers/comment.d.ts +5 -5
  81. package/dist/routers/conversation.d.ts +6 -6
  82. package/dist/routers/event.d.ts +21 -2
  83. package/dist/routers/event.d.ts.map +1 -1
  84. package/dist/routers/file.d.ts +2 -2
  85. package/dist/routers/folder.d.ts +24 -24
  86. package/dist/routers/labChat.d.ts +7 -7
  87. package/dist/routers/school.d.ts +384 -0
  88. package/dist/routers/school.d.ts.map +1 -0
  89. package/dist/routers/school.js +79 -0
  90. package/dist/routers/school.js.map +1 -0
  91. package/dist/routers/search.d.ts +1 -1
  92. package/dist/routers/worksheet.d.ts +21 -21
  93. package/dist/services/announcement.d.ts.map +1 -1
  94. package/dist/services/announcement.js +10 -6
  95. package/dist/services/announcement.js.map +1 -1
  96. package/dist/services/assignment.d.ts +36 -36
  97. package/dist/services/class.d.ts +20 -19
  98. package/dist/services/class.d.ts.map +1 -1
  99. package/dist/services/class.js +22 -3
  100. package/dist/services/class.js.map +1 -1
  101. package/dist/services/comment.d.ts +5 -5
  102. package/dist/services/comment.d.ts.map +1 -1
  103. package/dist/services/comment.js +8 -3
  104. package/dist/services/comment.js.map +1 -1
  105. package/dist/services/conversation.d.ts +6 -6
  106. package/dist/services/event.d.ts +21 -2
  107. package/dist/services/event.d.ts.map +1 -1
  108. package/dist/services/event.js +11 -7
  109. package/dist/services/event.js.map +1 -1
  110. package/dist/services/file.d.ts +2 -2
  111. package/dist/services/file.d.ts.map +1 -1
  112. package/dist/services/file.js +17 -8
  113. package/dist/services/file.js.map +1 -1
  114. package/dist/services/folder.d.ts +24 -24
  115. package/dist/services/labChat.d.ts +7 -7
  116. package/dist/services/school.d.ts +299 -0
  117. package/dist/services/school.d.ts.map +1 -0
  118. package/dist/services/school.js +225 -0
  119. package/dist/services/school.js.map +1 -0
  120. package/dist/services/worksheet.d.ts +21 -21
  121. package/package.json +1 -1
  122. package/prisma/migrations/20260504071500_school_memberships/migration.sql +81 -0
  123. package/prisma/schema.prisma +66 -2
  124. package/src/models/access.ts +48 -0
  125. package/src/models/announcement.ts +19 -2
  126. package/src/models/assignment.ts +17 -13
  127. package/src/models/attendance.ts +4 -3
  128. package/src/models/auth.ts +8 -9
  129. package/src/models/class.ts +8 -9
  130. package/src/models/comment.ts +29 -40
  131. package/src/models/event.ts +54 -4
  132. package/src/models/file.ts +53 -12
  133. package/src/models/folder.ts +3 -2
  134. package/src/models/labChat.ts +9 -8
  135. package/src/models/school.ts +361 -0
  136. package/src/models/section.ts +3 -2
  137. package/src/models/worksheet.ts +7 -12
  138. package/src/routers/_app.ts +2 -0
  139. package/src/routers/announcement.ts +30 -4
  140. package/src/routers/assignment.ts +27 -9
  141. package/src/routers/class.ts +1 -0
  142. package/src/routers/school.ts +122 -0
  143. package/src/services/announcement.ts +12 -4
  144. package/src/services/class.ts +25 -2
  145. package/src/services/comment.ts +10 -1
  146. package/src/services/event.ts +23 -6
  147. package/src/services/file.ts +20 -6
  148. package/src/services/school.ts +308 -0
@@ -0,0 +1,361 @@
1
+ /**
2
+ * School model - school membership, invites, and admin lookups.
3
+ */
4
+ import { SchoolMembershipRole } from "@prisma/client";
5
+ export declare function findSchoolMembership(schoolId: string, userId: string): import(".prisma/client").Prisma.Prisma__SchoolMembershipClient<{
6
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
7
+ id: string;
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
11
+ schoolId: string;
12
+ userId: string;
13
+ } | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
14
+ datasources: {
15
+ db: {
16
+ url: string;
17
+ };
18
+ };
19
+ }>;
20
+ export declare function findActiveSchoolMembership(schoolId: string, userId: string): import(".prisma/client").Prisma.Prisma__SchoolMembershipClient<{
21
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
22
+ id: string;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
26
+ schoolId: string;
27
+ userId: string;
28
+ } | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
29
+ datasources: {
30
+ db: {
31
+ url: string;
32
+ };
33
+ };
34
+ }>;
35
+ export declare function findActiveSchoolAdminMembership(schoolId: string, userId: string): import(".prisma/client").Prisma.Prisma__SchoolMembershipClient<{
36
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
37
+ id: string;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
41
+ schoolId: string;
42
+ userId: string;
43
+ } | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
44
+ datasources: {
45
+ db: {
46
+ url: string;
47
+ };
48
+ };
49
+ }>;
50
+ export declare function listUserSchoolMemberships(userId: string): import(".prisma/client").Prisma.PrismaPromise<({
51
+ school: {
52
+ name: string;
53
+ id: string;
54
+ logoId: string | null;
55
+ subdomain: string | null;
56
+ createdAt: Date;
57
+ updatedAt: Date;
58
+ };
59
+ } & {
60
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
61
+ id: string;
62
+ createdAt: Date;
63
+ updatedAt: Date;
64
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
65
+ schoolId: string;
66
+ userId: string;
67
+ })[]>;
68
+ export declare function createSchoolWithAdmin(data: {
69
+ name: string;
70
+ subdomain?: string;
71
+ logoId?: string;
72
+ userId: string;
73
+ }): import(".prisma/client").Prisma.Prisma__SchoolClient<{
74
+ memberships: {
75
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
76
+ id: string;
77
+ createdAt: Date;
78
+ updatedAt: Date;
79
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
80
+ schoolId: string;
81
+ userId: string;
82
+ }[];
83
+ } & {
84
+ name: string;
85
+ id: string;
86
+ logoId: string | null;
87
+ subdomain: string | null;
88
+ createdAt: Date;
89
+ updatedAt: Date;
90
+ }, never, import("@prisma/client/runtime/library.js").DefaultArgs, {
91
+ datasources: {
92
+ db: {
93
+ url: string;
94
+ };
95
+ };
96
+ }>;
97
+ export declare function getSchoolById(schoolId: string): import(".prisma/client").Prisma.Prisma__SchoolClient<{
98
+ name: string;
99
+ id: string;
100
+ logoId: string | null;
101
+ subdomain: string | null;
102
+ createdAt: Date;
103
+ updatedAt: Date;
104
+ } | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
105
+ datasources: {
106
+ db: {
107
+ url: string;
108
+ };
109
+ };
110
+ }>;
111
+ export declare function getSchoolOverview(schoolId: string): import(".prisma/client").Prisma.Prisma__SchoolClient<{
112
+ name: string;
113
+ id: string;
114
+ subdomain: string | null;
115
+ _count: {
116
+ memberships: number;
117
+ invites: number;
118
+ classes: number;
119
+ };
120
+ memberships: {
121
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
122
+ }[];
123
+ invites: {
124
+ id: string;
125
+ createdAt: Date;
126
+ email: string;
127
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
128
+ expiresAt: Date;
129
+ }[];
130
+ classes: {
131
+ name: string;
132
+ id: string;
133
+ subject: string;
134
+ color: string | null;
135
+ section: string;
136
+ _count: {
137
+ teachers: number;
138
+ students: number;
139
+ };
140
+ }[];
141
+ } | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
142
+ datasources: {
143
+ db: {
144
+ url: string;
145
+ };
146
+ };
147
+ }>;
148
+ export declare function listSchoolClasses(schoolId: string): import(".prisma/client").Prisma.PrismaPromise<({
149
+ _count: {
150
+ assignments: number;
151
+ teachers: number;
152
+ students: number;
153
+ };
154
+ teachers: {
155
+ id: string;
156
+ username: string;
157
+ profile: {
158
+ displayName: string | null;
159
+ profilePicture: string | null;
160
+ profilePictureThumbnail: string | null;
161
+ } | null;
162
+ }[];
163
+ students: {
164
+ id: string;
165
+ }[];
166
+ } & {
167
+ name: string;
168
+ id: string;
169
+ schoolId: string | null;
170
+ subject: string;
171
+ color: string | null;
172
+ section: string;
173
+ syllabus: string | null;
174
+ })[]>;
175
+ export declare function listSchoolMembers(schoolId: string): import(".prisma/client").Prisma.PrismaPromise<{
176
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
177
+ id: string;
178
+ createdAt: Date;
179
+ updatedAt: Date;
180
+ user: {
181
+ id: string;
182
+ username: string;
183
+ email: string;
184
+ profile: {
185
+ displayName: string | null;
186
+ profilePicture: string | null;
187
+ profilePictureThumbnail: string | null;
188
+ } | null;
189
+ };
190
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
191
+ }[]>;
192
+ export declare function countActiveAdmins(schoolId: string): import(".prisma/client").Prisma.PrismaPromise<number>;
193
+ export declare function upsertSchoolMembership(data: {
194
+ schoolId: string;
195
+ userId: string;
196
+ role: SchoolMembershipRole;
197
+ }): import(".prisma/client").Prisma.Prisma__SchoolMembershipClient<{
198
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
199
+ id: string;
200
+ createdAt: Date;
201
+ updatedAt: Date;
202
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
203
+ schoolId: string;
204
+ userId: string;
205
+ }, never, import("@prisma/client/runtime/library.js").DefaultArgs, {
206
+ datasources: {
207
+ db: {
208
+ url: string;
209
+ };
210
+ };
211
+ }>;
212
+ export declare function updateSchoolMembershipRole(schoolId: string, userId: string, role: SchoolMembershipRole): import(".prisma/client").Prisma.Prisma__SchoolMembershipClient<{
213
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
214
+ id: string;
215
+ createdAt: Date;
216
+ updatedAt: Date;
217
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
218
+ schoolId: string;
219
+ userId: string;
220
+ }, never, import("@prisma/client/runtime/library.js").DefaultArgs, {
221
+ datasources: {
222
+ db: {
223
+ url: string;
224
+ };
225
+ };
226
+ }>;
227
+ export declare function removeSchoolMembershipPreservingContent(schoolId: string, userId: string): Promise<{
228
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
229
+ id: string;
230
+ createdAt: Date;
231
+ updatedAt: Date;
232
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
233
+ schoolId: string;
234
+ userId: string;
235
+ }>;
236
+ export declare function findUserByEmailForSchool(email: string): import(".prisma/client").Prisma.Prisma__UserClient<{
237
+ id: string;
238
+ username: string;
239
+ email: string;
240
+ } | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
241
+ datasources: {
242
+ db: {
243
+ url: string;
244
+ };
245
+ };
246
+ }>;
247
+ export declare function findUserByIdForSchool(userId: string): import(".prisma/client").Prisma.Prisma__UserClient<{
248
+ id: string;
249
+ username: string;
250
+ email: string;
251
+ } | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
252
+ datasources: {
253
+ db: {
254
+ url: string;
255
+ };
256
+ };
257
+ }>;
258
+ export declare function createSchoolInvite(data: {
259
+ schoolId: string;
260
+ invitedById: string;
261
+ email: string;
262
+ role: SchoolMembershipRole;
263
+ token: string;
264
+ expiresAt: Date;
265
+ }): import(".prisma/client").Prisma.Prisma__SchoolInviteClient<{
266
+ school: {
267
+ name: string;
268
+ id: string;
269
+ };
270
+ } & {
271
+ status: import(".prisma/client").$Enums.SchoolInviteStatus;
272
+ id: string;
273
+ createdAt: Date;
274
+ updatedAt: Date;
275
+ email: string;
276
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
277
+ schoolId: string;
278
+ token: string;
279
+ expiresAt: Date;
280
+ acceptedAt: Date | null;
281
+ revokedAt: Date | null;
282
+ invitedById: string;
283
+ }, never, import("@prisma/client/runtime/library.js").DefaultArgs, {
284
+ datasources: {
285
+ db: {
286
+ url: string;
287
+ };
288
+ };
289
+ }>;
290
+ export declare function listSchoolInvites(schoolId: string): import(".prisma/client").Prisma.PrismaPromise<{
291
+ status: import(".prisma/client").$Enums.SchoolInviteStatus;
292
+ id: string;
293
+ createdAt: Date;
294
+ email: string;
295
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
296
+ expiresAt: Date;
297
+ acceptedAt: Date | null;
298
+ revokedAt: Date | null;
299
+ invitedBy: {
300
+ id: string;
301
+ username: string;
302
+ profile: {
303
+ displayName: string | null;
304
+ } | null;
305
+ };
306
+ }[]>;
307
+ export declare function revokeSchoolInvite(inviteId: string, schoolId: string): import(".prisma/client").Prisma.Prisma__SchoolInviteClient<{
308
+ status: import(".prisma/client").$Enums.SchoolInviteStatus;
309
+ id: string;
310
+ createdAt: Date;
311
+ updatedAt: Date;
312
+ email: string;
313
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
314
+ schoolId: string;
315
+ token: string;
316
+ expiresAt: Date;
317
+ acceptedAt: Date | null;
318
+ revokedAt: Date | null;
319
+ invitedById: string;
320
+ }, never, import("@prisma/client/runtime/library.js").DefaultArgs, {
321
+ datasources: {
322
+ db: {
323
+ url: string;
324
+ };
325
+ };
326
+ }>;
327
+ export declare function findPendingInviteByToken(token: string): import(".prisma/client").Prisma.Prisma__SchoolInviteClient<({
328
+ school: {
329
+ name: string;
330
+ id: string;
331
+ };
332
+ } & {
333
+ status: import(".prisma/client").$Enums.SchoolInviteStatus;
334
+ id: string;
335
+ createdAt: Date;
336
+ updatedAt: Date;
337
+ email: string;
338
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
339
+ schoolId: string;
340
+ token: string;
341
+ expiresAt: Date;
342
+ acceptedAt: Date | null;
343
+ revokedAt: Date | null;
344
+ invitedById: string;
345
+ }) | null, null, import("@prisma/client/runtime/library.js").DefaultArgs, {
346
+ datasources: {
347
+ db: {
348
+ url: string;
349
+ };
350
+ };
351
+ }>;
352
+ export declare function acceptSchoolInvite(inviteId: string, userId: string): Promise<{
353
+ status: import(".prisma/client").$Enums.SchoolMembershipStatus;
354
+ id: string;
355
+ createdAt: Date;
356
+ updatedAt: Date;
357
+ role: import(".prisma/client").$Enums.SchoolMembershipRole;
358
+ schoolId: string;
359
+ userId: string;
360
+ }>;
361
+ //# sourceMappingURL=school.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"school.d.ts","sourceRoot":"/","sources":["models/school.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAyBtD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;GAIpE;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;GAI1E;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;GAI/E;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;;MAiBvD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;;;;;;;;;;;;;;;;;;;;;;;GAoBA;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;GAY7C;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CjD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;MAsBjD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;KAMjD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,yDAIjD;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,oBAAoB,CAAC;CAC5B;;;;;;;;;;;;;;GAmBA;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,oBAAoB;;;;;;;;;;;;;;GAM3B;AAED,wBAAgB,uCAAuC,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;GAsBvF;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;GAKrD;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;GAKnD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,oBAAoB,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;CACjB;;;;;;;;;;;;;;;;;;;;;;;;GAOA;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;KAsBjD;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;;GAQpE;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;GAKrD;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;GAuClE"}
@@ -0,0 +1,314 @@
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]="2d7f12f2-3eee-5f9e-a7b4-25e65d32bd05")}catch(e){}}();
3
+ import { prisma } from "../lib/prisma.js";
4
+ const memberSelect = {
5
+ id: true,
6
+ role: true,
7
+ status: true,
8
+ createdAt: true,
9
+ updatedAt: true,
10
+ user: {
11
+ select: {
12
+ id: true,
13
+ username: true,
14
+ email: true,
15
+ profile: {
16
+ select: {
17
+ displayName: true,
18
+ profilePicture: true,
19
+ profilePictureThumbnail: true,
20
+ },
21
+ },
22
+ },
23
+ },
24
+ };
25
+ export function findSchoolMembership(schoolId, userId) {
26
+ return prisma.schoolMembership.findUnique({
27
+ where: { schoolId_userId: { schoolId, userId } },
28
+ });
29
+ }
30
+ export function findActiveSchoolMembership(schoolId, userId) {
31
+ return prisma.schoolMembership.findFirst({
32
+ where: { schoolId, userId, status: "ACTIVE" },
33
+ });
34
+ }
35
+ export function findActiveSchoolAdminMembership(schoolId, userId) {
36
+ return prisma.schoolMembership.findFirst({
37
+ where: { schoolId, userId, role: "ADMIN", status: "ACTIVE" },
38
+ });
39
+ }
40
+ export function listUserSchoolMemberships(userId) {
41
+ return prisma.schoolMembership.findMany({
42
+ where: { userId, status: "ACTIVE" },
43
+ include: {
44
+ school: {
45
+ select: {
46
+ id: true,
47
+ name: true,
48
+ subdomain: true,
49
+ logoId: true,
50
+ createdAt: true,
51
+ updatedAt: true,
52
+ },
53
+ },
54
+ },
55
+ orderBy: { createdAt: "asc" },
56
+ });
57
+ }
58
+ export function createSchoolWithAdmin(data) {
59
+ return prisma.school.create({
60
+ data: {
61
+ name: data.name,
62
+ subdomain: data.subdomain,
63
+ logoId: data.logoId,
64
+ memberships: {
65
+ create: {
66
+ userId: data.userId,
67
+ role: "ADMIN",
68
+ status: "ACTIVE",
69
+ },
70
+ },
71
+ },
72
+ include: {
73
+ memberships: {
74
+ where: { userId: data.userId },
75
+ },
76
+ },
77
+ });
78
+ }
79
+ export function getSchoolById(schoolId) {
80
+ return prisma.school.findUnique({
81
+ where: { id: schoolId },
82
+ select: {
83
+ id: true,
84
+ name: true,
85
+ subdomain: true,
86
+ logoId: true,
87
+ createdAt: true,
88
+ updatedAt: true,
89
+ },
90
+ });
91
+ }
92
+ export function getSchoolOverview(schoolId) {
93
+ return prisma.school.findUnique({
94
+ where: { id: schoolId },
95
+ select: {
96
+ id: true,
97
+ name: true,
98
+ subdomain: true,
99
+ _count: {
100
+ select: {
101
+ classes: true,
102
+ memberships: { where: { status: "ACTIVE" } },
103
+ invites: { where: { status: "PENDING" } },
104
+ },
105
+ },
106
+ memberships: {
107
+ where: { status: "ACTIVE" },
108
+ select: { role: true },
109
+ },
110
+ classes: {
111
+ orderBy: { name: "asc" },
112
+ take: 5,
113
+ select: {
114
+ id: true,
115
+ name: true,
116
+ subject: true,
117
+ section: true,
118
+ color: true,
119
+ _count: { select: { teachers: true, students: true } },
120
+ },
121
+ },
122
+ invites: {
123
+ where: { status: "PENDING" },
124
+ orderBy: { createdAt: "desc" },
125
+ take: 5,
126
+ select: {
127
+ id: true,
128
+ email: true,
129
+ role: true,
130
+ expiresAt: true,
131
+ createdAt: true,
132
+ },
133
+ },
134
+ },
135
+ });
136
+ }
137
+ export function listSchoolClasses(schoolId) {
138
+ return prisma.class.findMany({
139
+ where: { schoolId },
140
+ orderBy: [{ name: "asc" }, { section: "asc" }],
141
+ include: {
142
+ teachers: {
143
+ select: {
144
+ id: true,
145
+ username: true,
146
+ profile: {
147
+ select: {
148
+ displayName: true,
149
+ profilePicture: true,
150
+ profilePictureThumbnail: true,
151
+ },
152
+ },
153
+ },
154
+ },
155
+ students: { select: { id: true } },
156
+ _count: { select: { teachers: true, students: true, assignments: true } },
157
+ },
158
+ });
159
+ }
160
+ export function listSchoolMembers(schoolId) {
161
+ return prisma.schoolMembership.findMany({
162
+ where: { schoolId },
163
+ select: memberSelect,
164
+ orderBy: [{ role: "asc" }, { createdAt: "asc" }],
165
+ });
166
+ }
167
+ export function countActiveAdmins(schoolId) {
168
+ return prisma.schoolMembership.count({
169
+ where: { schoolId, role: "ADMIN", status: "ACTIVE" },
170
+ });
171
+ }
172
+ export function upsertSchoolMembership(data) {
173
+ return prisma.schoolMembership.upsert({
174
+ where: {
175
+ schoolId_userId: {
176
+ schoolId: data.schoolId,
177
+ userId: data.userId,
178
+ },
179
+ },
180
+ update: {
181
+ role: data.role,
182
+ status: "ACTIVE",
183
+ },
184
+ create: {
185
+ schoolId: data.schoolId,
186
+ userId: data.userId,
187
+ role: data.role,
188
+ status: "ACTIVE",
189
+ },
190
+ });
191
+ }
192
+ export function updateSchoolMembershipRole(schoolId, userId, role) {
193
+ return prisma.schoolMembership.update({
194
+ where: { schoolId_userId: { schoolId, userId } },
195
+ data: { role },
196
+ });
197
+ }
198
+ export function removeSchoolMembershipPreservingContent(schoolId, userId) {
199
+ return prisma.$transaction(async (tx) => {
200
+ const classes = await tx.class.findMany({
201
+ where: { schoolId },
202
+ select: { id: true },
203
+ });
204
+ const classIds = classes.map((cls) => ({ id: cls.id }));
205
+ for (const classWhere of classIds) {
206
+ await tx.class.update({
207
+ where: classWhere,
208
+ data: {
209
+ teachers: { disconnect: { id: userId } },
210
+ students: { disconnect: { id: userId } },
211
+ },
212
+ });
213
+ }
214
+ return tx.schoolMembership.delete({
215
+ where: { schoolId_userId: { schoolId, userId } },
216
+ });
217
+ });
218
+ }
219
+ export function findUserByEmailForSchool(email) {
220
+ return prisma.user.findFirst({
221
+ where: { email },
222
+ select: { id: true, email: true, username: true },
223
+ });
224
+ }
225
+ export function findUserByIdForSchool(userId) {
226
+ return prisma.user.findUnique({
227
+ where: { id: userId },
228
+ select: { id: true, email: true, username: true },
229
+ });
230
+ }
231
+ export function createSchoolInvite(data) {
232
+ return prisma.schoolInvite.create({
233
+ data,
234
+ include: {
235
+ school: { select: { id: true, name: true } },
236
+ },
237
+ });
238
+ }
239
+ export function listSchoolInvites(schoolId) {
240
+ return prisma.schoolInvite.findMany({
241
+ where: { schoolId },
242
+ orderBy: { createdAt: "desc" },
243
+ select: {
244
+ id: true,
245
+ email: true,
246
+ role: true,
247
+ status: true,
248
+ expiresAt: true,
249
+ acceptedAt: true,
250
+ revokedAt: true,
251
+ createdAt: true,
252
+ invitedBy: {
253
+ select: {
254
+ id: true,
255
+ username: true,
256
+ profile: { select: { displayName: true } },
257
+ },
258
+ },
259
+ },
260
+ });
261
+ }
262
+ export function revokeSchoolInvite(inviteId, schoolId) {
263
+ return prisma.schoolInvite.update({
264
+ where: { id: inviteId, schoolId },
265
+ data: {
266
+ status: "REVOKED",
267
+ revokedAt: new Date(),
268
+ },
269
+ });
270
+ }
271
+ export function findPendingInviteByToken(token) {
272
+ return prisma.schoolInvite.findUnique({
273
+ where: { token },
274
+ include: { school: { select: { id: true, name: true } } },
275
+ });
276
+ }
277
+ export function acceptSchoolInvite(inviteId, userId) {
278
+ return prisma.$transaction(async (tx) => {
279
+ const invite = await tx.schoolInvite.findUnique({
280
+ where: { id: inviteId },
281
+ });
282
+ if (!invite) {
283
+ throw new Error("Invite not found");
284
+ }
285
+ const membership = await tx.schoolMembership.upsert({
286
+ where: {
287
+ schoolId_userId: {
288
+ schoolId: invite.schoolId,
289
+ userId,
290
+ },
291
+ },
292
+ update: {
293
+ role: invite.role,
294
+ status: "ACTIVE",
295
+ },
296
+ create: {
297
+ schoolId: invite.schoolId,
298
+ userId,
299
+ role: invite.role,
300
+ status: "ACTIVE",
301
+ },
302
+ });
303
+ await tx.schoolInvite.update({
304
+ where: { id: inviteId },
305
+ data: {
306
+ status: "ACCEPTED",
307
+ acceptedAt: new Date(),
308
+ },
309
+ });
310
+ return membership;
311
+ });
312
+ }
313
+ //# sourceMappingURL=school.js.map
314
+ //# debugId=2d7f12f2-3eee-5f9e-a7b4-25e65d32bd05