-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
67 lines (53 loc) · 1.97 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const firebase = require('firebase/compat/app');
require('firebase/compat/auth');
require('firebase/compat/firestore');
const createGroupSchedule = require('./scheduleEndpoint');
const firebaseConfig = {
apiKey: "AIzaSyDMAvqhnUHnw0F68ZIo930zfHJ9ea_qY0c",
authDomain: "phoenix-interviews.firebaseapp.com",
projectId: "phoenix-interviews",
storageBucket: "phoenix-interviews.appspot.com",
messagingSenderId: "751491379571",
appId: "1:751491379571:web:554e19d967ce83a5255506"
};
const app = firebase.initializeApp(firebaseConfig);
const GROUP_CODE = 'testGroup';
//print out who is scheduled for the first shift
async function checkScheduledTenters(groupCode){
await firebase
.firestore()
.collection('groups')
.doc(groupCode)
.get()
.then((doc) => {
var schedule = doc.data().groupSchedule;
if (schedule == null){
console.log("Error, no schedule in the database");
return;
} else if (schedule.length == 0){
console.log("Error, schedule length is zero");
} else {
var tenters = schedule[0].split(' ')
console.log("Users scheduled for the first shift are " + tenters[0] + " and " + tenters[1]);
}
})
}
//initialize the schedule in the database with bad values that need to be fixed
async function init_db(groupCode){
await firebase
.firestore()
.collection('groups')
.doc(groupCode)
.update({
groupSchedule: ["Wrong_Tenter1 Wrong_Tenter2", "Wrong_Tenter1 Wrong_Tenter2"]
})
}
//mess up the db and print out who is scheduled for the first shift
init_db(GROUP_CODE);
console.log("Before fixing the schedule:")
checkScheduledTenters(GROUP_CODE);
//run the scheduler and print out who is scheduled afterwards
createGroupSchedule.createGroupSchedule(GROUP_CODE, "Black", 1).then(() => {
console.log("After fixing the schedule:");
checkScheduledTenters(GROUP_CODE).then(() => {console.log("Finished. You can terminate the program if it is still running")});
});