-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
59 lines (56 loc) · 1.04 KB
/
db.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
const Datastore = require("nedb-promises");
const rooms = Datastore.create(__dirname + "/rooms.db");
const records = Datastore.create(__dirname + "/records.db");
let roomsDao = {
findAll() {
return rooms.find({});
},
findById(roomId) {
return rooms.findOne({ roomId });
},
async create(roomId) {
let room = await roomsDao.findById(roomId);
if (room) {
return room;
}
room = await rooms.insert({
roomId,
});
return room;
},
update(roomId, update) {
return rooms.update(
{ roomId },
{ $set: update },
{
returnUpdatedDocs: true,
}
);
},
resetState() {
return rooms.update({}, { $set: { recording: false } });
},
};
let recordsDao = {
findAll() {
return records.find({});
},
update(id, update) {
return records.update(
{ _id: id },
{ $set: update },
{
returnUpdatedDocs: true,
}
);
},
create(doc) {
return records.insert(doc);
},
};
module.exports = {
rooms,
roomsDao,
records,
recordsDao,
};