-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.js
35 lines (33 loc) · 1.15 KB
/
storage.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
module.exports = () => {
const db = require('monk')(process.env.MONGODB_URI),
Team = db.get('teams'),
User = db.get('users'),
Channel = db.get('channels'),
storage = {
teams: {
get: id => Team.findOne({id}),
save: (id, data) => {
data.updatedAt = new Date();
return Team.findOneAndUpdate({id}, {$push: {suggestions: data}}, {upsert: true, new: true});
},
all: () => Team.find({})
},
users: {
get: id => User.findOne({id}),
save: (id, data) => {
data.updatedAt = new Date();
return User.findOneAndUpdate({id}, {$push: {suggestions: data}}, {upsert: true, new: true});
},
all: cb => User.find({})
},
channels: {
get: id => Channel.findOne({id}),
save: (id, data) => {
data.updatedAt = new Date();
return Channel.findOneAndUpdate({id}, {$push: {suggestions: data}}, {upsert: true, new: true});
},
all: () => Channel.find({})
}
};
return storage;
};