placementt-core 1.20.232 → 1.300.4

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 (101) hide show
  1. package/.eslintrc.js +40 -40
  2. package/.gitattributes +2 -2
  3. package/deploy-all.js +75 -0
  4. package/lib/config.d.ts +0 -13
  5. package/lib/config.js +1 -3
  6. package/lib/config.js.map +1 -1
  7. package/lib/constants.d.ts +1 -0
  8. package/lib/constants.js +48 -1
  9. package/lib/constants.js.map +1 -1
  10. package/lib/features/config.d.ts +133 -133
  11. package/lib/features/config.js +35 -35
  12. package/lib/features/contacts/contacts.d.ts +75 -75
  13. package/lib/features/contacts/contacts.js +105 -105
  14. package/lib/features/downtime/useDowntime.d.ts +11 -11
  15. package/lib/features/downtime/useDowntime.js +22 -22
  16. package/lib/features/placements/studentPlacements/activePlacement.js +1 -1
  17. package/lib/features/placements/studentPlacements/activePlacement.js.map +1 -1
  18. package/lib/features/placements/studentPlacements/studentPlacementsSlice.d.ts +63 -63
  19. package/lib/features/placements/studentPlacements/studentPlacementsSlice.js +81 -81
  20. package/lib/features/providerPlacements/providerPlacementsSlice.d.ts +19 -19
  21. package/lib/features/providerPlacements/providerPlacementsSlice.js +24 -24
  22. package/lib/features/studentPlacements/studentPlacementsSlice.d.ts +62 -62
  23. package/lib/features/studentPlacements/studentPlacementsSlice.js +87 -87
  24. package/lib/features/studentPlacements/useStudentPlacements.d.ts +6 -6
  25. package/lib/features/studentPlacements/useStudentPlacements.js +18 -18
  26. package/lib/features/userSlice.d.ts +26 -26
  27. package/lib/features/userSlice.js +23 -23
  28. package/lib/features/users/useUserFunctions.d.ts +25 -25
  29. package/lib/features/users/useUserFunctions.js +124 -124
  30. package/lib/features/users/userSlice.d.ts +46 -46
  31. package/lib/features/users/userSlice.js +48 -48
  32. package/lib/firebase/firebase.d.ts +1 -1
  33. package/lib/firebase/firebase.js +8 -3
  34. package/lib/firebase/firebase.js.map +1 -1
  35. package/lib/firebase/firebaseConfig.js +1 -0
  36. package/lib/firebase/firebaseConfig.js.map +1 -1
  37. package/lib/firebase/readDatabase.js +7 -7
  38. package/lib/firebase/readDatabase.js.map +1 -1
  39. package/lib/hooks.d.ts +85 -192
  40. package/lib/hooks.js +731 -671
  41. package/lib/hooks.js.map +1 -1
  42. package/lib/images/GatsbyBenchmarks.d.ts +1 -2
  43. package/lib/index.d.ts +0 -1
  44. package/lib/index.js +0 -1
  45. package/lib/index.js.map +1 -1
  46. package/lib/reduxHooks.d.ts +9 -41
  47. package/lib/reduxHooks.js +1 -49
  48. package/lib/reduxHooks.js.map +1 -1
  49. package/lib/tasksAndTips.js +368 -418
  50. package/lib/tasksAndTips.js.map +1 -1
  51. package/lib/typeDefinitions.d.ts +162 -83
  52. package/lib/util.d.ts +25 -1
  53. package/lib/util.js +329 -2
  54. package/lib/util.js.map +1 -1
  55. package/package.json +56 -56
  56. package/src/DatabaseDefinitions.ts +18 -18
  57. package/src/apiCalls.ts +128 -128
  58. package/src/config.ts +50 -53
  59. package/src/constants.ts +846 -796
  60. package/src/databaseTypes.ts +42 -42
  61. package/src/features/analytics/useAnalytics.tsx +63 -63
  62. package/src/features/contacts/contactsSlice.ts +147 -147
  63. package/src/features/contacts/useContacts.tsx +73 -73
  64. package/src/features/dropdown/useDropdown.tsx +52 -52
  65. package/src/features/global/downtime/useDowntime.tsx +23 -23
  66. package/src/features/global/users/useUserFunctions.tsx +132 -132
  67. package/src/features/jobs/jobsSlice.ts +71 -71
  68. package/src/features/placements/studentPlacements/activePlacement.ts +68 -68
  69. package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +97 -97
  70. package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +108 -108
  71. package/src/features/placements/studentPlacements/useStudentPlacements.tsx +9 -9
  72. package/src/features/placements/types.ts +10 -10
  73. package/src/features/referrals/useReferrals.tsx +56 -56
  74. package/src/features/updates/useUpdates.tsx +38 -38
  75. package/src/firebase/firebase.tsx +158 -153
  76. package/src/firebase/firebaseConfig.tsx +47 -45
  77. package/src/firebase/firebaseQuery.tsx +151 -151
  78. package/src/firebase/persistence.ts +84 -84
  79. package/src/firebase/readDatabase.tsx +236 -236
  80. package/src/firebase/util.tsx +352 -352
  81. package/src/firebase/writeDatabase.tsx +77 -77
  82. package/src/hooks.tsx +4476 -4463
  83. package/src/images/GatsbyBenchmarks.tsx +711 -711
  84. package/src/images/LogFuturePlacement.jsx +64 -64
  85. package/src/images/LogPreviousPlacement.jsx +228 -228
  86. package/src/images/gatsby_benchmarks.svg +466 -466
  87. package/src/images/log_future_placement.svg +114 -114
  88. package/src/images/log_previous_placement.svg +199 -199
  89. package/src/index.ts +34 -35
  90. package/src/readDatabase.tsx +3 -3
  91. package/src/reduxHooks.ts +295 -352
  92. package/src/tasksAndTips.ts +1267 -1267
  93. package/src/tutorialTips.ts +58 -58
  94. package/src/typeDefinitions.ts +1260 -1129
  95. package/src/util.ts +523 -177
  96. package/tsconfig.dev.json +5 -5
  97. package/tsconfig.json +21 -21
  98. package/lib/features/logs/logsSlice.d.ts +0 -93
  99. package/lib/features/logs/logsSlice.js +0 -146
  100. package/lib/features/logs/logsSlice.js.map +0 -1
  101. package/src/features/logs/logsSlice.ts +0 -208
@@ -1,236 +1,236 @@
1
- import {collection, getDocs, limit, orderBy, query, QueryConstraint, where} from "firebase/firestore";
2
- import {getDownloadURL, listAll, ref, StorageReference} from "firebase/storage";
3
- import {SetStateAction} from "react";
4
- import {BillingPackage, CohortData, InstituteData, NotificationObject, PlacementListing, ProviderData, UserData, UserGroupData} from "../typeDefinitions";
5
- import {db, storage} from "./firebaseConfig";
6
- import FirebaseQuery from "./firebaseQuery";
7
- import {pathToArr, sortByReverseStringLength} from "./util";
8
-
9
- const firebaseQuery = new FirebaseQuery();
10
-
11
- export const getStaffRolesForStudent = async (studentFields:string[], product:string, userObject:UserData) => {
12
- const roleWithStudent = await firebaseQuery.getDocsWhere(
13
- ["staffRoles"],
14
- where("filters.students", "array-contains", userObject.id));
15
-
16
- const roleWithFilters = await studentFields.reduce(async (acc, field) => {
17
- if (!userObject.details[field as keyof typeof userObject]) {
18
- return acc;
19
- }
20
- const roles = await firebaseQuery.getDocsWhere(
21
- ["staffRoles"],
22
- where(`filters.fields.${field}`, "==", userObject.details[field as keyof typeof userObject])) as {[key:string]: unknown};
23
-
24
- if (Object.keys(roles).length > 0) {
25
- acc = {...acc, ...roles};
26
- }
27
- return acc;
28
- }, Promise.resolve({}));
29
-
30
- return {...roleWithFilters, ...roleWithStudent};
31
- };
32
-
33
- export const searchUsers = async (userType:"Staff"|"Students", name:string, user:UserData, lim=5, constraints:QueryConstraint[]=[]) => {
34
- if (name.length < 3) {
35
- return {};
36
- }
37
- // This means we search for the longest string first, thereby probably getting the fewest results.
38
- const sortedNameList = sortByReverseStringLength(name.split(" "));
39
-
40
- const unfilteredUsersByForename = await firebaseQuery.getDocsWhere(
41
- "users",
42
- [where("userType", "==", userType),
43
- where("oId", "==", user.oId),
44
- where("product", "==", user.product),
45
- where("status", "==", "active"),
46
- ...constraints,
47
- where("details.forename", ">=", sortedNameList[0]),
48
- where("details.forename", "<=", sortedNameList[0]+ "\uf8ff"),
49
- limit(lim)]) as {[key:string]: UserData};
50
- const unfilteredUsersBySurname = await firebaseQuery.getDocsWhere(
51
- "users",
52
- [where("userType", "==", userType),
53
- where("product", "==", user.product),
54
- where("oId", "==", user.oId),
55
- where("status", "==", "active"),
56
- ...constraints,
57
- where("details.surname", ">=", sortedNameList[0]),
58
- where("details.surname", "<=", sortedNameList[0]+ "\uf8ff"),
59
- limit(lim)]) as {[key:string]: UserData};
60
-
61
- let userResults = {...unfilteredUsersByForename, ...unfilteredUsersBySurname};
62
- sortedNameList.shift();
63
- sortedNameList.forEach((name) => {
64
- userResults = Object.fromEntries(Object.entries(userResults).filter(([, user]) => user.details.forename.includes(name) || user.details.surname.includes(name)));
65
- });
66
-
67
- return userResults;
68
- };
69
-
70
- type OldUserData = {
71
- userGroup?: string,
72
- cohort?: string,
73
- }
74
-
75
- export const getUser = async (uid: string, setState: SetStateAction<any>) => {
76
- let oldUser:OldUserData = {};
77
- let groupData = {};
78
- let cohortData = {};
79
- let packageData = {};
80
-
81
- console.log("Fetching user");
82
-
83
- firebaseQuery.documentSnapshot(["users", uid], async (user: UserData) => {
84
- console.log("user", user);
85
- if (user.userGroup && user.userGroup !== "admin") {
86
- // Always set the groupData, but only get it if the user group has changed.keyof
87
- if (oldUser?.userGroup !== user.userGroup) {
88
- groupData = await firebaseQuery.getDocData(["userGroups", user.userGroup]);
89
- }
90
- }
91
- user.groupData = groupData as UserGroupData;
92
-
93
- if (user.product === "providers") {
94
- // Always set the groupData, but only get it if the user group has changed.keyof
95
- if (oldUser?.userGroup !== user.userGroup) {
96
- const provider = await firebaseQuery.getDocData(["providers", user.oId]) as ProviderData;
97
- packageData = await firebaseQuery.getDocData(["billing", provider.package]) as BillingPackage;
98
- }
99
- }
100
- user.packageData = packageData as BillingPackage;
101
-
102
- if (user.cohort) {
103
- // Always set the groupData, but only get it if the user group has changed.keyof
104
- if (oldUser?.cohort !== user.cohort) {
105
- cohortData = await firebaseQuery.getDocData(["cohorts", user.cohort]);
106
- }
107
- }
108
- user.cohortData = cohortData as CohortData;
109
-
110
- oldUser = user;
111
- setState(user)
112
- });
113
- };
114
-
115
- export const getNotifications = async (user: UserData, setState: SetStateAction<any>) => {
116
- const updateNotifications = (notifications:{[key:string]: NotificationObject}, type:"user"|"org") => {
117
- setState((old:{[key:string]: NotificationObject}) => {
118
- const concatenatedNotifications = {
119
- ...old,
120
- ...Object.fromEntries(
121
- Object.entries(notifications)
122
- .map(([k, v]) => [k, {...v, notifType: type}])
123
- ),
124
- };
125
- return Object.fromEntries(Object.entries(concatenatedNotifications).sort(([, a], [, b]) => b.created.toMillis() - a.created.toMillis()));
126
- });
127
- };
128
-
129
- type NotifQuery = [string[], QueryConstraint|QueryConstraint[]];
130
-
131
- const userNotifications:NotifQuery = [["users", user.id, "notifications"], [orderBy("created", "desc"), limit(10)]]; /* , limit(10) */
132
- firebaseQuery.getDocsWhere(userNotifications[0], userNotifications[1]).then((s) => {
133
- updateNotifications(s as {[key:string]: NotificationObject}, "user");
134
- });
135
-
136
- if (user.oId) {
137
- let notificationsQuery:NotifQuery;
138
-
139
- if (user.userGroup === "admin") {
140
- notificationsQuery = [[user.product, user.oId, "notifications"], [orderBy("created", "desc"), limit(10)]]; /* , limit(10) */
141
- } else {
142
- notificationsQuery = [[user.product, user.oId, "notifications"], [where("viewableBy", "array-contains-any", [user.id, user.userGroup]), orderBy("created", "desc")]]; /* , limit(10) */
143
- }
144
- firebaseQuery.getDocsWhere(notificationsQuery[0], notificationsQuery[1]).then((s) => {
145
- updateNotifications(s as {[key:string]: NotificationObject}, "org");
146
- });
147
- }
148
- // Only gets notifications that user can view, either by ID or usergroup. Once user not in group, can no longer see notifications.
149
-
150
- // getCollectionSnapshot(notificationsQuery[0], setState, notificationsQuery[1])
151
- };
152
-
153
-
154
- export const getFiles = async (path: string[]|string) => {
155
- const files = await listAll(ref(storage, ...pathToArr(path)));
156
-
157
- return (await ((Array.from(files.items) as Array<StorageReference>).reduce(async (acc, item) => {
158
- const url = await getDownloadURL(item);
159
- const entry = {name: item.name, url: url};
160
-
161
-
162
- if (!(await acc).includes(entry)) {
163
- (await acc).push(entry);
164
- }
165
- return acc;
166
- }, Promise.resolve([] as Array<{name: string, url: string}>))));
167
- };
168
-
169
-
170
- export const getFormsFromId = async (path: string[]|string, forms: string[]) => {
171
- return (await (Array.from(forms).reduce(async (acc: {[k: string]: any}, item: string) => {
172
- const formData = typeof item === "object" ? item : await firebaseQuery.getDocData([...pathToArr(path), item]);
173
- console.log("formData", formData);
174
-
175
- acc.then((acc: {[k: string]: any}) => {
176
- acc[item] = formData;
177
- });
178
-
179
- return acc;
180
- }, Promise.resolve({}))));
181
- };
182
-
183
- export const getUserById = async (id: string, setState?: SetStateAction<any>, getGroupData=true) => {
184
- if (!setState) {
185
- const user = await firebaseQuery.getDocData(["users", id]).catch(() => false) as UserData|false;
186
- if (!user) return;
187
- if (getGroupData) {
188
- user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
189
- }
190
- return user;
191
- }
192
- firebaseQuery.documentSnapshot(["users", id], async (user: UserData) => {
193
- if (getGroupData) {
194
- user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
195
- }
196
- setState(user);
197
- });
198
- return;
199
- };
200
-
201
- /* export const getUsersByType = async (q: Query, setState:SetStateAction<any>, uid:string, lim:number, limitType?:"start"|"end") => {
202
- if (limitType === "end") {
203
- q = query(q, endBefore(uid), limitToLast(lim));
204
- } else {
205
- q = query(q, startAfter(uid), limit(lim));
206
- }
207
- return firebaseQuery.collectionSnapshot(q, setState);
208
- };*/
209
-
210
- export const getPlacementbyId = async (pid: string, setState:SetStateAction<any>) => {
211
- return firebaseQuery.documentSnapshot(["placements", pid], setState);
212
- };
213
-
214
- export const getOrganisation = async (user: UserData, setOrg: (data: InstituteData|ProviderData) => void) => {
215
- return firebaseQuery.documentSnapshot([user.product, user.oId], setOrg);
216
- };
217
-
218
- export const getPlacementsWhere = async ({w=[], oId, uid, raw=false}:{w:QueryConstraint[]|QueryConstraint, oId?:string, uid?:string, raw?:boolean}) => {
219
- return await firebaseQuery.getDocsWhere("placements", [...(oId ? [where("oId", "==", oId)] : []), ...(uid ? [where("uid", "==", uid)] : []), ...pathToArr(w)], raw);
220
- };
221
-
222
- export const checkPlacementConflicts = async (instituteId:string, userGroupId:string) => {
223
- const q = query(collection(db, "placements"), where("oId", "==", instituteId), where("userGroup", "==", userGroupId));
224
-
225
- return (await getDocs(q)).size;
226
- };
227
-
228
- export const getPlacementListingsById = async (placementListings: string[]) => {
229
- const placements = await Promise.all(placementListings.map(async (listingId) => {
230
- return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]).catch(() => false) as PlacementListing];
231
- })) as [string, PlacementListing|false][];
232
-
233
- return placements.filter(([_, v]) => v !== false) as [string, PlacementListing][];
234
- }
235
-
236
-
1
+ import {collection, getDocs, limit, orderBy, query, QueryConstraint, where} from "firebase/firestore";
2
+ import {getDownloadURL, listAll, ref, StorageReference} from "firebase/storage";
3
+ import {SetStateAction} from "react";
4
+ import {BillingPackage, CohortData, InstituteData, NotificationObject, PlacementListing, ProviderData, UserData, UserGroupData} from "../typeDefinitions";
5
+ import {db, storage} from "./firebaseConfig";
6
+ import FirebaseQuery from "./firebaseQuery";
7
+ import {pathToArr, sortByReverseStringLength} from "./util";
8
+
9
+ const firebaseQuery = new FirebaseQuery();
10
+
11
+ export const getStaffRolesForStudent = async (studentFields:string[], product:string, userObject:UserData) => {
12
+ const roleWithStudent = await firebaseQuery.getDocsWhere(
13
+ ["staffRoles"],
14
+ where("filters.students", "array-contains", userObject.id));
15
+
16
+ const roleWithFilters = await studentFields.reduce(async (acc, field) => {
17
+ if (!userObject.details[field as keyof typeof userObject]) {
18
+ return acc;
19
+ }
20
+ const roles = await firebaseQuery.getDocsWhere(
21
+ ["staffRoles"],
22
+ where(`filters.fields.${field}`, "==", userObject.details[field as keyof typeof userObject])) as {[key:string]: unknown};
23
+
24
+ if (Object.keys(roles).length > 0) {
25
+ acc = {...acc, ...roles};
26
+ }
27
+ return acc;
28
+ }, Promise.resolve({}));
29
+
30
+ return {...roleWithFilters, ...roleWithStudent};
31
+ };
32
+
33
+ export const searchUsers = async (userType:"Staff"|"Students", name:string, user:UserData, lim=5, constraints:QueryConstraint[]=[]) => {
34
+ if (name.length < 3) {
35
+ return {};
36
+ }
37
+ // This means we search for the longest string first, thereby probably getting the fewest results.
38
+ const sortedNameList = sortByReverseStringLength(name.split(" "));
39
+
40
+ const unfilteredUsersByForename = await firebaseQuery.getDocsWhere(
41
+ "users",
42
+ [where("userType", "==", userType),
43
+ where("oId", "==", user.oId),
44
+ where("product", "==", user.product),
45
+ where("status", "==", "active"),
46
+ ...constraints,
47
+ where("details.forename", ">=", sortedNameList[0]),
48
+ where("details.forename", "<=", sortedNameList[0]+ "\uf8ff"),
49
+ limit(lim)]) as {[key:string]: UserData};
50
+ const unfilteredUsersBySurname = await firebaseQuery.getDocsWhere(
51
+ "users",
52
+ [where("userType", "==", userType),
53
+ where("product", "==", user.product),
54
+ where("oId", "==", user.oId),
55
+ where("status", "==", "active"),
56
+ ...constraints,
57
+ where("details.surname", ">=", sortedNameList[0]),
58
+ where("details.surname", "<=", sortedNameList[0]+ "\uf8ff"),
59
+ limit(lim)]) as {[key:string]: UserData};
60
+
61
+ let userResults = {...unfilteredUsersByForename, ...unfilteredUsersBySurname};
62
+ sortedNameList.shift();
63
+ sortedNameList.forEach((name) => {
64
+ userResults = Object.fromEntries(Object.entries(userResults).filter(([, user]) => user.details.forename.includes(name) || user.details.surname.includes(name)));
65
+ });
66
+
67
+ return userResults;
68
+ };
69
+
70
+ type OldUserData = {
71
+ userGroup?: string,
72
+ cohort?: string,
73
+ }
74
+
75
+ export const getUser = async (uid: string, setState: SetStateAction<any>) => {
76
+ let oldUser:OldUserData = {};
77
+ let groupData = {};
78
+ let cohortData = {};
79
+ let packageData = {};
80
+
81
+ console.log("Fetching user");
82
+
83
+ firebaseQuery.documentSnapshot(["users", uid], async (user: UserData) => {
84
+ console.log("user", user);
85
+ if (user.userGroup && user.userGroup !== "admin") {
86
+ // Always set the groupData, but only get it if the user group has changed.keyof
87
+ if (oldUser?.userGroup !== user.userGroup) {
88
+ groupData = await firebaseQuery.getDocData(["userGroups", user.userGroup]);
89
+ }
90
+ }
91
+ user.groupData = groupData as UserGroupData;
92
+
93
+ // if (user.product === "providers") {
94
+ // // Always set the groupData, but only get it if the user group has changed.keyof
95
+ // if (oldUser?.userGroup !== user.userGroup) {
96
+ // const provider = await firebaseQuery.getDocData(["providers", user.oId]) as ProviderData;
97
+ // packageData = await firebaseQuery.getDocData(["billing", provider.package]) as BillingPackage;
98
+ // }
99
+ // }
100
+ user.packageData = packageData as BillingPackage;
101
+
102
+ if (user.cohort) {
103
+ // Always set the groupData, but only get it if the user group has changed.keyof
104
+ if (oldUser?.cohort !== user.cohort) {
105
+ cohortData = await firebaseQuery.getDocData(["cohorts", user.cohort]);
106
+ }
107
+ }
108
+ user.cohortData = cohortData as CohortData;
109
+
110
+ oldUser = user;
111
+ setState(user)
112
+ });
113
+ };
114
+
115
+ export const getNotifications = async (user: UserData, setState: SetStateAction<any>) => {
116
+ const updateNotifications = (notifications:{[key:string]: NotificationObject}, type:"user"|"org") => {
117
+ setState((old:{[key:string]: NotificationObject}) => {
118
+ const concatenatedNotifications = {
119
+ ...old,
120
+ ...Object.fromEntries(
121
+ Object.entries(notifications)
122
+ .map(([k, v]) => [k, {...v, notifType: type}])
123
+ ),
124
+ };
125
+ return Object.fromEntries(Object.entries(concatenatedNotifications).sort(([, a], [, b]) => b.created.toMillis() - a.created.toMillis()));
126
+ });
127
+ };
128
+
129
+ type NotifQuery = [string[], QueryConstraint|QueryConstraint[]];
130
+
131
+ const userNotifications:NotifQuery = [["users", user.id, "notifications"], [orderBy("created", "desc"), limit(10)]]; /* , limit(10) */
132
+ firebaseQuery.getDocsWhere(userNotifications[0], userNotifications[1]).then((s) => {
133
+ updateNotifications(s as {[key:string]: NotificationObject}, "user");
134
+ });
135
+
136
+ if (user.oId) {
137
+ let notificationsQuery:NotifQuery;
138
+
139
+ if (user.userGroup === "admin") {
140
+ notificationsQuery = [[user.product, user.oId, "notifications"], [orderBy("created", "desc"), limit(10)]]; /* , limit(10) */
141
+ } else {
142
+ notificationsQuery = [[user.product, user.oId, "notifications"], [where("viewableBy", "array-contains-any", [user.id, user.userGroup]), orderBy("created", "desc")]]; /* , limit(10) */
143
+ }
144
+ firebaseQuery.getDocsWhere(notificationsQuery[0], notificationsQuery[1]).then((s) => {
145
+ updateNotifications(s as {[key:string]: NotificationObject}, "org");
146
+ });
147
+ }
148
+ // Only gets notifications that user can view, either by ID or usergroup. Once user not in group, can no longer see notifications.
149
+
150
+ // getCollectionSnapshot(notificationsQuery[0], setState, notificationsQuery[1])
151
+ };
152
+
153
+
154
+ export const getFiles = async (path: string[]|string) => {
155
+ const files = await listAll(ref(storage, ...pathToArr(path)));
156
+
157
+ return (await ((Array.from(files.items) as Array<StorageReference>).reduce(async (acc, item) => {
158
+ const url = await getDownloadURL(item);
159
+ const entry = {name: item.name, url: url};
160
+
161
+
162
+ if (!(await acc).includes(entry)) {
163
+ (await acc).push(entry);
164
+ }
165
+ return acc;
166
+ }, Promise.resolve([] as Array<{name: string, url: string}>))));
167
+ };
168
+
169
+
170
+ export const getFormsFromId = async (path: string[]|string, forms: string[]) => {
171
+ return (await (Array.from(forms).reduce(async (acc: {[k: string]: any}, item: string) => {
172
+ const formData = typeof item === "object" ? item : await firebaseQuery.getDocData([...pathToArr(path), item]);
173
+ console.log("formData", formData);
174
+
175
+ acc.then((acc: {[k: string]: any}) => {
176
+ acc[item] = formData;
177
+ });
178
+
179
+ return acc;
180
+ }, Promise.resolve({}))));
181
+ };
182
+
183
+ export const getUserById = async (id: string, setState?: SetStateAction<any>, getGroupData=true) => {
184
+ if (!setState) {
185
+ const user = await firebaseQuery.getDocData(["users", id]).catch(() => false) as UserData|false;
186
+ if (!user) return;
187
+ if (getGroupData) {
188
+ user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
189
+ }
190
+ return user;
191
+ }
192
+ firebaseQuery.documentSnapshot(["users", id], async (user: UserData) => {
193
+ if (getGroupData) {
194
+ user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
195
+ }
196
+ setState(user);
197
+ });
198
+ return;
199
+ };
200
+
201
+ /* export const getUsersByType = async (q: Query, setState:SetStateAction<any>, uid:string, lim:number, limitType?:"start"|"end") => {
202
+ if (limitType === "end") {
203
+ q = query(q, endBefore(uid), limitToLast(lim));
204
+ } else {
205
+ q = query(q, startAfter(uid), limit(lim));
206
+ }
207
+ return firebaseQuery.collectionSnapshot(q, setState);
208
+ };*/
209
+
210
+ export const getPlacementbyId = async (pid: string, setState:SetStateAction<any>) => {
211
+ return firebaseQuery.documentSnapshot(["placements", pid], setState);
212
+ };
213
+
214
+ export const getOrganisation = async (user: UserData, setOrg: (data: InstituteData|ProviderData) => void) => {
215
+ return firebaseQuery.documentSnapshot([user.product, user.oId], setOrg);
216
+ };
217
+
218
+ export const getPlacementsWhere = async ({w=[], oId, uid, raw=false}:{w:QueryConstraint[]|QueryConstraint, oId?:string, uid?:string, raw?:boolean}) => {
219
+ return await firebaseQuery.getDocsWhere("placements", [...(oId ? [where("oId", "==", oId)] : []), ...(uid ? [where("uid", "==", uid)] : []), ...pathToArr(w)], raw);
220
+ };
221
+
222
+ export const checkPlacementConflicts = async (instituteId:string, userGroupId:string) => {
223
+ const q = query(collection(db, "placements"), where("oId", "==", instituteId), where("userGroup", "==", userGroupId));
224
+
225
+ return (await getDocs(q)).size;
226
+ };
227
+
228
+ export const getPlacementListingsById = async (placementListings: string[]) => {
229
+ const placements = await Promise.all(placementListings.map(async (listingId) => {
230
+ return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]).catch(() => false) as PlacementListing];
231
+ })) as [string, PlacementListing|false][];
232
+
233
+ return placements.filter(([_, v]) => v !== false) as [string, PlacementListing][];
234
+ }
235
+
236
+