Skip to content

Commit

Permalink
add notification function
Browse files Browse the repository at this point in the history
  • Loading branch information
manupacheco committed May 6, 2018
1 parent 0cdcea2 commit 5f6d621
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions models/msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const msgSchema = new Schema({
from: { type: Schema.Types.ObjectId, ref: this.roleFrom },
msg: String,
read: Boolean,
type: String,
}, {
timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
});
Expand Down
6 changes: 4 additions & 2 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ router.post('/send-msg', (req, res, next) => {
if (!req.session.currentUser) {
return res.status(401).json({ error: 'unauthorized' });
}
const { message, to } = req.body;
const { message, to, type } = req.body;
const { _id, role } = req.session.currentUser;

const msgContentFrom = {
Expand All @@ -465,6 +465,7 @@ router.post('/send-msg', (req, res, next) => {
read: true,
roleTo: role === 'influencer' ? 'Company' : 'Influencer',
roleFrom: role === 'influencer' ? 'Influencer' : 'Company',
type,
};

const msgContentTo = {
Expand All @@ -474,6 +475,7 @@ router.post('/send-msg', (req, res, next) => {
read: false,
roleTo: role === 'influencer' ? 'Company' : 'Influencer',
roleFrom: role === 'influencer' ? 'Influencer' : 'Company',
type,
};

if (role === 'influencer') {
Expand Down Expand Up @@ -540,7 +542,7 @@ router.put('/messages/delete/:idMessage', (req, res, next) => {
const { idMessage } = req.params;
const id = mongoose.Types.ObjectId(idMessage);
if (role === 'company') {
Company.findByIdAndUpdate({ _id }, { $pull: { messages: { _id: id } } }, options)
Company.updateOne({ _id }, { $pull: { messages: { _id: id } } }, options)
.then((updateUser) => {
res.status(200).json(updateUser);
})
Expand Down

0 comments on commit 5f6d621

Please sign in to comment.