placementt-core 1.20.217 → 11.0.803

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 (86) hide show
  1. package/.eslintrc.js +40 -40
  2. package/.gitattributes +2 -2
  3. package/lib/constants.js +10 -1
  4. package/lib/constants.js.map +1 -1
  5. package/lib/features/config.d.ts +133 -133
  6. package/lib/features/config.js +35 -35
  7. package/lib/features/contacts/contacts.d.ts +75 -75
  8. package/lib/features/contacts/contacts.js +105 -105
  9. package/lib/features/downtime/useDowntime.d.ts +11 -11
  10. package/lib/features/downtime/useDowntime.js +22 -22
  11. package/lib/features/placements/studentPlacements/studentPlacementsSlice.d.ts +63 -63
  12. package/lib/features/placements/studentPlacements/studentPlacementsSlice.js +81 -81
  13. package/lib/features/providerPlacements/providerPlacementsSlice.d.ts +19 -19
  14. package/lib/features/providerPlacements/providerPlacementsSlice.js +24 -24
  15. package/lib/features/studentPlacements/studentPlacementsSlice.d.ts +62 -62
  16. package/lib/features/studentPlacements/studentPlacementsSlice.js +87 -87
  17. package/lib/features/studentPlacements/useStudentPlacements.d.ts +6 -6
  18. package/lib/features/studentPlacements/useStudentPlacements.js +18 -18
  19. package/lib/features/userSlice.d.ts +26 -26
  20. package/lib/features/userSlice.js +23 -23
  21. package/lib/features/users/useUserFunctions.d.ts +25 -25
  22. package/lib/features/users/useUserFunctions.js +124 -124
  23. package/lib/features/users/userSlice.d.ts +46 -46
  24. package/lib/features/users/userSlice.js +48 -48
  25. package/lib/firebase/firebase.d.ts +1 -1
  26. package/lib/firebase/firebase.js +6 -2
  27. package/lib/firebase/firebase.js.map +1 -1
  28. package/lib/firebase/readDatabase.js +3 -1
  29. package/lib/firebase/readDatabase.js.map +1 -1
  30. package/lib/hooks.d.ts +33 -5
  31. package/lib/hooks.js +143 -107
  32. package/lib/hooks.js.map +1 -1
  33. package/lib/images/GatsbyBenchmarks.d.ts +1 -2
  34. package/lib/reduxHooks.d.ts +1 -66
  35. package/lib/reduxHooks.js +9 -69
  36. package/lib/reduxHooks.js.map +1 -1
  37. package/lib/tasksAndTips.d.ts +2 -2
  38. package/lib/tasksAndTips.js +37 -6
  39. package/lib/tasksAndTips.js.map +1 -1
  40. package/lib/typeDefinitions.d.ts +50 -5
  41. package/lib/util.d.ts +1 -1
  42. package/lib/util.js +12 -1
  43. package/lib/util.js.map +1 -1
  44. package/package.json +52 -56
  45. package/src/DatabaseDefinitions.ts +18 -18
  46. package/src/apiCalls.ts +128 -128
  47. package/src/config.ts +50 -50
  48. package/src/constants.ts +796 -787
  49. package/src/databaseTypes.ts +42 -42
  50. package/src/features/analytics/useAnalytics.tsx +63 -63
  51. package/src/features/contacts/contactsSlice.ts +147 -147
  52. package/src/features/contacts/useContacts.tsx +73 -73
  53. package/src/features/dropdown/useDropdown.tsx +52 -52
  54. package/src/features/global/downtime/useDowntime.tsx +23 -23
  55. package/src/features/global/users/useUserFunctions.tsx +132 -132
  56. package/src/features/jobs/jobsSlice.ts +71 -71
  57. package/src/features/placements/studentPlacements/activePlacement.ts +68 -68
  58. package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +97 -97
  59. package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +108 -108
  60. package/src/features/placements/studentPlacements/useStudentPlacements.tsx +9 -9
  61. package/src/features/placements/types.ts +10 -10
  62. package/src/features/referrals/useReferrals.tsx +56 -56
  63. package/src/features/updates/useUpdates.tsx +38 -38
  64. package/src/firebase/firebase.tsx +149 -145
  65. package/src/firebase/firebaseConfig.tsx +45 -45
  66. package/src/firebase/firebaseQuery.tsx +151 -151
  67. package/src/firebase/persistence.ts +84 -84
  68. package/src/firebase/readDatabase.tsx +236 -235
  69. package/src/firebase/util.tsx +352 -352
  70. package/src/firebase/writeDatabase.tsx +77 -77
  71. package/src/hooks.tsx +4353 -4323
  72. package/src/images/GatsbyBenchmarks.tsx +711 -711
  73. package/src/images/LogFuturePlacement.jsx +64 -64
  74. package/src/images/LogPreviousPlacement.jsx +228 -228
  75. package/src/images/gatsby_benchmarks.svg +466 -466
  76. package/src/images/log_future_placement.svg +114 -114
  77. package/src/images/log_previous_placement.svg +199 -199
  78. package/src/index.ts +34 -34
  79. package/src/readDatabase.tsx +3 -3
  80. package/src/reduxHooks.ts +232 -297
  81. package/src/tasksAndTips.ts +1209 -1177
  82. package/src/tutorialTips.ts +58 -58
  83. package/src/typeDefinitions.ts +1003 -958
  84. package/src/util.ts +160 -150
  85. package/tsconfig.dev.json +5 -5
  86. package/tsconfig.json +21 -22
@@ -1,235 +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]) as UserData;
186
- if (getGroupData) {
187
- user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
188
- }
189
- return user;
190
- }
191
- firebaseQuery.documentSnapshot(["users", id], async (user: UserData) => {
192
- if (getGroupData) {
193
- user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
194
- }
195
- setState(user);
196
- });
197
- return;
198
- };
199
-
200
- /* export const getUsersByType = async (q: Query, setState:SetStateAction<any>, uid:string, lim:number, limitType?:"start"|"end") => {
201
- if (limitType === "end") {
202
- q = query(q, endBefore(uid), limitToLast(lim));
203
- } else {
204
- q = query(q, startAfter(uid), limit(lim));
205
- }
206
- return firebaseQuery.collectionSnapshot(q, setState);
207
- };*/
208
-
209
- export const getPlacementbyId = async (pid: string, setState:SetStateAction<any>) => {
210
- return firebaseQuery.documentSnapshot(["placements", pid], setState);
211
- };
212
-
213
- export const getOrganisation = async (user: UserData, setOrg: (data: InstituteData|ProviderData) => void) => {
214
- return firebaseQuery.documentSnapshot([user.product, user.oId], setOrg);
215
- };
216
-
217
- export const getPlacementsWhere = async ({w=[], oId, uid, raw=false}:{w:QueryConstraint[]|QueryConstraint, oId?:string, uid?:string, raw?:boolean}) => {
218
- return await firebaseQuery.getDocsWhere("placements", [...(oId ? [where("oId", "==", oId)] : []), ...(uid ? [where("uid", "==", uid)] : []), ...pathToArr(w)], raw);
219
- };
220
-
221
- export const checkPlacementConflicts = async (instituteId:string, userGroupId:string) => {
222
- const q = query(collection(db, "placements"), where("oId", "==", instituteId), where("userGroup", "==", userGroupId));
223
-
224
- return (await getDocs(q)).size;
225
- };
226
-
227
- export const getPlacementListingsById = async (placementListings: string[]) => {
228
- const placements = await Promise.all(placementListings.map(async (listingId) => {
229
- return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]).catch(() => false) as PlacementListing];
230
- })) as [string, PlacementListing|false][];
231
-
232
- return placements.filter(([_, v]) => v !== false) as [string, PlacementListing][];
233
- }
234
-
235
-
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
+