Skip to content

Commit

Permalink
add route for save cofluencers by campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBHdez committed May 9, 2018
1 parent bcbce0a commit f4b35bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion models/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Schema = mongoose.Schema;
const campaignSchema = new Schema({
company_id: { type: Schema.Types.ObjectId, ref: 'Company' },
influencer_id: [{ type: Schema.Types.ObjectId, ref: 'Influencer' }],
influencersSelected: [{ type: Schema.Types.ObjectId, ref: 'Selecteds' }],
cofluencersSelected: [{ type: Schema.Types.ObjectId }],
title: String,
description: String,
campaignImage: String,
Expand Down
17 changes: 13 additions & 4 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ router.post('/upload-image/:image/:campaignid', upload.single('file'), (req, res
};
Campaign.findByIdAndUpdate(campaignId, updateImage, options)
.then((updatedCampaign) => {
console.log(updatedCampaign);
res.status(200).json(updatedCampaign);
})
.catch(next);
Expand Down Expand Up @@ -290,12 +289,22 @@ router.put('/update-user', (req, res, next) => {
}
});

router.post('campaigns/save-cofluencers', (req, res, next) => {
router.put('/campaigns/save-cofluencers', (req, res, next) => {
if (!req.session.currentUser) {
return res.status(401).json({ error: 'unauthorized' });
}
console.log('entraaaaaaa!!!!!!');
console.log(req.body);

const options = {
new: true,
};

const { cofluencerId, campaignId } = req.body;

Campaign.findByIdAndUpdate(campaignId, { $push: { cofluencersSelected: cofluencerId } }, options)
.then((updatedCampaign) => {
res.status(200).json(updatedCampaign);
})
.catch(next);
});

router.get('/campaigns/edit/:id', (req, res, next) => {
Expand Down

0 comments on commit f4b35bc

Please sign in to comment.