/** * Get link for a given page. * @param {Object} req the HTTP request * @param {Number} page the page number * @returns {String} link for the page */ function getPageLink (req, page) { const q = _.assignIn({}, req.query, { page }) return `${config.API_BASE_URL}${req.path}?${querystring.stringify(q)}` }
function Logger (config) { winston.Logger.call(this); var self = this; _.forEach(config, function (cfg, key) { self.add(winston.transports[cfg.type], _.assignIn({ name: key }, cfg.options)); }); }
function Population({ template, size=50, data=[], population=[], fitness=(genome, data) => 1 - genome.test(data).error, _sorted=false, _selection=methods.selection.POWER } = {}) { let self = this; _.assignIn(self, {template,size,data,population,fitness}); if(self.template && !self.population.length) _.times(self.size, function() { self.population.push(Network.fromJSON({ ...self.template.toJSON(), score: undefined })); }); }
router.get('/getTrendingTopics', function(req, res) { // returns trending topics. Twit.get('trends/place', _.assignIn({ id: 1940345, count: 25 }, req.query), function(err, data, response) { try { res.json({ RESULT_CODE: '1', DATA: data && _.head(data) ? _.head(data).trends.slice(0, 25) : [] }); } catch (e) { console.log(e) } }); });
/** * Partially update challenge type. * @param {String} id the challenge type id * @param {Object} data the challenge type data to be updated * @returns {Object} the updated challenge type */ async function partiallyUpdateChallengeType (id, data) { const type = await helper.getById('ChallengeType', id) if (data.name && type.name.toLowerCase() !== data.name.toLowerCase()) { await helper.validateDuplicate('ChallengeType', 'name', data.name) } if (data.abbreviation && type.abbreviation.toLowerCase() !== data.abbreviation.toLowerCase()) { await helper.validateDuplicate('ChallengeType', 'abbreviation', data.abbreviation) } const ret = await helper.update(type, data) // post bus event await helper.postBusEvent(constants.Topics.ChallengeTypeUpdated, _.assignIn({ id }, data)) return ret }
app.post('/questionnaireTemplate', function(req, res){ var QuestionnaireTemplate = app.models.QuestionnaireTemplate; var data = req.body; QuestionnaireTemplate.retrieveByTitle({title: data.title}, function(error, checkData){ if(_.size(checkData)) return res.json(400, {type: 0, message: '该用问卷已存在,请不要重复添加'}); console.log(data.topic, 'data.topic'); // 添加题号 data.topic.forEach(function(item, index){ _.assignIn(item, {number: index+1}); // // if(item.options){ // item.options.forEach(function(option, opIdx){ // _.assignIn(option, {number: opIdx+1}); // }); // } }); var questionnaireTemplate = new QuestionnaireTemplate(data); questionnaireTemplate.save(function(error, model){ if(error){ res.json(500, error); }else{ res.json(200); } }); }); });
router.get('/getTopicTweet', function(req, res) { // First get 25 tweets show that user can see something on UI. then start stream. if (req.query && req.query.q) { Twit.get('search/tweets', _.assignIn({ count: 25 }, req.query), function(err, data, response) { try { res.json({ RESULT_CODE: '1', DATA: data && data.statuses || [] }); if (io_socket) { if (stream) { stream = undefined; } var stream = Twit.stream('statuses/filter', { track: req.query.q }) stream.on('tweet', function(tweet) { io_socket.emit('tweet', tweet); }); } } catch (e) { console.log(e) } }) } else { res.status(400).send({ RESULT_CODE: '-1', message: 'required param is missing.' }); } });
/** * Update timeline template. * @param {String} timelineTemplateId the timeline template id * @param {Object} data the timeline template data to be updated * @param {Boolean} isFull the flag indicate it is a fully update operation. * @returns {Object} the updated timeline template */ async function update (timelineTemplateId, data, isFull) { const timelineTemplate = await helper.getById('TimelineTemplate', timelineTemplateId) if (data.name && data.name.toLowerCase() !== timelineTemplate.name.toLowerCase()) { await helper.validateDuplicate('TimelineTemplate', 'name', data.name) } if (data.phases) { await helper.validatePhases(data.phases) } if (isFull) { // description is optional field, can be undefined timelineTemplate.description = data.description } const ret = await helper.update(timelineTemplate, data) // post bus event await helper.postBusEvent(constants.Topics.TimelineTemplateUpdated, isFull ? ret : _.assignIn({ id: timelineTemplateId }, data)) return ret }
}); const newObject = (overwrite) ? _.assignIn(this.json, object) : deepExtend(this.json, object);
type: config.ES.ES_TYPE, id: challenge.id, body: _.assignIn({ numOfSubmissions: 0, numOfRegistrants: 0 }, challenge.originalItem()), refresh: 'true' // refresh ES so that it is visible for read operations instantly }) type: config.ES.ES_TYPE, id: completedChallenge.id, body: _.assignIn({ numOfSubmissions: 0, numOfRegistrants: 0 }, completedChallenge.originalItem()), refresh: 'true' // refresh ES so that it is visible for read operations instantly })
/** * Update phase. * @param {String} phaseId the phase id * @param {Object} data the phase data to be updated * @param {Boolean} isFull the flag indicate it is a fully update operation. * @returns {Object} the updated phase */ async function update (phaseId, data, isFull) { const phase = await helper.getById('Phase', phaseId) if (data.name && data.name.toLowerCase() !== phase.name.toLowerCase()) { await helper.validateDuplicate('Phase', 'name', data.name) } if (isFull) { // description is optional field, can be undefined phase.description = data.description } const ret = await helper.update(phase, data) // post bus event await helper.postBusEvent(constants.Topics.ChallengePhaseUpdated, isFull ? ret : _.assignIn({ id: phaseId }, data)) return ret }
/** * Partially update challenge type. * @param {String} id the challenge type id * @param {Object} data the challenge type data to be updated * @returns {Object} the updated challenge type */ async function partiallyUpdateChallengeTrack (id, data) { const type = await helper.getById('ChallengeTrack', id) if (data.name && type.name.toLowerCase() !== data.name.toLowerCase()) { await helper.validateDuplicate('ChallengeTrack', 'name', data.name) } if (data.abbreviation && type.abbreviation.toLowerCase() !== data.abbreviation.toLowerCase()) { await helper.validateDuplicate('ChallengeTrack', 'abbreviation', data.abbreviation) } if (data.legacyId && type.legacyId !== data.legacyId) { await helper.validateDuplicate('ChallengeTrack', 'legacyId', data.legacyId) } const ret = await helper.update(type, data) // post bus event await helper.postBusEvent(constants.Topics.ChallengeTrackUpdated, _.assignIn({ id }, data)) return ret }