-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
44 lines (41 loc) · 1.09 KB
/
api.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
var MessageModel = require('./model/message.js');
exports.writeMessages = function(data) {
var message = new MessageModel({
userName: data.userName,
userId: data.userId.split("\"")[1],
text: data.text
});
message.save(function(err) {
if(!err) {
return console.log('created');
} else {
return console.log(err);
}
});
};
exports.getMessages = function(request, response) {
return MessageModel.find(function(err, data) {
if (!err) {
return response.send(data);
} else {
return console.log(err);
}
});
};
exports.postMessage = function(request, response) {
console.log(request.body);
console.log(request.user);
var message = new MessageModel({
userName: request.user.username,
userId: request.user._id,
text: request.body.text
});
message.save(function(err) {
if(!err) {
return console.log('created');
} else {
return console.log(err);
}
});
return response.send(message);
};