f22cd7f3
Geoffrey PREUD'HOMME
Système de messag...
|
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
|
// if (nom) {
// Mess.nom = nom;
// } else {
// Mess.nom = Mess.login;
// }
// cb(null, Mess);
// });
cb(null, mess);
};
MesssServ.get = function (id, cb) {
MessModl.findById(id).lean().exec(function (err, mess) {
if (err)
cb(err);
else
MesssServ.addData(mess, cb);
});
};
MesssServ.list = function (conv, cb) {
MessModl.find({
conv: conv
}).lean().exec(function (err, Messs) {
async.mapSeries(Messs, MesssServ.addData, cb);
});
};
MesssServ.add = function (data, cb) {
ConvsServ.canWriteIn(data.conv, data.login, function (err, canWriteIn) {
if (err)
cb(err);
else {
if (canWriteIn) {
MessModl.create({
content: data.content,
login: data.login,
conv: data.conv
}, function (err, Mess) {
MesssServ.get(Mess._id, cb);
});
} else {
cb('unauthorized');
}
}
});
};
|
ba3a9e89
Geoffrey PREUD'HOMME
Ajout de l'éditio...
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
MesssServ.edit = function (data, cb) {
MessModl.findById(data._id, function (err, mess) {
if (err) {
cb(err);
} else {
if (mess) {
mess.content = data.content;
// TODO Edit date
mess.save(cb);
} else {
cb('notfound');
}
}
});
};
|