-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visitor.js
70 lines (62 loc) · 1.67 KB
/
visitor.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
68
69
70
const ObjectId = require("mongodb").ObjectId;
let visitors;
class Visitor {
static async injectDB(conn) {
visitors = await conn.db("vms").collection("visitors")
}
static async getVisitor(id) {
let visitor = await visitors.findOne({ "id": id });
if(visitor) {
return visitors.find({"id": id}).toArray();
}
else {
return null
}
}
static async createVisitor(name, id, phone, inputby, date, checkin) {
let visitor = await visitors.findOne({ "id": id });
if (visitor) {
return null;
} else {
await visitors.insertOne({ "name": name, "id": id, "phone": phone, "inputby": inputby, "date": date, "checkin": checkin});
}
return visitor = await visitors.findOne({ "id": id });
}
static async updateVisitor(id, checkout, inputby) {
let visitor = await visitors.findOne({ "id": id });
if (visitor.inputby == inputby) {
await visitors.updateOne({"id": id }, { $set: { "checkout": checkout } });
return visitor = await visitors.findOne({ "id": id });
} else {
return null;
}
}
static async deleteVisitor(id, inputby) {
let visitor = await visitors.findOne({ "id": id });
if (visitor.inputby == inputby) {
await visitors.deleteOne({ "id": id });
return true;
} else {
return null;
}
}
static async UsergetVisitors(inputby) {
let visitor = await visitors.find({ "inputby": inputby }).toArray();
if(visitor){
return visitor;
}
else {
return null
}
}
static async getAllVisitors() {
let visitor = await visitors.find({ }).toArray();
if(visitor){
return visitor;
}
else {
return null
}
}
}
module.exports = Visitor;