placementt-core 1.20.197 → 11.0.533
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.
- package/.eslintrc.js +40 -40
- package/.gitattributes +2 -2
- package/lib/config.d.ts +0 -1
- package/lib/constants.d.ts +5 -2
- package/lib/constants.js +130 -136
- package/lib/constants.js.map +1 -1
- package/lib/features/analytics/useAnalytics.d.ts +0 -1
- package/lib/features/analytics/useAnalytics.js +3 -4
- package/lib/features/analytics/useAnalytics.js.map +1 -1
- package/lib/features/config.d.ts +133 -133
- package/lib/features/config.js +35 -35
- package/lib/features/contacts/contacts.d.ts +75 -75
- package/lib/features/contacts/contacts.js +105 -105
- package/lib/features/contacts/contactsSlice.d.ts +5 -5
- package/lib/features/contacts/useContacts.js +1 -2
- package/lib/features/contacts/useContacts.js.map +1 -1
- package/lib/features/downtime/useDowntime.d.ts +11 -11
- package/lib/features/downtime/useDowntime.js +22 -22
- package/lib/features/dropdown/useDropdown.d.ts +2 -3
- package/lib/features/dropdown/useDropdown.js +1 -2
- package/lib/features/dropdown/useDropdown.js.map +1 -1
- package/lib/features/global/downtime/useDowntime.d.ts +0 -1
- package/lib/features/global/downtime/useDowntime.js +3 -2
- package/lib/features/global/downtime/useDowntime.js.map +1 -1
- package/lib/features/global/users/useUserFunctions.d.ts +0 -1
- package/lib/features/global/users/useUserFunctions.js +6 -7
- package/lib/features/global/users/useUserFunctions.js.map +1 -1
- package/lib/features/placements/studentPlacements/activePlacement.d.ts +1 -1
- package/lib/features/placements/studentPlacements/activePlacement.js +1 -1
- package/lib/features/placements/studentPlacements/activePlacement.js.map +1 -1
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.d.ts +4 -5
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js +1 -4
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js.map +1 -1
- package/lib/features/placements/studentPlacements/studentPlacementsSlice.d.ts +63 -63
- package/lib/features/placements/studentPlacements/studentPlacementsSlice.js +81 -81
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.d.ts +4 -4
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js +1 -1
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js.map +1 -1
- package/lib/features/placements/studentPlacements/useStudentPlacements.d.ts +0 -1
- package/lib/features/placements/studentPlacements/useStudentPlacements.js +1 -2
- package/lib/features/placements/studentPlacements/useStudentPlacements.js.map +1 -1
- package/lib/features/providerPlacements/providerPlacementsSlice.d.ts +19 -19
- package/lib/features/providerPlacements/providerPlacementsSlice.js +24 -24
- package/lib/features/referrals/useReferrals.d.ts +0 -1
- package/lib/features/referrals/useReferrals.js +1 -2
- package/lib/features/referrals/useReferrals.js.map +1 -1
- package/lib/features/studentPlacements/studentPlacementsSlice.d.ts +62 -62
- package/lib/features/studentPlacements/studentPlacementsSlice.js +87 -87
- package/lib/features/studentPlacements/useStudentPlacements.d.ts +6 -6
- package/lib/features/studentPlacements/useStudentPlacements.js +18 -18
- package/lib/features/updates/useUpdates.js +1 -2
- package/lib/features/updates/useUpdates.js.map +1 -1
- package/lib/features/userSlice.d.ts +26 -26
- package/lib/features/userSlice.js +23 -23
- package/lib/features/users/useUserFunctions.d.ts +25 -25
- package/lib/features/users/useUserFunctions.js +124 -124
- package/lib/features/users/userSlice.d.ts +46 -46
- package/lib/features/users/userSlice.js +48 -48
- package/lib/firebase/firebase.d.ts +1 -1
- package/lib/firebase/firebase.js +9 -4
- package/lib/firebase/firebase.js.map +1 -1
- package/lib/firebase/firebaseConfig.js +3 -0
- package/lib/firebase/firebaseConfig.js.map +1 -1
- package/lib/firebase/firebaseQuery.js +3 -0
- package/lib/firebase/firebaseQuery.js.map +1 -1
- package/lib/firebase/persistence.js +2 -2
- package/lib/firebase/persistence.js.map +1 -1
- package/lib/firebase/readDatabase.d.ts +9 -6
- package/lib/firebase/readDatabase.js +16 -6
- package/lib/firebase/readDatabase.js.map +1 -1
- package/lib/firebase/util.d.ts +3 -4
- package/lib/firebase/util.js +49 -4
- package/lib/firebase/util.js.map +1 -1
- package/lib/firebase/writeDatabase.d.ts +3 -3
- package/lib/firebase/writeDatabase.js +7 -1
- package/lib/firebase/writeDatabase.js.map +1 -1
- package/lib/hooks.d.ts +384 -23
- package/lib/hooks.js +1342 -223
- package/lib/hooks.js.map +1 -1
- package/lib/images/GatsbyBenchmarks.d.ts +0 -1
- package/lib/images/GatsbyBenchmarks.js +1 -1
- package/lib/images/GatsbyBenchmarks.js.map +1 -1
- package/lib/reduxHooks.d.ts +11 -20
- package/lib/reduxHooks.js +28 -18
- package/lib/reduxHooks.js.map +1 -1
- package/lib/tasksAndTips.d.ts +25 -5
- package/lib/tasksAndTips.js +346 -48
- package/lib/tasksAndTips.js.map +1 -1
- package/lib/typeDefinitions.d.ts +478 -53
- package/lib/util.d.ts +1 -0
- package/lib/util.js +78 -6
- package/lib/util.js.map +1 -1
- package/package.json +52 -49
- package/src/DatabaseDefinitions.ts +18 -18
- package/src/apiCalls.ts +128 -128
- package/src/config.ts +50 -50
- package/src/constants.ts +708 -707
- package/src/databaseTypes.ts +42 -42
- package/src/features/analytics/useAnalytics.tsx +55 -55
- package/src/features/contacts/contactsSlice.ts +147 -147
- package/src/features/contacts/useContacts.tsx +73 -73
- package/src/features/dropdown/useDropdown.tsx +52 -52
- package/src/features/global/downtime/useDowntime.tsx +19 -18
- package/src/features/global/users/useUserFunctions.tsx +132 -132
- package/src/features/jobs/jobsSlice.ts +65 -65
- package/src/features/placements/studentPlacements/activePlacement.ts +63 -63
- package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +94 -97
- package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +108 -108
- package/src/features/placements/studentPlacements/useStudentPlacements.tsx +33 -33
- package/src/features/placements/types.ts +10 -10
- package/src/features/referrals/useReferrals.tsx +56 -56
- package/src/features/updates/useUpdates.tsx +36 -36
- package/src/firebase/firebase.tsx +142 -138
- package/src/firebase/firebaseConfig.tsx +45 -42
- package/src/firebase/firebaseQuery.tsx +143 -140
- package/src/firebase/persistence.ts +84 -84
- package/src/firebase/readDatabase.tsx +208 -197
- package/src/firebase/util.tsx +352 -308
- package/src/firebase/writeDatabase.tsx +75 -68
- package/src/hooks.tsx +3395 -1943
- package/src/images/GatsbyBenchmarks.tsx +711 -711
- package/src/images/LogFuturePlacement.jsx +64 -64
- package/src/images/LogPreviousPlacement.jsx +228 -228
- package/src/images/gatsby_benchmarks.svg +466 -466
- package/src/images/log_future_placement.svg +114 -114
- package/src/images/log_previous_placement.svg +199 -199
- package/src/index.ts +34 -34
- package/src/readDatabase.tsx +3 -3
- package/src/reduxHooks.ts +183 -170
- package/src/tasksAndTips.ts +744 -410
- package/src/tutorialTips.ts +58 -58
- package/src/typeDefinitions.ts +899 -503
- package/src/util.ts +132 -47
- package/tsconfig.dev.json +5 -5
- package/tsconfig.json +21 -21
|
@@ -1,197 +1,208 @@
|
|
|
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 {CohortData, NotificationObject, 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
|
-
|
|
45
|
-
where("
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
where("
|
|
54
|
-
where("
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
user.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
user.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
setState(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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 {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
|
+
|
|
80
|
+
console.log("Fetching user");
|
|
81
|
+
|
|
82
|
+
firebaseQuery.documentSnapshot(["users", uid], async (user: UserData) => {
|
|
83
|
+
console.log("user", user);
|
|
84
|
+
if (user.userGroup && user.userGroup !== "admin") {
|
|
85
|
+
// Always set the groupData, but only get it if the user group has changed.keyof
|
|
86
|
+
if (oldUser?.userGroup !== user.userGroup) {
|
|
87
|
+
groupData = await firebaseQuery.getDocData(["userGroups", user.userGroup]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
user.groupData = groupData as UserGroupData;
|
|
91
|
+
|
|
92
|
+
if (user.cohort) {
|
|
93
|
+
// Always set the groupData, but only get it if the user group has changed.keyof
|
|
94
|
+
if (oldUser?.cohort !== user.cohort) {
|
|
95
|
+
cohortData = await firebaseQuery.getDocData(["cohorts", user.cohort]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
user.cohortData = cohortData as CohortData;
|
|
99
|
+
|
|
100
|
+
oldUser = user;
|
|
101
|
+
setState(user)
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const getNotifications = async (user: UserData, setState: SetStateAction<any>) => {
|
|
106
|
+
const updateNotifications = (notifications:{[key:string]: NotificationObject}, type:"user"|"org") => {
|
|
107
|
+
setState((old:{[key:string]: NotificationObject}) => {
|
|
108
|
+
const concatenatedNotifications = {
|
|
109
|
+
...old,
|
|
110
|
+
...Object.fromEntries(
|
|
111
|
+
Object.entries(notifications)
|
|
112
|
+
.map(([k, v]) => [k, {...v, notifType: type}])
|
|
113
|
+
),
|
|
114
|
+
};
|
|
115
|
+
return Object.fromEntries(Object.entries(concatenatedNotifications).sort(([, a], [, b]) => b.created.toMillis() - a.created.toMillis()));
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type NotifQuery = [string[], QueryConstraint|QueryConstraint[]];
|
|
120
|
+
|
|
121
|
+
const userNotifications:NotifQuery = [["users", user.id, "notifications"], [orderBy("created", "desc"), limit(10)]]; /* , limit(10) */
|
|
122
|
+
firebaseQuery.getDocsWhere(userNotifications[0], userNotifications[1]).then((s) => {
|
|
123
|
+
updateNotifications(s as {[key:string]: NotificationObject}, "user");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (user.oId) {
|
|
127
|
+
let notificationsQuery:NotifQuery;
|
|
128
|
+
|
|
129
|
+
if (user.userGroup === "admin") {
|
|
130
|
+
notificationsQuery = [[user.product, user.oId, "notifications"], [orderBy("created", "desc"), limit(10)]]; /* , limit(10) */
|
|
131
|
+
} else {
|
|
132
|
+
notificationsQuery = [[user.product, user.oId, "notifications"], [where("viewableBy", "array-contains-any", [user.id, user.userGroup]), orderBy("created", "desc")]]; /* , limit(10) */
|
|
133
|
+
}
|
|
134
|
+
firebaseQuery.getDocsWhere(notificationsQuery[0], notificationsQuery[1]).then((s) => {
|
|
135
|
+
updateNotifications(s as {[key:string]: NotificationObject}, "org");
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Only gets notifications that user can view, either by ID or usergroup. Once user not in group, can no longer see notifications.
|
|
139
|
+
|
|
140
|
+
// getCollectionSnapshot(notificationsQuery[0], setState, notificationsQuery[1])
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
export const getFiles = async (path: string[]|string) => {
|
|
145
|
+
const files = await listAll(ref(storage, ...pathToArr(path)));
|
|
146
|
+
|
|
147
|
+
return (await ((Array.from(files.items) as Array<StorageReference>).reduce(async (acc, item) => {
|
|
148
|
+
const url = await getDownloadURL(item);
|
|
149
|
+
const entry = {name: item.name, url: url};
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if (!(await acc).includes(entry)) {
|
|
153
|
+
(await acc).push(entry);
|
|
154
|
+
}
|
|
155
|
+
return acc;
|
|
156
|
+
}, Promise.resolve([] as Array<{name: string, url: string}>))));
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
export const getFormsFromId = async (path: string[]|string, forms: string[]) => {
|
|
161
|
+
return (await (Array.from(forms).reduce(async (acc: {[k: string]: any}, item: string) => {
|
|
162
|
+
const formData = typeof item === "object" ? item : await firebaseQuery.getDocData([...pathToArr(path), item]);
|
|
163
|
+
console.log("formData", formData);
|
|
164
|
+
|
|
165
|
+
acc.then((acc: {[k: string]: any}) => {
|
|
166
|
+
acc[item] = formData;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return acc;
|
|
170
|
+
}, Promise.resolve({}))));
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const getUserById = async (id: string) => {
|
|
174
|
+
return await firebaseQuery.getDocData(["users", id]) as UserData;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/* export const getUsersByType = async (q: Query, setState:SetStateAction<any>, uid:string, lim:number, limitType?:"start"|"end") => {
|
|
178
|
+
if (limitType === "end") {
|
|
179
|
+
q = query(q, endBefore(uid), limitToLast(lim));
|
|
180
|
+
} else {
|
|
181
|
+
q = query(q, startAfter(uid), limit(lim));
|
|
182
|
+
}
|
|
183
|
+
return firebaseQuery.collectionSnapshot(q, setState);
|
|
184
|
+
};*/
|
|
185
|
+
|
|
186
|
+
export const getPlacementbyId = async (pid: string, setState:SetStateAction<any>) => {
|
|
187
|
+
return firebaseQuery.documentSnapshot(["placements", pid], setState);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const getOrganisation = async (user: UserData, setOrg: (data: InstituteData|ProviderData) => void) => {
|
|
191
|
+
return firebaseQuery.documentSnapshot([user.product, user.oId], setOrg);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export const getPlacementsWhere = async ({w=[], oId, uid, raw=false}:{w:QueryConstraint[]|QueryConstraint, oId?:string, uid?:string, raw?:boolean}) => {
|
|
195
|
+
return await firebaseQuery.getDocsWhere("placements", [...(oId ? [where("oId", "==", oId)] : []), ...(uid ? [where("uid", "==", uid)] : []), ...pathToArr(w)], raw);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const checkPlacementConflicts = async (instituteId:string, userGroupId:string) => {
|
|
199
|
+
const q = query(collection(db, "placements"), where("oId", "==", instituteId), where("userGroup", "==", userGroupId));
|
|
200
|
+
|
|
201
|
+
return (await getDocs(q)).size;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export const getPlacementListingsById = async (placementListings: string[]) => {
|
|
205
|
+
return Object.fromEntries(await Promise.all(placementListings.map(async (listingId) => {
|
|
206
|
+
return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]) as PlacementListing];
|
|
207
|
+
})) as [string, PlacementListing][]);
|
|
208
|
+
}
|