function get(req, res){ var REQ = req.params; Model .find({_company : mongoose.Types.ObjectId(req.headers["x-shoply-company"])}) .exec(function(err, rs){ if(!err) { res.json(rs); } else res.json(err); }); }
forecastRouter.get('/forecast', bodyParser, (req, res) => { // if(!req.query.lon.match(/-/)) req.query.lon = '-' + req.query.lon; Forecast.find(req.query, (err, data) => { if (err) return errorHandler(err, res); if (data.length === 0) { forecastData(req.query.lat, req.query.lon); Forecast.find(req.query, (err, data) => { if (err) return errorHandler(err); res.status(200).json(data); }); } else { res.status(200).json(data); } }); });
router.get('/api/list', function(req, res, next) { ModelObj.find({showyn:true},{aobjid:1,typ:1,saving:1,url:1,loc:1,attaches:1,regdate:1},function(err,docs){ if(err) { var result = {"result":-1,"error":err.toString()}; res.send(result); } else { res.send(docs); } }); });
this.userForm = function(req, res, next) { logger.logDebug('access to UserController form display.'); User.find({}, function(err, users) { if (err) { logger.logError('error while finding users ' + err); return next(err); } req.viewProperties = { name : 'user/user-form', title : 'Utilisateurs', users : users }; return next(); }); },
it ('can parse hashtags after applying the plugin', () => { expect(linkify.find('There is a #hashtag #YOLO-2015 and #1234 and #%^&*( should not work')) .to.be.eql([{ type: 'hashtag', value: '#hashtag', href: '#hashtag' }, { type: 'hashtag', value: '#YOLO-2015', href: '#YOLO-2015' }]); expect(linkify.test('#wat', 'hashtag')).to.be.ok; expect(linkify.test('#987', 'hashtag')).to.not.be.ok; });
visit(markdownAST, `image`, image => { const imagePath = path.join(getNode(markdownNode.parent).dir, image.url) const imageNode = _.find(files, file => { if (file && file.absolutePath) { return file.absolutePath === imagePath } return false }) if ( imageNode && (imageNode.extension === `gif` || imageNode.extension === `svg`) ) { visitor(image) } })
.then(function ( res ) { expect(res).to.have.status(201); File.find({ _id: { $in: _.map(res.body.file, '_id') } }, function ( err, file ) { if ( err ) throw err; expect(file).to.have.length(2); file.forEach(function ( f ) { expect(fs.existsSync(f.location), 'File Exists').to.equal(true); }); done(); }); });
userRoutes.get('/garage/status', function(req,res){ var user = req.decoded; Garage.find({ username: user.username }, function(err,garage){ if (err){ res.send(err); return; } res.json({ success: true, name: garage[0].name, status: garage[0].actualState }); }); });
read: function(args, callback) { try { var model = require('./models/' + args.collection); var transaction = model.find(args.query); if (args.skip) transaction.skip(Number(args.skip)); if (args.limit) transaction.limit(Number(args.limit)); if (args.sort) transaction.sort(args.sort); if (args.select) transaction.select(args.select); if (args.populate) transaction.populate(args.populate); transaction.exec(callback); } catch (err) { return callback(err); } },
exports.loadChatData = function(id, callback){ var data = []; if(!id){ return callback('Unable to load chat data'); } chatModel.find({ sessionId: id}, false, { sort: { created: 1 }}, function(err, items){ items.forEach(function(item){ data.push({ username: item.username, message: item.message }); }); callback(null, data); }); }
hikeMatchRouter.get('/hikematch', jwtAuth, (req, res) => { Trail.find({ userId: req.user._id }, (err, data) => { if (err) return errorHandler(err, res); goodHike(data, res, (goodWeatherTrailArray) => { dataResults(goodWeatherTrailArray); res.status(200).json({ msg: 'You found some hikes with nice weather', fairWeatherHikes: goodWeatherTrailArray }); }); }); });
router.get('/list/:line/:subway', function(req, res, next) { var line = req.params.line; var subway = req.params.subway; console.log('line==>' + line); console.log('subway==>' + subway); var lineData = []; var sData = []; //호선 정보로 group by ApInfoObj.aggregate([ {"$group" : {_id:"$line", count:{$sum:1}}}, {$sort:{"_id":1}} ]).exec(function(err, docs){ console.log("ApInfoObj docs : " + docs); if(err){ res.render('common/error',{'error':'An error has occurred','url':initurl}); }else { lineData = docs; } }); //역 정보로 group by ApInfoObj.aggregate([ {"$match" : {line : line}}, {"$group" : {_id:"$place", count:{$sum:1}}}, {$sort:{"_id":1}} ]).exec(function(err, docs){ console.log("ApInfoObj Name docs : " + docs); if(err){ res.render('common/error',{'error':'An error has occurred','url':initurl}); }else { sData = docs; } }); ApInfoObj.find({'line': line, 'place' : subway}) .exec(function(err,docs){ console.log('==============>' + docs.length); if(err){ res.render('common/error',{'error':'An error has occurred','url':initurl}); }else { res.render(objname+'/list', {'objname':objname, 'lineData' : lineData, 'data' : docs, 'sData' : sData}); } }); });
.get(function(req, res) { var random = Math.floor(Math.random() * 10); // req.query.skip + Math.floor(Math.random() * 10); var limit = 10; Tips.find() //.limit(limit) .exec(function(err, tips) { if (err) { res.send(err); } else { res.json({'tips': tips}); } }); })
exports.index = function(req, res) { req.query = _.merge({page: 1, perPage: 20, keyword : '', orderBy: 'lastName', orderDir:'asc'}, req.query); var keyword = {$regex: new RegExp(req.query.keyword, 'i')}; var where = {$or: [{lastName: keyword}, {firstName: keyword}, {code: keyword}, {city: keyword}]}; Person.find(where) .sort([[req.query.orderBy, req.query.orderDir]]) .skip(req.query.perPage * (req.query.page - 1)) .limit(req.query.perPage) .exec(function(err, persons) { Person.count().exec(function(err, count) { res.setHeader('pages', Math.ceil( count / req.query.perPage )); res.setHeader('count', count); res.json(200, persons); }) }); };
router.get('/', passport.authenticate('bearer', { session: false }), function(req, res) { Article.find(function (err, articles) { if (!err) { return res.json(articles); } else { res.statusCode = 500; log.error('Internal error(%d): %s',res.statusCode,err.message); return res.json({ error: 'Server error' }); } }); });
//Question dispatcher function questionDispatcher(){ //Getting a random question var random = Math.random(); console.log("Random nummer"+ random); // 1 element questionOp.find({ "random": { $lt: random }}, function (err, result) { console.log("Random gt docs"+ result); if (result === null) { questionOp.find({ "random": { $gt: random }}, function (err, result) { console.log("Random lt docs"+ result); }).limit(1); } }).limit(1); };
user_manager.get_user_membership(username,function(group_list){ if (!group_list || group_list.Error) { }else{ // Find labs where either the user is owner, or has a share to it database.find('labs', {$or: [ {"owner": username}, {"shares": {$elemMatch: {"type": "user", name: username}}}, {"shares": {$elemMatch: {"type": "group", name: {$in: group_list}}}} ]}, {fields: {"_id": false, "lab_id": true}}, function(results){ callback(results); }); } });
quizSchema.methods.populateState = function (){ var self=this; Question.find(function(err,docs){ if(err) { console.log(err);} while(docs.length>0){ var docindex = Math.floor(Math.random()*docs.length); self.questions.push(docs[docindex]); self.answers.push(null); docs.splice(docindex,1); } self.save(function(err,qs){ if(err){ console.log(err);} }); }); };
app.get('/api/users', authAdmin, function(req, res) { User.find({}, function(error, users) { if (error) { console.log(error); return res.sendStatus(500); } var userMap = {}; users.forEach(function(user) { userMap[user._id] = user; }); res.send(userMap); }); });
verify_group: function(group_name,callback){ database.find('groups',{name: group_name},{},function(result){ if (result&&result.Error) { callback(result); }else{ if (result.length===0) { callback(false); }else{ callback(true); } } }); },
it("execAsync and once should have been called for pim.contacts.find() if correct arguments are passed", function () { var successCb = jasmine.createSpy(), errorCb = jasmine.createSpy(); client.find(["name"], { filter: [{ fieldName: ContactFindOptions.SEARCH_FIELD_GIVEN_NAME, fieldValue: "John" }], // filter limit: 5 // limit }, successCb, errorCb); expect(mockedWebworks.execAsync).toHaveBeenCalledWith(_ID, "find", jasmine.any(Object)); expect(mockedWebworks.event.once).toHaveBeenCalledWith(_ID, jasmine.any(String), jasmine.any(Function)); expect(successCb).toHaveBeenCalledWith([]); expect(errorCb).not.toHaveBeenCalled(); });
verify_user: function(username,callback){ database.find('users',{username:username},{},function(result){ if (result&&result.Error) { callback(result); }else{ if (result.length===0) { callback(false); }else{ callback(true); } } }); },
router.get("/", function (req, res, next) { if (req.session.hasOwnProperty('passport')) { var organizationId = filters.getOrganizationId(req); var filterString = {}; if (organizationId != 0) filterString = {organization: organizationId}; EmailLists.find(filterString) .populate("organization") .exec(function (err, emailLists) { if (err) res.json({error: err}); else if (emailLists) res.json({emailLists: emailLists}); else res.json({emailLists: []}); }); } else res.status(403).send('Unknown session'); });
it("error callback is invoked for pim.contacts.find() if contactFields is missing or empty", function () { var successCb = jasmine.createSpy(), errorCb = jasmine.createSpy(); client.find([], new ContactFindOptions( [{ fieldName: ContactFindOptions.SEARCH_FIELD_GIVEN_NAME, fieldValue: "John" }], // filter null, // sort 5 // limit ), successCb, errorCb); expect(errorCb).toHaveBeenCalledWith(new ContactError(ContactError.INVALID_ARGUMENT_ERROR)); expect(successCb).not.toHaveBeenCalled(); });
.then((user) => { if (!user) { return res.json({ users: [] }); } else { return UserSchema.find({ _id: { $in: user.follows } }).sort({ _id: -1 }).lean() .exec().then((data) => { res.json({ users: data, isMore: false }) }, next); } }).catch(next);
it("error callback is invoked for pim.contacts.find() if filter field name is invalid", function () { var successCb = jasmine.createSpy(), errorCb = jasmine.createSpy(); client.find(["name"], new ContactFindOptions( [{ fieldName: 2343, fieldValue: "John" }], // filter null, // sort 5 // limit ), successCb, errorCb); expect(errorCb).toHaveBeenCalledWith(new ContactError(ContactError.INVALID_ARGUMENT_ERROR)); expect(successCb).not.toHaveBeenCalled(); });
app.get('/s/:token', function(req, res){ Lottery.find({token: req.param('token')}, function(err, lotteries){ if(!err){ var lottery = lotteries[0]; Phone.where('token', req.param('token')).where({status: {'$ne': null}}).where({status: {'$ne': ""}}).exec(function(err, docs){ var data = []; for(var i = 0, l = docs.length; i < l; i++){ data.push({status: docs[i].status, phone_number: docs[i].phone_number, callstatus: docs[i].callstatus}); } res.json({data: data, lottery: lottery}); }); }else{ res.json({data: [], lottery: null}); } }); });
userRouter.get('/posts', authCheck, (req, res) => { Post.find({ author_id: req.user._id }, (err, data) => { if (err) { return res.status(500).json({ msg: 'Error finding posts' }) } res.status(200).json({ msg: 'All posts retrieved', posts: data }); }); });
exports.create = function ( req, res, next ) { var payload = req.body.enrollmentPeriod; var _clientError = function ( err ) { res.status(400).send(err); }; if ( !payload || !payload.start || !payload.end ) { return _clientError('Invalid payload'); } EnrollmentPeriod.find({ super: true }, function ( err, enrollmentPeriods ) { if ( err ) { return respond.error.res(res, err, true); } var startDate = moment(payload.start), endDate = moment(payload.end); if ( startDate.isAfter(endDate) ) { return _clientError('Enrollment Period start must be before end date'); } var inSuperPeriod = _.find(enrollmentPeriods, function ( period ) { return moment(period.start).subtract(1, 'day').isBefore(startDate) && moment(period.end).add(1, 'day').isAfter(period.end); }); if ( !inSuperPeriod ) { return _clientError('Enrollment Period must exist within a administration open enrollment period'); } var enrollmentPeriod = new EnrollmentPeriod(_.merge(payload, { company: req.session.user._id, super: false })); enrollmentPeriod.save(function ( err, savedPeriod ) { if ( err ) { return respond.error.res(res, err, true); } res.send({ enrollmentPeriod: savedPeriod }); }); }); };
router.get('/list/:line/:subway', function(req, res, next) { var line = req.params.line; var subway = req.params.subway; console.log('line==>' + line); console.log('subway==>' + subway); ApInfoObj.find({'line': line, 'place' : subway}) .exec(function(err,docs){ console.log('==============>' + docs.length); if(err){ res.send([]); }else { res.send(docs); } }); });