placementt-core 11.0.803 → 11.0.914

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.
@@ -146,8 +146,8 @@ const instituteTips = {
146
146
  // Accept a cohort to any task
147
147
  const instituteTasks = {
148
148
  invalidStaffEmails: {
149
- callback: async (user, organisation, cohort) => {
150
- if (!(0, util_1.getAccess)(user, "viewStaff") || !Array.isArray(cohort))
149
+ callback: async ({ user, cohorts }) => {
150
+ if (!(0, util_1.getAccess)(user, "viewStaff") || !Array.isArray(cohorts))
151
151
  return;
152
152
  const staffCount = (await firebaseQuery.getCount(["users"], [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("userType", "==", "Staff"), (0, firestore_1.where)("flags", "array-contains", "userEmailFailed")]));
153
153
  if (staffCount > 0) {
@@ -156,14 +156,63 @@ const instituteTasks = {
156
156
  severity: "error",
157
157
  title: `${staffCount} staff have invalid emails.`,
158
158
  message: `${staffCount} staff accounts have invalid email addresses. Delete and reupload these users.`,
159
- link: "/institutes/cohorts/staff/all",
159
+ link: "/institutes/organisation/staff/all",
160
160
  };
161
161
  }
162
162
  return;
163
163
  },
164
164
  },
165
+ approveAlumniConversation: {
166
+ callback: async ({ user, organisation, schools }) => {
167
+ if (!schools) {
168
+ if (!organisation.alumniConversations)
169
+ return;
170
+ const convos = (await firebaseQuery.getCount(["alumniConversations"], [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("open", "==", true), (0, firestore_1.where)("delivered", "==", "pending")]));
171
+ if (convos > 0) {
172
+ return {
173
+ dismissible: false,
174
+ severity: "info",
175
+ title: `${convos} alumni conversation message${convos > 1 ? "s" : ""} needs approval.`,
176
+ message: `There are ${convos} message${convos > 1 ? "s" : ""} to alumni for you to review and release.`,
177
+ link: "/institutes/network/alumni/conversations",
178
+ };
179
+ }
180
+ return;
181
+ }
182
+ if (!Array.isArray(schools)) {
183
+ // One school
184
+ const convos = (await firebaseQuery.getCount(["alumniConversations"], [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("schoolId", "==", schools.id), (0, firestore_1.where)("open", "==", true), (0, firestore_1.where)("delivered", "==", "pending")]));
185
+ if (convos > 0) {
186
+ return {
187
+ dismissible: false,
188
+ severity: "info",
189
+ title: `${convos} alumni conversation message${convos > 1 ? "s" : ""} needs approval.`,
190
+ message: `There are ${convos} message${convos > 1 ? "s" : ""} to alumni for you to review and release.`,
191
+ link: `/institutes/network/alumni/conversations/${schools.id}`,
192
+ };
193
+ }
194
+ return;
195
+ }
196
+ const items = await Promise.all(schools.map(async ([id, school]) => {
197
+ if (!school.alumniConversations)
198
+ return;
199
+ const convos = (await firebaseQuery.getCount(["alumniConversations"], [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("schoolId", "==", id), (0, firestore_1.where)("open", "==", true), (0, firestore_1.where)("delivered", "==", "pending")]));
200
+ if (convos > 0) {
201
+ return {
202
+ dismissible: false,
203
+ severity: "info",
204
+ title: `${convos} alumni conversation message${convos > 1 ? "s" : ""} needs approval.`,
205
+ message: `${school.name}, has ${convos} outstanding alumni message${convos > 1 ? "s" : ""} to approve. Click to view.`,
206
+ link: `/institutes/network/alumni/conversations/${school.id}`,
207
+ };
208
+ }
209
+ return;
210
+ }));
211
+ return items.filter((v) => v);
212
+ },
213
+ },
165
214
  invalidStudentEmails: {
166
- callback: async (user, organisation, cohorts) => {
215
+ callback: async ({ user, cohorts }) => {
167
216
  if (!(0, util_1.getAccess)(user, "viewStudents") || user.viewStudents === "none")
168
217
  return;
169
218
  if (!Array.isArray(cohorts)) {
@@ -196,7 +245,7 @@ const instituteTasks = {
196
245
  },
197
246
  },
198
247
  outstandingReminders: {
199
- callback: async (user, organisation, cohorts) => {
248
+ callback: async ({ user, cohorts }) => {
200
249
  if (!Array.isArray(cohorts)) {
201
250
  const reminderCount = (await firebaseQuery.getCount(["reminders"], [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("uid", "==", user.id), (0, firestore_1.where)("dueDate", "<=", (0, util_2.convertDate)(new Date(), "dbstring")), (0, firestore_1.where)("cohort", "==", cohorts.id), (0, firestore_1.where)("status", "==", "upcoming")]));
202
251
  if (reminderCount > 0) {
@@ -227,7 +276,7 @@ const instituteTasks = {
227
276
  },
228
277
  },
229
278
  invalidParentEmails: {
230
- callback: async (user, _, cohorts) => {
279
+ callback: async ({ user, cohorts }) => {
231
280
  if (!(0, util_1.getAccess)(user, "signOffPlacements") || user.viewStudents === "none")
232
281
  return;
233
282
  if (!Array.isArray(cohorts)) {
@@ -261,7 +310,7 @@ const instituteTasks = {
261
310
  },
262
311
  },
263
312
  invalidProviderEmails: {
264
- callback: async (user, organisation, cohorts) => {
313
+ callback: async ({ user, cohorts }) => {
265
314
  if (!(0, util_1.getAccess)(user, "signOffPlacements") || user.viewStudents === "none")
266
315
  return;
267
316
  if (!Array.isArray(cohorts)) {
@@ -295,7 +344,7 @@ const instituteTasks = {
295
344
  },
296
345
  },
297
346
  requiredStage: {
298
- callback: async (user, _, cohorts) => {
347
+ callback: async ({ user, cohorts }) => {
299
348
  if (!(0, util_1.getAccess)(user, "signOffPlacements") || user.viewStudents === "none")
300
349
  return;
301
350
  if (!Array.isArray(cohorts)) {
@@ -329,7 +378,7 @@ const instituteTasks = {
329
378
  },
330
379
  },
331
380
  verifyInsurance: {
332
- callback: async (user, _, cohorts) => {
381
+ callback: async ({ user, cohorts }) => {
333
382
  if (!(0, util_1.getAccess)(user, "verifyInsurance") || user.viewStudents === "none")
334
383
  return;
335
384
  if (!Array.isArray(cohorts)) {
@@ -363,7 +412,7 @@ const instituteTasks = {
363
412
  },
364
413
  },
365
414
  verifyDbsCheck: {
366
- callback: async (user, _, cohorts) => {
415
+ callback: async ({ user, cohorts }) => {
367
416
  if (!(0, util_1.getAccess)(user, "verifyDbsChecks") || user.viewStudents === "none")
368
417
  return;
369
418
  if (!Array.isArray(cohorts)) {
@@ -397,7 +446,7 @@ const instituteTasks = {
397
446
  },
398
447
  },
399
448
  verifyRiskAssessment: {
400
- callback: async (user, _, cohorts) => {
449
+ callback: async ({ user, cohorts }) => {
401
450
  if (!(0, util_1.getAccess)(user, "verifyRiskAssessments") || user.viewStudents === "none")
402
451
  return;
403
452
  if (!Array.isArray(cohorts)) {
@@ -431,7 +480,7 @@ const instituteTasks = {
431
480
  },
432
481
  },
433
482
  missingParentEmail: {
434
- callback: async (user, _, cohorts) => {
483
+ callback: async ({ user, cohorts }) => {
435
484
  var _a, _b, _c;
436
485
  if (!(0, util_1.getAccess)(user, "editStudents") || user.viewStudents === "none")
437
486
  return;
@@ -481,7 +530,7 @@ const instituteTasks = {
481
530
  },
482
531
  },
483
532
  inactiveStudents: {
484
- callback: async (user, _, cohorts) => {
533
+ callback: async ({ user, cohorts }) => {
485
534
  var _a, _b, _c;
486
535
  if (!(0, util_1.getAccess)(user, "activateStudents") || user.viewStudents === "none")
487
536
  return;
@@ -525,7 +574,7 @@ const instituteTasks = {
525
574
  },
526
575
  },
527
576
  uploadStudents: {
528
- callback: async (user, _, cohorts) => {
577
+ callback: async ({ user, cohorts }) => {
529
578
  if (!Array.isArray(cohorts))
530
579
  return;
531
580
  if (!(0, util_1.getAccess)(user, "addStudents") || user.viewStudents === "none")
@@ -554,7 +603,7 @@ const instituteTasks = {
554
603
  },
555
604
  },
556
605
  inactiveStaff: {
557
- callback: async (user, _, cohorts) => {
606
+ callback: async ({ user, cohorts }) => {
558
607
  if (!(0, util_1.getAccess)(user, "addStaff"))
559
608
  return;
560
609
  if (!Array.isArray(cohorts) || user.product === "students")
@@ -576,16 +625,16 @@ const instituteTasks = {
576
625
  },
577
626
  },
578
627
  overdueStage: {
579
- callback: async (user, _, cohort) => {
580
- console.log(user, cohort);
628
+ callback: async ({ user, cohorts }) => {
629
+ console.log(user, cohorts);
581
630
  return undefined;
582
631
  },
583
632
  },
584
633
  approveExternalPlacement: {
585
- callback: async (user, _, cohort) => {
634
+ callback: async ({ user, cohorts }) => {
586
635
  if (!(0, util_1.getAccess)(user, "verifyListings"))
587
636
  return;
588
- if (!Array.isArray(cohort))
637
+ if (!Array.isArray(cohorts))
589
638
  return;
590
639
  const externalCount = await firebaseQuery.getCount(["placementListings"], [(0, firestore_1.where)(`savedBy.${user.oId}.exists`, "==", true), (0, firestore_1.where)(`savedBy.${user.oId}.status`, "==", "uploaded"), (0, firestore_1.where)("mapConsent", "==", "institute")]);
591
640
  console.log("EXT", externalCount);
@@ -621,411 +670,363 @@ const studentTasks = {
621
670
  },
622
671
  }
623
672
  };
624
- const providerTasks = {
625
- requestedVisibleAddresses: {
626
- callback: async (user) => {
627
- if (!(0, util_1.getAccess)(user, "addStaff"))
628
- return;
629
- const accessRequests = await firebaseQuery.getCount("users", [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("product", "==", "providers"), (0, firestore_1.orderBy)("requestedVisibleAddresses")]) - ((Array.isArray(user === null || user === void 0 ? void 0 : user.requestedVisibleAddresses) && (user === null || user === void 0 ? void 0 : user.requestedVisibleAddresses.length) > 0) ? 1 : 0);
630
- if (accessRequests === 0)
631
- return;
632
- if (accessRequests === 1) {
633
- const userRequestingAccess = Object.entries(await firebaseQuery.getDocsWhere("users", [(0, firestore_1.where)("product", "==", "providers"), (0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.orderBy)("requestedVisibleAddresses")]) || {})[0];
634
- return {
635
- dismissible: false,
636
- severity: "primary",
637
- title: `${userRequestingAccess[1].details.forename} ${userRequestingAccess[1].details.surname} has requested access to view addresses.`,
638
- message: `Click to review the addresses and grant access to the user.`,
639
- link: `/${user.product}/users/${userRequestingAccess[0]}`,
640
- buttonTitle: "View request",
641
- };
642
- }
643
- return {
644
- dismissible: false,
645
- severity: "warning",
646
- title: `Multiple users have requested access to view addresses.`,
647
- message: `Click to review the addresses and grant access to the user.`,
648
- link: `/${user.product}/organisation/staff/all`,
649
- buttonTitle: "View request",
650
- };
651
- },
652
- },
653
- requestedVisiblePlacementListings: {
654
- callback: async (user) => {
655
- if (!(0, util_1.getAccess)(user, "addStaff"))
656
- return;
657
- const accessRequests = await firebaseQuery.getCount("users", [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("product", "==", "providers"), (0, firestore_1.orderBy)("requestedVisibleListings")]) - ((Array.isArray(user === null || user === void 0 ? void 0 : user.requestedVisibleListings) && (user === null || user === void 0 ? void 0 : user.requestedVisibleListings.length) > 0) ? 1 : 0);
658
- ;
659
- if (accessRequests === 0)
660
- return;
661
- if (accessRequests === 1) {
662
- const userRequestingAccess = Object.entries(await firebaseQuery.getDocsWhere("users", [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("product", "==", "providers"), (0, firestore_1.orderBy)("requestedVisibleListings")]) || {})[0];
663
- return {
664
- dismissible: false,
665
- severity: "primary",
666
- title: `${userRequestingAccess[1].details.forename} ${userRequestingAccess[1].details.surname} has requested access to view placement listings.`,
667
- message: `Click to review the placement listings and grant access to the user.`,
668
- link: `/${user.product}/users/${userRequestingAccess[0]}`,
669
- buttonTitle: "View request",
670
- };
671
- }
672
- return {
673
- dismissible: false,
674
- severity: "warning",
675
- title: `Multiple users have requested access to view placement listings.`,
676
- message: `Click to review the placement listings and grant access to the user.`,
677
- link: `/${user.product}/organisation/staff/all`,
678
- buttonTitle: "View request",
679
- };
680
- },
681
- },
682
- applicationRequireReview: {
683
- callback: async (user) => {
684
- var _a, _b;
685
- const constraints = [(0, firestore_1.where)("providerId", "==", user.oId), (0, firestore_1.where)("reqUserType", "==", "Staff"), (0, firestore_1.where)("status", "==", "submitted")];
686
- if (user.userGroup !== "admin") {
687
- if (!user.viewPlacementListings || user.viewPlacementListings === "none")
688
- return;
689
- if (!user.viewAddresses || user.viewAddresses === "none")
690
- return;
691
- if (user.viewPlacementListings === "request") {
692
- if (!user.visibleListings || ((_a = user.visibleListings) === null || _a === void 0 ? void 0 : _a.length) === 0)
693
- return;
694
- constraints.push((0, firestore_1.where)("listingId", 'in', user.visibleListings));
695
- }
696
- else {
697
- // viewPlacementListings must be 'all'
698
- if (user.viewAddresses === "request") {
699
- if (!user.visibleAddresses || ((_b = user.visibleAddresses) === null || _b === void 0 ? void 0 : _b.length) === 0)
700
- return;
701
- constraints.push((0, firestore_1.where)("addressId", 'in', user.visibleAddresses));
702
- }
703
- }
704
- }
705
- const applicationCount = await firebaseQuery.getCount("applications", constraints);
706
- if (applicationCount === 0)
707
- return;
708
- return {
709
- dismissible: false,
710
- severity: "primary",
711
- title: `${applicationCount} applications require your review.`,
712
- message: `Click to view ${applicationCount} that require your attention.`,
713
- link: `/${user.product}/placementListings/applicants`,
714
- buttonTitle: "View applications",
715
- };
716
- },
717
- },
718
- completeStudentDocs: {
719
- callback: async (user) => {
720
- return;
721
- return {};
722
- },
723
- },
724
- reviewOnboarding: {
725
- callback: async (user) => {
726
- var _a, _b;
727
- const constraints = [(0, firestore_1.where)("providerId", "==", user.oId), (0, firestore_1.where)("onboarding.completed.accepted", "==", false), (0, firestore_1.where)("onboarding.completed.submitted", "==", true), (0, firestore_1.where)("endDate", ">=", (0, util_1.dateToString)(new Date()))];
728
- if (user.userGroup !== "admin") {
729
- if (!user.viewPlacementListings || user.viewPlacementListings === "none")
730
- return;
731
- if (!user.viewAddresses || user.viewAddresses === "none")
732
- return;
733
- if (user.viewPlacementListings === "request") {
734
- if (!user.visibleListings || ((_a = user.visibleListings) === null || _a === void 0 ? void 0 : _a.length) === 0)
735
- return;
736
- constraints.push((0, firestore_1.where)("placementId", 'in', user.visibleListings));
737
- }
738
- else {
739
- // viewPlacementListings must be 'all'
740
- if (user.viewAddresses === "request") {
741
- if (!user.visibleAddresses || ((_b = user.visibleAddresses) === null || _b === void 0 ? void 0 : _b.length) === 0)
742
- return;
743
- constraints.push((0, firestore_1.where)("addressId", 'in', user.visibleAddresses));
744
- }
745
- }
746
- }
747
- const toReview = await firebaseQuery.getCount("placements", constraints);
748
- if (toReview === 0)
749
- return;
750
- if (toReview === 1) {
751
- const placement = Object.entries(await firebaseQuery.getDocsWhere("placements", constraints) || {})[0];
752
- const student = await firebaseQuery.getDocData(["users", placement[1].uid]);
753
- return {
754
- dismissible: false,
755
- severity: "primary",
756
- title: `${student.details.forename} ${student.details.surname} has completed their onboarding for their placement from ${(0, util_2.convertDate)(placement[1].startDate, "visual")} to ${(0, util_2.convertDate)(placement[1].endDate, "visual")}`,
757
- message: `Click to view the placement and review the onboarding.`,
758
- link: `/${user.product}/placements/${placement[0]}`,
759
- buttonTitle: "View",
760
- };
761
- }
762
- return {
763
- dismissible: false,
764
- severity: "primary",
765
- title: `${toReview} student have completed their onboarding.`,
766
- message: `Click to view your placements and approve completed onboarding`,
767
- link: `/${user.product}/placementListings/placements`,
768
- buttonTitle: "View placements",
769
- };
770
- },
771
- },
772
- uploadOnboarding: {
773
- callback: async (user) => {
774
- var _a, _b;
775
- const constraints = [(0, firestore_1.where)("providerId", "==", user.oId), (0, firestore_1.where)("onboarding", "==", null), (0, firestore_1.where)("endDate", ">=", (0, util_1.dateToString)(new Date()))];
776
- if (user.userGroup !== "admin") {
777
- if (!user.viewPlacementListings || user.viewPlacementListings === "none")
778
- return;
779
- if (!user.viewAddresses || user.viewAddresses === "none")
780
- return;
781
- if (user.viewPlacementListings === "request") {
782
- if (!user.visibleListings || ((_a = user.visibleListings) === null || _a === void 0 ? void 0 : _a.length) === 0)
783
- return;
784
- constraints.push((0, firestore_1.where)("placementId", 'in', user.visibleListings));
785
- }
786
- else {
787
- // viewPlacementListings must be 'all'
788
- if (user.viewAddresses === "request") {
789
- if (!user.visibleAddresses || ((_b = user.visibleAddresses) === null || _b === void 0 ? void 0 : _b.length) === 0)
790
- return;
791
- constraints.push((0, firestore_1.where)("addressId", 'in', user.visibleAddresses));
792
- }
793
- }
794
- }
795
- const withoutOnboarding = await firebaseQuery.getCount("placements", constraints);
796
- if (withoutOnboarding === 0)
797
- return;
798
- if (withoutOnboarding === 1) {
799
- const placement = Object.entries(await firebaseQuery.getDocsWhere("placements", constraints) || {})[0];
800
- const student = await firebaseQuery.getDocData(["users", placement[1].uid]);
801
- return {
802
- dismissible: false,
803
- severity: "primary",
804
- title: `Send onboarding documents to ${student.details.forename} ${student.details.surname}'s placement from ${(0, util_2.convertDate)(placement[1].startDate, "visual")} to ${(0, util_2.convertDate)(placement[1].endDate, "visual")}`,
805
- message: `Click to view the placement and add or dismiss onboarding reminders.`,
806
- link: `/${user.product}/placements/${placement[0]}`,
807
- buttonTitle: "View",
808
- };
809
- }
810
- return {
811
- dismissible: false,
812
- severity: "primary",
813
- title: `Set up onboarding for ${withoutOnboarding} placements to prepare yourself and your students.`,
814
- message: `Click to view your placements and add or dismiss onboarding reminders.`,
815
- link: `/${user.product}/placementListings/placements`,
816
- buttonTitle: "View placements",
817
- };
818
- },
819
- },
820
- completeListing: {
821
- callback: async (user) => {
822
- var _a, _b;
823
- const constraints = [(0, firestore_1.where)("providerId", "==", user.oId), (0, firestore_1.where)("status", "==", "draft")];
824
- if (user.userGroup !== "admin") {
825
- if (!user.viewPlacementListings || user.viewPlacementListings === "none")
826
- return;
827
- if (!user.viewAddresses || user.viewAddresses === "none")
828
- return;
829
- if (user.viewPlacementListings === "request") {
830
- if (!user.visibleListings || ((_a = user.visibleListings) === null || _a === void 0 ? void 0 : _a.length) === 0)
831
- return;
832
- constraints.push((0, firestore_1.where)((0, firestore_1.documentId)(), 'in', user.visibleListings));
833
- }
834
- else {
835
- // viewPlacementListings must be 'all'
836
- if (user.viewAddresses === "request") {
837
- if (!user.visibleAddresses || ((_b = user.visibleAddresses) === null || _b === void 0 ? void 0 : _b.length) === 0)
838
- return;
839
- constraints.push((0, firestore_1.where)("addressId", 'in', user.visibleAddresses));
840
- }
841
- }
842
- }
843
- const incompleteListings = await firebaseQuery.getCount("placementListings", constraints);
844
- if (incompleteListings === 0)
845
- return;
846
- if (incompleteListings === 1) {
847
- const incompleteListing = Object.entries(await firebaseQuery.getDocsWhere("placementListings", constraints) || {})[0];
848
- const address = incompleteListing[1].addressId ? await firebaseQuery.getDocData(["addresses", incompleteListing[1].addressId]) : undefined;
849
- return {
850
- dismissible: false,
851
- severity: "info",
852
- title: `Your listing '${incompleteListing[1].title || "unnamed"}' at ${address ? `${address["address-line1"]}, ${address.postal_code.toUpperCase()}, ${(0, util_1.capitaliseWords)((0, util_1.camelCaseToNormal)(address.country))}` : "unknown address"} requires more information before publishing.`,
853
- message: `Click to complete and publish the placement listing.`,
854
- link: `/${user.product}/addListing/${incompleteListing[0]}`,
855
- buttonTitle: "View listing",
856
- };
857
- }
858
- return {
859
- dismissible: false,
860
- severity: "info",
861
- title: `You have ${incompleteListings} draft listings waiting to be published.`,
862
- message: `Click to review and publish the placement listings.`,
863
- link: `/${user.product}/placementListings/listings`,
864
- buttonTitle: "View listings",
865
- };
866
- },
867
- },
868
- completeAddress: {
869
- callback: async (user) => {
870
- var _a;
871
- const constraints = [(0, firestore_1.where)("product", "==", "providers"), (0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("stage", "!=", "complete")];
872
- if (user.userGroup !== "admin") {
873
- if (!user.viewAddresses || user.viewAddresses === "none")
874
- return;
875
- if (user.viewAddresses === "request") {
876
- if (!user.visibleAddresses || ((_a = user.visibleAddresses) === null || _a === void 0 ? void 0 : _a.length) === 0)
877
- return;
878
- constraints.push((0, firestore_1.where)("addressId", 'in', user.visibleAddresses));
879
- }
880
- }
881
- const incompleteAddresses = await firebaseQuery.getCount("addresses", constraints);
882
- if (incompleteAddresses === 0)
883
- return;
884
- if (incompleteAddresses === 1) {
885
- const address = Object.entries(await firebaseQuery.getDocsWhere("addresses", constraints) || {})[0];
886
- return {
887
- dismissible: false,
888
- severity: "info",
889
- title: `Your address: ${address[1]["address-line1"]}, ${address[1].postal_code.toUpperCase()}, ${(0, util_1.capitaliseWords)((0, util_1.camelCaseToNormal)(address[1].country))} is currently incomplete.`,
890
- message: `Click to complete the addresses.`,
891
- link: `/${user.product}/addAddress/${address[0]}`,
892
- buttonTitle: "View address",
893
- };
894
- }
895
- return {
896
- dismissible: false,
897
- severity: "info",
898
- title: `You have ${incompleteAddresses} draft addresses waiting to be published.`,
899
- message: `Click to review the addresses.`,
900
- link: `/${user.product}/organisation/addresses`,
901
- buttonTitle: "View addresses",
902
- };
903
- },
904
- },
905
- registrationRequests: {
906
- callback: async (user) => {
907
- if (!(0, util_1.getAccess)(user, "addStaff"))
908
- return;
909
- const regRequests = await firebaseQuery.getCount("requests", [(0, firestore_1.where)("product", "==", user.product), (0, firestore_1.where)("oId", "==", user.oId)]);
910
- if (regRequests === 0)
911
- return;
912
- if (regRequests === 1) {
913
- const request = Object.entries(await firebaseQuery.getDocsWhere("requests", [(0, firestore_1.where)("product", "==", user.product), (0, firestore_1.where)("oId", "==", user.oId)]) || {})[0];
914
- return {
915
- dismissible: false,
916
- severity: "primary",
917
- title: `${request[1].forename} ${request[1].surname} has requested to access your organisation.`,
918
- message: `Click to review these request.`,
919
- link: `/${user.product}/organisation/staff/requests`,
920
- buttonTitle: "View requests",
921
- };
922
- }
923
- return {
924
- dismissible: false,
925
- severity: "primary",
926
- title: `${regRequests} people have requested to register with your organisation.`,
927
- message: `Click to review these requests.`,
928
- link: `/${user.product}/organisation/staff/requests`,
929
- buttonTitle: "View requests",
930
- };
931
- },
932
- },
933
- activateStaff: {
934
- callback: async (user) => {
935
- if (!(0, util_1.getAccess)(user, "addStaff"))
936
- return;
937
- const inactiveAccounts = await firebaseQuery.getCount("users", [(0, firestore_1.where)("product", "==", user.product), (0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("status", "==", "inactive")]);
938
- if (inactiveAccounts === 0)
939
- return;
940
- if (inactiveAccounts === 1) {
941
- const account = Object.entries(await firebaseQuery.getDocsWhere("users", [(0, firestore_1.where)("product", "==", user.product), (0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("status", "==", "inactive")]) || {})[0];
942
- return {
943
- dismissible: false,
944
- severity: "info",
945
- title: `Activate ${account[1].details.forename} ${account[1].details.surname}'s staff account.`,
946
- message: "Activate this account to give the user access to Placementt.",
947
- link: `/${user.product}/organisation/staff/all`,
948
- buttonTitle: "View accounts",
949
- };
950
- }
951
- return {
952
- dismissible: false,
953
- severity: "info",
954
- title: `${inactiveAccounts} staff have inactive active accounts.`,
955
- message: "Activate these accounts to give the user access to Placementt.",
956
- link: `/${user.product}/organisation/staff/all`,
957
- buttonTitle: "View accounts",
958
- };
959
- },
960
- },
961
- placementStarting: {
962
- callback: async (user) => {
963
- var _a, _b;
964
- const sevenDaysInFuture = new Date();
965
- sevenDaysInFuture.setDate(sevenDaysInFuture.getDate() + 7);
966
- const constraints = [(0, firestore_1.where)("providerId", "==", user.oId), (0, firestore_1.where)("startDate", "<=", (0, util_2.convertDate)(sevenDaysInFuture, "dbstring")), (0, firestore_1.where)("startDate", ">", (0, util_1.dateToString)(new Date()))];
967
- if (user.userGroup !== "admin") {
968
- if (!user.viewPlacementListings || user.viewPlacementListings === "none")
969
- return;
970
- if (!user.viewAddresses || user.viewAddresses === "none")
971
- return;
972
- if (user.viewPlacementListings === "request") {
973
- if (!user.visibleListings || ((_a = user.visibleListings) === null || _a === void 0 ? void 0 : _a.length) === 0)
974
- return;
975
- constraints.push((0, firestore_1.where)((0, firestore_1.documentId)(), 'in', user.visibleListings));
976
- }
977
- else {
978
- // viewPlacementListings must be 'all'
979
- if (user.viewAddresses === "request") {
980
- if (!user.visibleAddresses || ((_b = user.visibleAddresses) === null || _b === void 0 ? void 0 : _b.length) === 0)
981
- return;
982
- constraints.push((0, firestore_1.where)("addressId", 'in', user.visibleAddresses));
983
- }
984
- }
985
- }
986
- const placementsStartingSoon = await firebaseQuery.getCount("placements", constraints);
987
- if (placementsStartingSoon === 0)
988
- return;
989
- if (placementsStartingSoon === 1) {
990
- const placement = Object.entries(await firebaseQuery.getDocsWhere("placements", constraints) || {})[0];
991
- const student = placement[1].uid ? await firebaseQuery.getDocData(["users", placement[1].uid]) : {
992
- details: {
993
- forename: placement[1].studentForename,
994
- surname: placement[1].studentSurname,
995
- }
996
- };
997
- return {
998
- dismissible: false,
999
- severity: "success",
1000
- title: `${student.details.forename} ${student.details.surname}'s placement from ${(0, util_2.convertDate)(placement[1].startDate, "visual")} to ${(0, util_2.convertDate)(placement[1].endDate, "visual")} is starting in less than a week.`,
1001
- message: `Click to view the placement and acquaint yourself with the student.`,
1002
- link: `/${user.product}/placements/${placement[0]}`,
1003
- buttonTitle: "View",
1004
- };
1005
- }
1006
- return {
1007
- dismissible: false,
1008
- severity: "success",
1009
- title: `${placementsStartingSoon} placements starting soon.`,
1010
- message: `Click to view scheduled placements.`,
1011
- link: `/${user.product}/placementListings/placements`,
1012
- buttonTitle: "View placements",
1013
- };
1014
- },
1015
- },
1016
- completeFeedback: {
1017
- callback: async (user) => {
1018
- return;
1019
- return {};
1020
- },
1021
- },
1022
- setUpFeedback: {
1023
- callback: async (user) => {
1024
- return;
1025
- return {};
1026
- },
1027
- },
1028
- };
673
+ // const providerTasks:ProviderTaskObject = {
674
+ // requestedVisibleAddresses: {
675
+ // callback: async (user) => {
676
+ // if (!getAccess(user, "addStaff")) return;
677
+ // const accessRequests = await firebaseQuery.getCount("users", [where("oId", "==", user.oId), where("product", "==", "providers"), orderBy("requestedVisibleAddresses")]) - ((Array.isArray(user?.requestedVisibleAddresses) && user?.requestedVisibleAddresses.length > 0) ? 1 : 0);
678
+ // if (accessRequests === 0) return;
679
+ // if (accessRequests === 1) {
680
+ // const userRequestingAccess = Object.entries(await firebaseQuery.getDocsWhere("users", [where("product", "==", "providers"), where("oId", "==", user.oId), orderBy("requestedVisibleAddresses")]) || {})[0] as [string, UserData];
681
+ // return {
682
+ // dismissible: false,
683
+ // severity: "primary",
684
+ // title: `${userRequestingAccess[1].details.forename} ${userRequestingAccess[1].details.surname} has requested access to view addresses.`,
685
+ // message: `Click to review the addresses and grant access to the user.`,
686
+ // link: `/${user.product}/users/${userRequestingAccess[0]}`,
687
+ // buttonTitle: "View request",
688
+ // } as TaskQueryReturnObject;
689
+ // }
690
+ // return {
691
+ // dismissible: false,
692
+ // severity: "warning",
693
+ // title: `Multiple users have requested access to view addresses.`,
694
+ // message: `Click to review the addresses and grant access to the user.`,
695
+ // link: `/${user.product}/organisation/staff/all`,
696
+ // buttonTitle: "View request",
697
+ // } as TaskQueryReturnObject;
698
+ // },
699
+ // },
700
+ // requestedVisiblePlacementListings: {
701
+ // callback: async (user) => {
702
+ // if (!getAccess(user, "addStaff")) return;
703
+ // const accessRequests = await firebaseQuery.getCount("users", [where("oId", "==", user.oId), where("product", "==", "providers"), orderBy("requestedVisibleListings")])- ((Array.isArray(user?.requestedVisibleListings) && user?.requestedVisibleListings.length > 0) ? 1 : 0);;
704
+ // if (accessRequests === 0) return;
705
+ // if (accessRequests === 1) {
706
+ // const userRequestingAccess = Object.entries(await firebaseQuery.getDocsWhere("users", [where("oId", "==", user.oId), where("product", "==", "providers"), orderBy("requestedVisibleListings")]) || {})[0] as [string, UserData];
707
+ // return {
708
+ // dismissible: false,
709
+ // severity: "primary",
710
+ // title: `${userRequestingAccess[1].details.forename} ${userRequestingAccess[1].details.surname} has requested access to view placement listings.`,
711
+ // message: `Click to review the placement listings and grant access to the user.`,
712
+ // link: `/${user.product}/users/${userRequestingAccess[0]}`,
713
+ // buttonTitle: "View request",
714
+ // } as TaskQueryReturnObject;
715
+ // }
716
+ // return {
717
+ // dismissible: false,
718
+ // severity: "warning",
719
+ // title: `Multiple users have requested access to view placement listings.`,
720
+ // message: `Click to review the placement listings and grant access to the user.`,
721
+ // link: `/${user.product}/organisation/staff/all`,
722
+ // buttonTitle: "View request",
723
+ // } as TaskQueryReturnObject;
724
+ // },
725
+ // },
726
+ // applicationRequireReview: {
727
+ // callback: async (user) => {
728
+ // const constraints = [where("providerId", "==", user.oId), where("reqUserType", "==", "Staff"), where("status", "==", "submitted")];
729
+ // if (user.userGroup !== "admin") {
730
+ // if (!user.viewPlacementListings || user.viewPlacementListings === "none") return;
731
+ // if (!user.viewAddresses || user.viewAddresses === "none") return;
732
+ // if (user.viewPlacementListings === "request") {
733
+ // if (!user.visibleListings || user.visibleListings?.length === 0) return;
734
+ // constraints.push(where("listingId", 'in', user.visibleListings));
735
+ // } else {
736
+ // // viewPlacementListings must be 'all'
737
+ // if (user.viewAddresses === "request") {
738
+ // if (!user.visibleAddresses || user.visibleAddresses?.length === 0) return;
739
+ // constraints.push(where("addressId", 'in', user.visibleAddresses));
740
+ // }
741
+ // }
742
+ // }
743
+ // const applicationCount = await firebaseQuery.getCount("applications", constraints);
744
+ // if (applicationCount === 0) return;
745
+ // return {
746
+ // dismissible: false,
747
+ // severity: "primary",
748
+ // title: `${applicationCount} applications require your review.`,
749
+ // message: `Click to view ${applicationCount} that require your attention.`,
750
+ // link: `/${user.product}/placementListings/applicants`,
751
+ // buttonTitle: "View applications",
752
+ // } as TaskQueryReturnObject;
753
+ // },
754
+ // },
755
+ // completeStudentDocs: {
756
+ // callback: async (user) => {
757
+ // return;
758
+ // return {} as TaskQueryReturnObject;
759
+ // },
760
+ // },
761
+ // reviewOnboarding: {
762
+ // callback: async (user) => {
763
+ // const constraints = [where("providerId", "==", user.oId), where("onboarding.completed.accepted", "==", false), where("onboarding.completed.submitted", "==", true), where("endDate", ">=", dateToString(new Date()))]
764
+ // if (user.userGroup !== "admin") {
765
+ // if (!user.viewPlacementListings || user.viewPlacementListings === "none") return;
766
+ // if (!user.viewAddresses || user.viewAddresses === "none") return;
767
+ // if (user.viewPlacementListings === "request") {
768
+ // if (!user.visibleListings || user.visibleListings?.length === 0) return;
769
+ // constraints.push(where("placementId", 'in', user.visibleListings));
770
+ // } else {
771
+ // // viewPlacementListings must be 'all'
772
+ // if (user.viewAddresses === "request") {
773
+ // if (!user.visibleAddresses || user.visibleAddresses?.length === 0) return;
774
+ // constraints.push(where("addressId", 'in', user.visibleAddresses));
775
+ // }
776
+ // }
777
+ // }
778
+ // const toReview = await firebaseQuery.getCount("placements", constraints);
779
+ // if (toReview === 0) return;
780
+ // if (toReview === 1) {
781
+ // const placement = Object.entries(await firebaseQuery.getDocsWhere("placements", constraints) || {})[0] as [string, StudentPlacementData];
782
+ // const student = await firebaseQuery.getDocData(["users", placement[1].uid]) as UserData;
783
+ // return {
784
+ // dismissible: false,
785
+ // severity: "primary",
786
+ // title: `${student.details.forename} ${student.details.surname} has completed their onboarding for their placement from ${convertDate(placement[1].startDate, "visual")} to ${convertDate(placement[1].endDate, "visual")}`,
787
+ // message: `Click to view the placement and review the onboarding.`,
788
+ // link: `/${user.product}/placements/${placement[0]}`,
789
+ // buttonTitle: "View",
790
+ // } as TaskQueryReturnObject;
791
+ // }
792
+ // return {
793
+ // dismissible: false,
794
+ // severity: "primary",
795
+ // title: `${toReview} student have completed their onboarding.`,
796
+ // message: `Click to view your placements and approve completed onboarding`,
797
+ // link: `/${user.product}/placementListings/placements`,
798
+ // buttonTitle: "View placements",
799
+ // } as TaskQueryReturnObject;
800
+ // },
801
+ // },
802
+ // uploadOnboarding: {
803
+ // callback: async (user) => {
804
+ // const constraints = [where("providerId", "==", user.oId), where("onboarding", "==", null), where("endDate", ">=", dateToString(new Date()))];
805
+ // if (user.userGroup !== "admin") {
806
+ // if (!user.viewPlacementListings || user.viewPlacementListings === "none") return;
807
+ // if (!user.viewAddresses || user.viewAddresses === "none") return;
808
+ // if (user.viewPlacementListings === "request") {
809
+ // if (!user.visibleListings || user.visibleListings?.length === 0) return;
810
+ // constraints.push(where("placementId", 'in', user.visibleListings));
811
+ // } else {
812
+ // // viewPlacementListings must be 'all'
813
+ // if (user.viewAddresses === "request") {
814
+ // if (!user.visibleAddresses || user.visibleAddresses?.length === 0) return;
815
+ // constraints.push(where("addressId", 'in', user.visibleAddresses));
816
+ // }
817
+ // }
818
+ // }
819
+ // const withoutOnboarding = await firebaseQuery.getCount("placements", constraints);
820
+ // if (withoutOnboarding === 0) return;
821
+ // if (withoutOnboarding === 1) {
822
+ // const placement = Object.entries(await firebaseQuery.getDocsWhere("placements", constraints) || {})[0] as [string, StudentPlacementData];
823
+ // const student = await firebaseQuery.getDocData(["users", placement[1].uid]) as UserData;
824
+ // return {
825
+ // dismissible: false,
826
+ // severity: "primary",
827
+ // title: `Send onboarding documents to ${student.details.forename} ${student.details.surname}'s placement from ${convertDate(placement[1].startDate, "visual")} to ${convertDate(placement[1].endDate, "visual")}`,
828
+ // message: `Click to view the placement and add or dismiss onboarding reminders.`,
829
+ // link: `/${user.product}/placements/${placement[0]}`,
830
+ // buttonTitle: "View",
831
+ // } as TaskQueryReturnObject;
832
+ // }
833
+ // return {
834
+ // dismissible: false,
835
+ // severity: "primary",
836
+ // title: `Set up onboarding for ${withoutOnboarding} placements to prepare yourself and your students.`,
837
+ // message: `Click to view your placements and add or dismiss onboarding reminders.`,
838
+ // link: `/${user.product}/placementListings/placements`,
839
+ // buttonTitle: "View placements",
840
+ // } as TaskQueryReturnObject;
841
+ // },
842
+ // },
843
+ // completeListing: {
844
+ // callback: async (user) => {
845
+ // const constraints = [where("providerId", "==", user.oId), where("status", "==", "draft")];
846
+ // if (user.userGroup !== "admin") {
847
+ // if (!user.viewPlacementListings || user.viewPlacementListings === "none") return;
848
+ // if (!user.viewAddresses || user.viewAddresses === "none") return;
849
+ // if (user.viewPlacementListings === "request") {
850
+ // if (!user.visibleListings || user.visibleListings?.length === 0) return;
851
+ // constraints.push(where(documentId(), 'in', user.visibleListings));
852
+ // } else {
853
+ // // viewPlacementListings must be 'all'
854
+ // if (user.viewAddresses === "request") {
855
+ // if (!user.visibleAddresses || user.visibleAddresses?.length === 0) return;
856
+ // constraints.push(where("addressId", 'in', user.visibleAddresses));
857
+ // }
858
+ // }
859
+ // }
860
+ // const incompleteListings = await firebaseQuery.getCount("placementListings", constraints);
861
+ // if (incompleteListings === 0) return;
862
+ // if (incompleteListings === 1) {
863
+ // const incompleteListing = Object.entries(await firebaseQuery.getDocsWhere("placementListings", constraints) || {})[0] as [string, PlacementListing];
864
+ // const address = incompleteListing[1].addressId ? await firebaseQuery.getDocData(["addresses", incompleteListing[1].addressId]) as OrganisationAddress : undefined;
865
+ // return {
866
+ // dismissible: false,
867
+ // severity: "info",
868
+ // title: `Your listing '${incompleteListing[1].title || "unnamed"}' at ${address ? `${address["address-line1"]}, ${address.postal_code.toUpperCase()}, ${capitaliseWords(camelCaseToNormal(address.country))}` : "unknown address"} requires more information before publishing.`,
869
+ // message: `Click to complete and publish the placement listing.`,
870
+ // link: `/${user.product}/addListing/${incompleteListing[0]}`,
871
+ // buttonTitle: "View listing",
872
+ // } as TaskQueryReturnObject;
873
+ // }
874
+ // return {
875
+ // dismissible: false,
876
+ // severity: "info",
877
+ // title: `You have ${incompleteListings} draft listings waiting to be published.`,
878
+ // message: `Click to review and publish the placement listings.`,
879
+ // link: `/${user.product}/placementListings/listings`,
880
+ // buttonTitle: "View listings",
881
+ // } as TaskQueryReturnObject;
882
+ // },
883
+ // },
884
+ // completeAddress: {
885
+ // callback: async (user) => {
886
+ // const constraints = [where("product", "==", "providers"), where("oId", "==", user.oId), where("stage", "!=", "complete")];
887
+ // if (user.userGroup !== "admin") {
888
+ // if (!user.viewAddresses || user.viewAddresses === "none") return;
889
+ // if (user.viewAddresses === "request") {
890
+ // if (!user.visibleAddresses || user.visibleAddresses?.length === 0) return;
891
+ // constraints.push(where("addressId", 'in', user.visibleAddresses));
892
+ // }
893
+ // }
894
+ // const incompleteAddresses = await firebaseQuery.getCount("addresses", constraints);
895
+ // if (incompleteAddresses === 0) return;
896
+ // if (incompleteAddresses === 1) {
897
+ // const address = Object.entries(await firebaseQuery.getDocsWhere("addresses", constraints) || {})[0] as [string, OrganisationAddress];
898
+ // return {
899
+ // dismissible: false,
900
+ // severity: "info",
901
+ // title: `Your address: ${address[1]["address-line1"]}, ${address[1].postal_code.toUpperCase()}, ${capitaliseWords(camelCaseToNormal(address[1].country))} is currently incomplete.`,
902
+ // message: `Click to complete the addresses.`,
903
+ // link: `/${user.product}/addAddress/${address[0]}`,
904
+ // buttonTitle: "View address",
905
+ // } as TaskQueryReturnObject;
906
+ // }
907
+ // return {
908
+ // dismissible: false,
909
+ // severity: "info",
910
+ // title: `You have ${incompleteAddresses} draft addresses waiting to be published.`,
911
+ // message: `Click to review the addresses.`,
912
+ // link: `/${user.product}/organisation/addresses`,
913
+ // buttonTitle: "View addresses",
914
+ // } as TaskQueryReturnObject;
915
+ // },
916
+ // },
917
+ // registrationRequests: {
918
+ // callback: async (user) => {
919
+ // if (!getAccess(user, "addStaff")) return;
920
+ // const regRequests = await firebaseQuery.getCount("requests", [where("product", "==", user.product), where("oId", "==", user.oId)]);
921
+ // if (regRequests === 0) return;
922
+ // if (regRequests === 1) {
923
+ // const request = Object.entries(await firebaseQuery.getDocsWhere("requests", [where("product", "==", user.product), where("oId", "==", user.oId)]) || {})[0] as [string, RegistrationRequest];
924
+ // return {
925
+ // dismissible: false,
926
+ // severity: "primary",
927
+ // title: `${request[1].forename} ${request[1].surname} has requested to access your organisation.`,
928
+ // message: `Click to review these request.`,
929
+ // link: `/${user.product}/organisation/staff/requests`,
930
+ // buttonTitle: "View requests",
931
+ // } as TaskQueryReturnObject;
932
+ // }
933
+ // return {
934
+ // dismissible: false,
935
+ // severity: "primary",
936
+ // title: `${regRequests} people have requested to register with your organisation.`,
937
+ // message: `Click to review these requests.`,
938
+ // link: `/${user.product}/organisation/staff/requests`,
939
+ // buttonTitle: "View requests",
940
+ // } as TaskQueryReturnObject;
941
+ // },
942
+ // },
943
+ // activateStaff: {
944
+ // callback: async (user) => {
945
+ // if (!getAccess(user, "addStaff")) return;
946
+ // const inactiveAccounts = await firebaseQuery.getCount("users", [where("product", "==", user.product), where("oId", "==", user.oId), where("status", "==", "inactive")]);
947
+ // if (inactiveAccounts === 0) return;
948
+ // if (inactiveAccounts === 1) {
949
+ // const account = Object.entries(await firebaseQuery.getDocsWhere("users", [where("product", "==", user.product), where("oId", "==", user.oId), where("status", "==", "inactive")]) || {})[0] as [string, UserData];
950
+ // return {
951
+ // dismissible: false,
952
+ // severity: "info",
953
+ // title: `Activate ${account[1].details.forename} ${account[1].details.surname}'s staff account.`,
954
+ // message: "Activate this account to give the user access to Placementt.",
955
+ // link: `/${user.product}/organisation/staff/all`,
956
+ // buttonTitle: "View accounts",
957
+ // } as TaskQueryReturnObject;
958
+ // }
959
+ // return {
960
+ // dismissible: false,
961
+ // severity: "info",
962
+ // title: `${inactiveAccounts} staff have inactive active accounts.`,
963
+ // message: "Activate these accounts to give the user access to Placementt.",
964
+ // link: `/${user.product}/organisation/staff/all`,
965
+ // buttonTitle: "View accounts",
966
+ // } as TaskQueryReturnObject;
967
+ // },
968
+ // },
969
+ // placementStarting: {
970
+ // callback: async (user) => {
971
+ // const sevenDaysInFuture = new Date();
972
+ // sevenDaysInFuture.setDate(sevenDaysInFuture.getDate() + 7)
973
+ // const constraints = [where("providerId", "==", user.oId), where("startDate", "<=", convertDate(sevenDaysInFuture, "dbstring")), where("startDate", ">", dateToString(new Date()))];
974
+ // if (user.userGroup !== "admin") {
975
+ // if (!user.viewPlacementListings || user.viewPlacementListings === "none") return;
976
+ // if (!user.viewAddresses || user.viewAddresses === "none") return;
977
+ // if (user.viewPlacementListings === "request") {
978
+ // if (!user.visibleListings || user.visibleListings?.length === 0) return;
979
+ // constraints.push(where(documentId(), 'in', user.visibleListings));
980
+ // } else {
981
+ // // viewPlacementListings must be 'all'
982
+ // if (user.viewAddresses === "request") {
983
+ // if (!user.visibleAddresses || user.visibleAddresses?.length === 0) return;
984
+ // constraints.push(where("addressId", 'in', user.visibleAddresses));
985
+ // }
986
+ // }
987
+ // }
988
+ // const placementsStartingSoon = await firebaseQuery.getCount("placements", constraints);
989
+ // if (placementsStartingSoon === 0) return;
990
+ // if (placementsStartingSoon === 1) {
991
+ // const placement = Object.entries(await firebaseQuery.getDocsWhere("placements", constraints) || {})[0] as [string, StudentPlacementData];
992
+ // const student = placement[1].uid ? await firebaseQuery.getDocData(["users", placement[1].uid]) as UserData : {
993
+ // details: {
994
+ // forename: placement[1].studentForename,
995
+ // surname: placement[1].studentSurname,
996
+ // }
997
+ // };
998
+ // return {
999
+ // dismissible: false,
1000
+ // severity: "success",
1001
+ // title: `${student.details.forename} ${student.details.surname}'s placement from ${convertDate(placement[1].startDate, "visual")} to ${convertDate(placement[1].endDate, "visual")} is starting in less than a week.`,
1002
+ // message: `Click to view the placement and acquaint yourself with the student.`,
1003
+ // link: `/${user.product}/placements/${placement[0]}`,
1004
+ // buttonTitle: "View",
1005
+ // } as TaskQueryReturnObject;
1006
+ // }
1007
+ // return {
1008
+ // dismissible: false,
1009
+ // severity: "success",
1010
+ // title: `${placementsStartingSoon} placements starting soon.`,
1011
+ // message: `Click to view scheduled placements.`,
1012
+ // link: `/${user.product}/placementListings/placements`,
1013
+ // buttonTitle: "View placements",
1014
+ // } as TaskQueryReturnObject;
1015
+ // },
1016
+ // },
1017
+ // completeFeedback: {
1018
+ // callback: async (user) => {
1019
+ // return;
1020
+ // return {} as TaskQueryReturnObject;
1021
+ // },
1022
+ // },
1023
+ // setUpFeedback: {
1024
+ // callback: async (user) => {
1025
+ // return;
1026
+ // return {} as TaskQueryReturnObject;
1027
+ // },
1028
+ // },
1029
+ // }
1029
1030
  const getTips = async (user, organisation, addresses) => {
1030
1031
  const tipsObject = {
1031
1032
  providers: providerTips,
@@ -1049,16 +1050,16 @@ const getTips = async (user, organisation, addresses) => {
1049
1050
  return processedTips;
1050
1051
  };
1051
1052
  exports.getTips = getTips;
1052
- const getTasks = async (user, organisation, cohort) => {
1053
+ const getTasks = async ({ user, organisation, cohort, school }) => {
1053
1054
  // Cohort is either a specific one or all.
1054
1055
  if (user.product === "institutes" && user.userType === "Staff" && organisation) {
1055
- return await getInstituteTasks(user, organisation, cohort);
1056
+ return await getInstituteTasks({ user, organisation, cohort, school });
1056
1057
  }
1057
1058
  if (user.product === "students" || user.userType === "Students") {
1058
1059
  return await getStudentTasks(user, organisation, cohort);
1059
1060
  }
1060
1061
  if (user.product === "providers" && organisation) {
1061
- return await getProviderTasks(user, organisation);
1062
+ // return await getProviderTasks(user, organisation);
1062
1063
  }
1063
1064
  return [];
1064
1065
  };
@@ -1075,47 +1076,55 @@ const getStudentTasks = async (user, organisation, cohort) => {
1075
1076
  }, Promise.resolve([]));
1076
1077
  return processedTasks;
1077
1078
  };
1078
- const getProviderTasks = async (user, organisation, cohort) => {
1079
- const processedTasks = await Object.entries(providerTasks).reduce(async (acc, [itemName, item]) => {
1080
- const queryResult = await item.callback(user);
1081
- if (!queryResult)
1082
- return await acc;
1083
- const queryResultArray = Array.isArray(queryResult) ? queryResult : [queryResult];
1084
- const results = queryResultArray.map((r) => ({ itemName: itemName, ...r }));
1085
- (await acc).push(...results);
1086
- return await acc;
1087
- }, Promise.resolve([]));
1088
- return processedTasks;
1089
- };
1090
- const getInstituteTasks = async (user, organisation, cohort) => {
1091
- var _a;
1079
+ // const getProviderTasks = async (user: UserData, organisation: InstituteData|ProviderData, cohort?: CohortData):Promise<(TaskQueryReturnObject)[]> => {
1080
+ // const processedTasks = await Object.entries(providerTasks).reduce(async (acc, [itemName, item]) => {
1081
+ // const queryResult = await item.callback(user);
1082
+ // if (!queryResult) return await acc;
1083
+ // const queryResultArray = Array.isArray(queryResult) ? queryResult : [queryResult];
1084
+ // const results = queryResultArray.map((r) => ({itemName: itemName as ProviderTaskNames, ...r}));
1085
+ // (await acc).push(...results);
1086
+ // return await acc;
1087
+ // }, Promise.resolve<TaskQueryReturnObject[]>([]));
1088
+ // return processedTasks;};
1089
+ const getInstituteTasks = async ({ user, organisation, cohort, school }) => {
1092
1090
  let fCohort = cohort;
1093
- if (!fCohort) {
1094
- // get all associated cohorts.
1095
- if (user.viewCohorts === "none")
1091
+ let fSchool = school;
1092
+ const getCohortsOrSchoolsIfNotProvided = async (type) => {
1093
+ var _a;
1094
+ if (user[`view${type}`] === "none")
1096
1095
  return ([]);
1097
- if (user.userGroup === "admin" || user.viewCohorts === "all") {
1098
- const cohorts = await firebaseQuery.getDocsWhere("cohorts", [(0, firestore_1.where)("product", "==", user.product), (0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("stage", "==", "created")]);
1099
- fCohort = Object.entries(cohorts);
1096
+ if (user.userGroup === "admin" || user[`view${type}`] === "all") {
1097
+ const constraints = [(0, firestore_1.where)("oId", "==", user.oId)];
1098
+ if (type === "cohorts") {
1099
+ constraints.push((0, firestore_1.where)("product", "==", user.product), (0, firestore_1.where)("stage", "==", "created"));
1100
+ }
1101
+ const cohorts = await firebaseQuery.getDocsWhere(type, constraints);
1102
+ return Object.entries(cohorts);
1100
1103
  }
1101
- if (user.viewCohorts === "some") {
1102
- const cohorts = await ((_a = user.visibleCohorts) === null || _a === void 0 ? void 0 : _a.reduce(async (acc, cohortId) => {
1103
- const cohort = await firebaseQuery.getDocData(["cohorts", cohortId]);
1104
- if (cohort.stage !== "created") {
1104
+ if (user[`view${type}`] === "some") {
1105
+ const items = await ((_a = user[`visible${type}s`]) === null || _a === void 0 ? void 0 : _a.reduce(async (acc, itemId) => {
1106
+ const item = await firebaseQuery.getDocData([type, itemId]);
1107
+ if (type === "cohorts" && item.stage !== "created") {
1105
1108
  return acc;
1106
1109
  }
1107
- acc[cohortId] = cohort;
1110
+ acc[itemId] = item;
1108
1111
  return acc;
1109
1112
  }, Promise.resolve([])));
1110
- fCohort = cohorts;
1113
+ return items;
1111
1114
  }
1115
+ };
1116
+ if (!fCohort) {
1117
+ fCohort = await getCohortsOrSchoolsIfNotProvided("cohorts");
1118
+ }
1119
+ if (!fSchool) {
1120
+ fSchool = await getCohortsOrSchoolsIfNotProvided("schools");
1112
1121
  }
1113
1122
  const processedTasks = await Object.entries(instituteTasks).reduce(async (acc, [itemName, item]) => {
1114
1123
  if (!fCohort) {
1115
1124
  console.log("No cohorts to retrieve tasks for");
1116
1125
  return ([]);
1117
1126
  }
1118
- const queryResult = await item.callback(user, organisation, fCohort);
1127
+ const queryResult = await item.callback({ user, organisation, cohorts: fCohort, schools: fSchool });
1119
1128
  if (!queryResult)
1120
1129
  return await acc;
1121
1130
  const queryResultArray = Array.isArray(queryResult) ? queryResult : [queryResult];