-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmongodb.js
More file actions
40 lines (38 loc) · 965 Bytes
/
Copy pathmongodb.js
File metadata and controls
40 lines (38 loc) · 965 Bytes
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
const userSchema = require("./schemas/user.js");
const mongo = {
create: async (user_id, cash_amount = 0, items = []) => {
const user = await userSchema.create({
id: user_id,
cash: cash_amount,
items: items,
});
return user;
},
check: async (user_id) => {
const user = await userSchema.exists({ id: user_id });
if (!user) {
mongo.create(user_id);
}
},
exists: async (user_id) => {
const bool = await userSchema.exists({ id: user_id });
return bool;
},
update: async (user_id, data) => {
const user = await userSchema.findOneAndUpdate({ id: user_id }, data);
return user;
},
find: async (user_id) => {
const user = await userSchema.findOne({ id: user_id });
return user;
},
clear: async () => {
await userSchema.deleteMany({});
return true;
},
all: async () => {
const users = await userSchema.find({});
return users;
},
};
module.exports = mongo;