-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabaseHelpers.js
55 lines (52 loc) · 1.4 KB
/
databaseHelpers.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
const { userSubmissionsModel, usersModel } = require("./Schema")
const checkStudentRegistrationStatus = (uid) => {
userSubmissionsModel.find({"uri": "123"})
.then(res => {
console.log(res)
})
}
const addDataToDatabase = (model, data, res) => {
switch (model) {
case 1:
new userSubmissionsModel(data).save()
.then(() => res.status(200).send("saved"))
.catch(err => res.status(500).send())
break
case 2:
new usersModel(data).save()
.then(() => res.status(200).send("saved"))
.catch(err => res.status(500).send())
break
default:
console.log("Invalid request")
break
}
}
const getItemFromDatabase = async (model, filterData) => {
let returnVal;
console.log("Sending a request")
switch(model) {
case 1:
await userSubmissionsModel.find({...filterData})
.then((res) => {
returnVal = res
})
break;
case 2:
await usersModel.find({...filterData})
.then((res) => {
returnVal = res
})
break;
default:
returnVal = null
break;
}
console.log(returnVal)
return returnVal
}
module.exports = {
checkStudentRegistrationStatus,
addDataToDatabase,
getItemFromDatabase
}