Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit 9ba2ab3

Browse files
feat(#5): return user status on create chat
1 parent 8f84a53 commit 9ba2ab3

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

controllers/chats/post-chat.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
var mongoose = require('mongoose');
1+
const mongoose = require('mongoose');
22

3-
var Chat = mongoose.model('Chat');
4-
var User = mongoose.model('User');
3+
const Chat = mongoose.model('Chat');
54

65
module.exports.postChat = function (req, res, next) {
76

8-
var chat = req.body.chat;
7+
const chat = req.body.chat;
98

10-
var populateFields = new Array();
11-
populateFields.push({path: "userItem", select: "_id google.id facebook.id facebook.firstName", options: {lean: true}}, {path: "userApplicant", select: "_id facebook.id google.id facebook.firstName", options: {lean: true}});
9+
let populateFields = new Array();
10+
populateFields.push({path: "userItem", select: "_id google.id facebook.id facebook.firstName status", options: {lean: true}}, {path: "userApplicant", select: "_id facebook.id google.id facebook.firstName status", options: {lean: true}});
1211

13-
Chat.create(chat, function (err, createdChat) {
12+
Chat.create(chat, (err, createdChat) => {
1413
if (err) {
1514
res.status(500).json({
1615
error: "There was a problem adding the chat into the database."
1716
});
1817
} else {
19-
Chat.findOne({_id: createdChat._id}).lean().populate(populateFields).exec(function(err, populatedChat) {
18+
Chat.findOne({_id: createdChat._id}).lean().populate(populateFields).exec((err, populatedChat) => {
2019
if (err) {
2120
res.status(500).json({
2221
error: "There was a problem getting the chat from the database."
2322
});
2423
} else {
2524
res.format({
26-
json: function(){
25+
json: () => {
2726
res.json(populatedChat);
2827
}
2928
});

0 commit comments

Comments
 (0)