-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataUserLayer.js
79 lines (71 loc) · 1.76 KB
/
dataUserLayer.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
71
72
73
74
75
76
77
78
79
var mongoose = require('./config_db.js');
mongoose = mongoose.mongoose;
var Schema = mongoose.Schema;
var uuidv4 = require('uuid-v4');
var UserSchema = Schema({
name: String,
_id: String,
password: String
});
// TODO MODIFIER LE TRUC DES DEUX LIGNES DESSOUS
var UserModel = mongoose.model('User', UserSchema);
module.exports = {
findUserById: function(id, cb){
UserModel.findById(id,{ password: 0 },function(err, user){
if(err){
throw err;
}else{
if(user!=null){
cb(user);
}
}
});
},
updateUser: function(user, cb){
UserModel.findByIdAndUpdate(user.id, user, function(err, user){
if(err){
throw err;
}else{
cb();
}
});
},
addUser: function(user, cb){
var userToSave = new UserModel({
_id:user.email,
name:user.name,
password:user.password
});
userToSave.save(function(err){
if(err){
throw err;
}else{
cb();
}
});
},
deleteUserById: function(id, cb){
UserModel.findByIdAndRemove(id, function(err, todo){
if (err){
throw err;
}else{
cb();
}
});
},
getUserSet: function(cb) {
UserModel.find({}, function (err, users) {
if (err) throw err;
else cb(users);
});
},
findUserByIdWithPwd: function(id, cb){
UserModel.findById(id,function(err, user){
if(err){
throw err;
}else{
cb(user);
}
});
}
};