-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplydb.js
More file actions
81 lines (63 loc) · 1.98 KB
/
Copy pathapplydb.js
File metadata and controls
81 lines (63 loc) · 1.98 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const mongo = require('@root/mongo');
const ApplySchema = require('@schema/ApplySchema')
module.exports = (client) => { }
module.exports.addApp = async (userID, applycode, answers) => {
return await mongo().then(async (mongoose) => {
try {
console.log('Running: Findone()')
let _id = applycode
const result = await ApplySchema.findOne({
userID,
_id
});
let status = false;
if (result) {
console.log(`${result}, Already exists`)
} else {
console.log(`Inserting Document: ${userID}, ${applycode}`)
await new ApplySchema({
userID,
_id,
answers,
status
}).save()
}
} finally {
mongoose.connection.close()
}
})
}
module.exports.denyApp = async (applycode) => {
return await mongo().then(async (mongoose) => {
try {
let _id = applycode;
console.log(`Running: Findone(${_id})`)
const result = await ApplySchema.findOne({ _id: _id })
let userID = null;
if (result) {
return userID = result.userID;
} else {
console.log("No result recieved")
}
} finally {
mongoose.connection.close()
}
})
}
module.exports.acceptApp = async (applycode) => {
return await mongo().then(async (mongoose) => {
try {
console.log(`Running: Findone(${applycode})`)
const filter = { _id: applycode }
const result = await ApplySchema.findOne(filter)
let userID = null;
if (result) {
return userID = result.userID;
} else {
console.log("No result recieved")
}
} finally {
mongoose.connection.close()
}
})
}