.then((data) => { var product_id = req.body._id; delete req.body._id; delete req.body.stripe_SKUs; Product.update({ _id: product_id }, flat(req.body), (err, updatedProduct) => { return (err || !updatedProduct) ? error.dbError(res, err, 'Error updating product 1') : res.status(200).json({}); }); })
/*--------------------------------------------------------------- upload user getting score through seed timed include torrent seeders count coefficient value and life coefficient value ---------------------------------------------------------------*/ function (done) { if (!req.currentPeer.isNewCreated) { if (req.seeder && event(query.event) !== EVENT_COMPLETED) { mtDebug.debugGreen('---------------UPLOAD SCORE THROUGH SEED TIMED----------------', 'ANNOUNCE', true, req.passkeyuser); var action = scoreConfig.action.seedTimed; var slAction = scoreConfig.action.seedSeederAndLife; if (action.enable) { var timed = Date.now() - req.currentPeer.last_announce_at; var seedUnit = Math.round((timed / action.additionTime) * 100) / 100; var seedScore = seedUnit * action.timedValue; if (seedScore > 0) { //vip addition if (action.vipRatio && req.passkeyuser.isVip) { seedScore = seedScore * action.vipRatio; } if (slAction.enable) { //torrent seeders count addition if (req.torrent.torrent_seeds <= slAction.seederCount) { var seederUnit = slAction.seederBasicRatio + slAction.seederCoefficient * (slAction.seederCount - req.torrent.torrent_seeds + 1); seedScore = seedScore * seederUnit; } //torrent life addition var life = moment(Date.now()) - moment(req.torrent.createdat); var days = Math.floor(life / (60 * 60 * 1000 * 24)); var lifeUnit = slAction.lifeBasicRatio + slAction.lifeCoefficientOfDay * days; lifeUnit = lifeUnit > slAction.lifeMaxRatio ? slAction.lifeMaxRatio : lifeUnit; seedScore = seedScore * lifeUnit; seedScore = Math.round(seedScore * 100) / 100; } scoreUpdate(req, req.passkeyuser, action, seedScore); done(null); } else { done(null); } } else { done(null); } } else { done(null); } } else { done(null); } },
it('should get error when failed to CAS during create a new role.', function (done) { var configurationOfRomeClient = [ { 'action': '/vatican/counter', 'res': { 'result': { 'affected': 1, 'data': { 'name': 'revision', 'value': 11115 } } } }, { 'action': '/vatican/configuration/role/read', 'res': { 'result': { 'affected': 0, 'data': [] } } }, { 'action': '/vatican/configuration/role/create', 'res': { 'result': { 'affected': 1 } } }, { 'action': '/vatican/configuration/role/cas', 'err': { 'error': { 'code': 1001 } } } ]; var req = {}; req.call = romeClient(configurationOfRomeClient); req.body = { 'name': 'Apache' }; var controller = new ConfigurationController(); controller.update('role', 'roleHistory', req, function (error, result) { should.not.exist(result); done(); }); });
.post(function updateParticipant(req, res, next){ /* POST /updateParticipant * * req.body must have keys: [_id, name, email, phone] */ let updatedParticipant = new Participant(req.body); let particpantID = { '_id':req.body._id }; Participant.update(particpantID, updatedParticipant) .then(function (participant) { return res.json({ message: 'success', participant: participant }); }) .catch(next); });
function update(req, res){ var data = {}; var REQ = req.body || req.params; !REQ.data || (data.data = REQ.data); data = { $set : data }; Model.update({ _id : mongoose.Types.ObjectId(req.params.id) }, data,function(err, rs){ if(rs){ res.json(err || rs); } }); }
var fromDocument = (doc) => { if(doc == null){ return null; } var isArray = Array.isArray(doc); if(!isArray) doc = [doc]; var output = []; for(var it=0; it<doc.length; it++){ let user = new User(doc[it]._id); user.update(doc[it]); output.push(user); } return isArray ? output : output[0]; }
var toFragment = (obj) => { if(obj == null){ return null; } var isArray = Array.isArray(obj); if(!isArray) obj = [obj]; var output = []; for(let it=0; it<obj.length; it++){ let fragment = new Fragment(obj[it]._id); fragment.update(obj[it]); output.push(fragment); } return isArray ? output : output[0]; }
it('should call models update function', function (done) { var difficulty = 'easy'; var settingName = 'rockets'; var label = 'rockets'; var value = '80'; var type = 'number'; modelStub = sinon.stub(difficultyModel, 'updateSetting').returns(new promise (function (resolve, reject) { resolve('test'); })); setting.update(difficulty, settingName, label, value, type).then(function () { expect(modelStub.calledWith(difficulty, settingName, label, Number(value))).to.be.true; done(); }); });
checkAuthenticated(req, res, function(user) { if (user) { boards.update(req,res); } else { dataError.log({ model: "boards", action: "update", code: 401, msg: "Unauthorized access", res: res }); } });
it('saves the tag description to the community', () => { req.params.description = 'here is a #newtag! yay' req.params.tagDescriptions = {newtag: 'i am a new tag'} req.params.communities = [community.id] return PostController.update(req, res) .then(() => community.load('tags')) .then(() => { const tag = community.relations.tags.first() expect(tag).to.exist expect(tag.get('name')).to.equal('newtag') expect(tag.pivot.get('description')).to.equal('i am a new tag') }) })
var fromDocument = (doc) => { if(doc == null){ return null; } var isArray = Array.isArray(doc); if(!isArray) doc = [doc]; var output = []; for(let it=0; it<doc.length; it++){ let collection = new Collection(doc[it]._id); collection.update(doc[it]); output.push(collection); } return isArray ? output : output[0]; }
router.post('/save', (req, res, next) => { var p; if (req.body.docreate === "create") { p = notes.create(req.body.notekey, req.body.title, req.body.body); } else { p = notes.update(req.body.notekey, req.body.title, req.body.body); } p.then(note => { res.redirect('/notes/view?key='+ req.body.notekey); }) .catch(err => { next(err); }); });
inventoryRouter.put('/inventory/unclaim/:id', jwtAuth, (req, res) => { Inventory.update( { _id: req.params.id, claimedBy: { $ne: '' } }, { $set: { claimedBy: '' } }, (err, data) => { if (err) return handleDBError(err, res); if (!data.n) { return res.status(410).json({ msg: 'Inventory already unclaimed' }); } res.status(200).json({ msg: 'Successfully unclaimed inventory' }); renderCSV(); } ); });
modelQuestion.get(id, function(question){ if(answer != ''){ modelQuestion.update(id, answer, 'traité', function(question){ modelQuestion.clean([question], "expert", function(question){ res.location('/expert/questions/'+ question._id); res.status(200).json(question); console.log('Question répondue avec succès ! id :'+question.id); }); }); } else { res.location('/expert/questions/'+ question._id); res.redirect(303, '/expert/questions/' + id); } });
s3.upload(params, (err, obj)=>{ console.log('Obj Key : ' + obj.Key); var url = s3.getSignedUrl('getObject', {Bucket: 'sawabucket', Key: idFile}); console.log('Object added : ' + JSON.stringify(obj)); File.update({_id: idFile}, {url: url}, (err, file)=>{ if(err){ return res.json({msg: err}); } console.log(file); File.findOne({_id: idFile}, (err, file2)=>{ res.json(file2); }); });//File update end });//s3 put obj end
function upSert(result) { if(result.length > 0){ thoughts.update({"_id":thoughtId},{"$set":thoughtObject},function(err,result){ if(err) throw err; }); }else{ thoughts.insert(thoughtObject,function(err,result){ if(err) throw err; else thoughtId = result._id; }) } }
generateToken(function(err, token) { if (err) { return res.status(500).send(err); } User.update({name: req.body.name},{token: token}, function(err, numAffect) { if (err) { console.log('Could not update!'); return res.status(500).send(); } console.log(numAffect); return res.status(200).send({token: token}); }); });
s3.upload(params, (err, data)=>{ if(err){ return res.json({msg: err}); } console.log('Successfully uploaded data : ' + JSON.stringify(data)); //next time, use this below command instead og grabbing url inside upload var urlaws = s3.getSignedUrl('getObject', {Bucket: 'sawabucket', Key: JSON.stringify(file._id)}); console.log('Here is AWS URL : ' + urlaws); File.update({_id: file._id}, {url: urlaws }, (err, file)=>{ console.log('Here is file!!! : ' + file); }); File.findOne({_id: file._id},(err, data)=>{ res.json(data); }); });
it('adds docs', () => { req.params.docs = [doc1Data, doc2Data] return PostController.update(req, res) .tap(() => post.load('media')) .then(() => { var media = post.relations.media expect(media.length).to.equal(2) expect(media.map(m => m.get('type'))).to.deep.equal(['gdoc', 'gdoc']) expect(_.sortBy(media.models, m => m.get('name')).map(m => ({ url: m.get('url'), name: m.get('name') }))).to.deep.equal([doc2Data, doc1Data]) }) })
req.on('data', (data) => { req.body = JSON.parse(data); if (JSON.stringify(req.params.id) === JSON.stringify(req.user.submissions)) { Submission.update({_id: req.params.id}, req.body, (err, sub) => { if (err) { res.status(404).json({msg: 'PUT err: ' + err}); res.end(); } res.status(200).json({data: req.body}); res.end(); }); } else { res.status(404).json({msg: 'You do not have permission to edit this submission!'}); } });
widgetRouter.put('/:id', mAuth(), jsonParser, (req, res) => { try { Widget.update({ _id: req.params.id }, req.body, (err, foundData) => { // Errors if (err) return handleError.dbError(err, res); if (!foundData) return handleError.noData('Error', res); // Return Data; res.status(200).json(foundData); }); } catch (e) { return handleError.dbError('PUT -- Catch hit', res); } });
friendRequest.remove(function(err, friendRequest){ if(err){ console.log(err); return res.send(500, 'Something wrong just happened. Please try again.'); } // delete friend in user's user list User.update({'_id':userId},{$pull:{friend:{'userId':friendId}}},function(err){ if(err){ console.log(err); return res.send(500, 'Something wrong just happened. Please try again.'); } return res.send(200, 'Unfriend'); }); });
}, (err, member) => { if (!err) { member = request.payload; Pf.update({ _id: request.params.pfId }, member, (err) => { if (!err) { return reply(request.payload.name + ' stays in the family for another season!\n'); } else { return reply('The contract says we can\'t change that!'); } }); } else { reply.status(500); } });
authRouter.put('/update/:id', authCheck, jsonParser, (req, res) => { var updateUser = req.body; delete updateUser._id; User.update({ _id: req.params.id }, updateUser, (err) => { if (err) { return res.status(500).json({ msg: 'Error updating user' }) } res.status(200).json({ msg: 'User updated', }); }); });
Practitioner.createRapidProIdInHwr = function (practitionerId, rapidProId) { var dataLoad = "<?xml version='1.0' encoding='utf-8'?>" + "<csd:careServicesRequest xmlns:csd='urn:ihe:iti:csd:2013' xmlns='urn:ihe:iti:csd:2013'>" + " <function urn='urn:openhie.org:openinfoman-hwr:stored-function:health_worker_create_otherid'>" + " <requestParams>" + " <id urn='" + practitionerId + "'/>" + " <otherID assigningAuthorityName='" + rapidProIdAssigner + "' code='" + rapidProId + "' />" + " </requestParams>" + " </function>" + "</csd:careServicesRequest>"; var HwrEndPoint = require(__dirname + '/hwr-end-point'); var hwr = new HwrEndPoint(config.practitionerUpdateEndPoint); return hwr.update(dataLoad); };
}, (err, cat) => { if (!err) { // const name = cat.name; cat = req.payload; Kitty.update({ _id: req.params.catId }, cat, (err) => { if (!err) { res('They must have nine lives!'); } else { return res('Error on put'); } }); } });
app.put('/' + path + '/:id', function(req, res){ log('received PUT for /item'); // TODO: Mix params with object so partial data can be sent // body has post data, params has id log(req.body, req.params); if(!req.body){ res.send({success:0}); }else{ Model.update(req.body, function(item){ res.send(item); }); } });
userRouter.put('/post/:id', authCheck, jsonParser, (req, res) => { var updatePost = req.body; delete updatePost._id; Post.update({ _id: req.params.id }, updatePost, (err) => { if (err) { return res.status(500).json({ msg: 'Error updating post' }) } res.status(200).json({ msg: 'Post updated' }); }); });
it('should get error when bad parameter type.', function (done) { var configurationOfRomeClient = []; var req = {}; req.call = romeClient(configurationOfRomeClient); req.body = { 'name': 'Apache', 'revision': 11111, 'includes': 'IDC-zjm' }; var res = {}; res.json = function (status, body) { body.error.code.should.equal(4001); done(); }; var controller = new RoleController(); controller.update(req, res); });
eveapi.fetch('eve:ConquerableStationList', {}, function (err, result) { if (err) throw err; grunt.log.write('-----> Fetching NPC Stations\n'); for (stationID in result.outposts) { station = result.outposts[stationID]; Station.update({stationID: stationID}, {$set: station}, {upsert: true}, function(err) { throw err; }); count += 1; grunt.verbose.write('.'); } grunt.verbose.write("\n") grunt.log.write(' %s Stations Updated: ', count); mongoose.disconnect(); grunt.log.ok(); });