slowGet(ctx) { let post = _.cloneDeep(posts.find(post => post.id == ctx.params.id)); return this.Promise.delay(2000) .then(() => ctx.call("v2.users.slowGet", { id: post.author, withPostCount: true })) .then(user => { post.author = _.pick(user, ["userName", "email", "id", "firstName", "lastName", "postsCount"]); return post; }) .catch(err => this.logger.error(err)); }
/** * Convert Error to POJO. * * @param {Error} err * @returns {Object} * @memberof BaseTraceExporter */ errorToObject(err) { if (!err) return null; return _.pick(err, this.tracer.opts.errorFields); }
/* * Helper to load in all app plugins */ const loadPlugins = (app, lando) => Promise.resolve(app.plugins.registry) // Filter out .filter(plugin => _.has(plugin, 'app')) // LOADEM! .map(plugin => app.plugins.load(plugin, plugin.app, app, lando)) // Remove any naughty shit .map(plugin => _.pick(plugin.data, ['config', 'composeData', 'env', 'labels'])) // Merge minotaur .each(result => _.merge(app, result))
@Get('usertrack') async userTrack(@Req() req, @Query() query: any) { const data = _.pick(query, ['platform', 'clientID', 'osName', 'osVersion', 'language', 'country', 'deviceModel', 'deviceWidth', 'deviceHeight', 'referrer', 'url', 'browserName', 'browserVersion', 'ip', 'ua', ]); data.ip = req.ip; await this.statsService.userTrack(data); return {}; }
handler(ctx) { let result = _.cloneDeep(posts); if (ctx.params.limit) result = result.slice(0, ctx.params.limit); // Resolve authors return this.Promise.all(result.map(post => ctx.call("v2.users.get", { id: post.author}) .then(user => post.author = _.pick(user, ["userName", "email", "id", "firstName", "lastName", "postsCount"])))) .then(() => result); }
function getAPI({ user, previews = [], request }) { const github = new Octokit({ auth: user.githubAccessToken, previews, request: { timeout: 10000 }, log: { info(msg, info) { logger.info(`Github API log: ${msg}`, { ..._.omit(info, 'headers', 'request', 'body'), user: _.pick(user, '_id', 'githubUsername', 'githubId'), ..._.pick(request, 'ip', 'hostname'), }); }, }, }); return github; }
_.map(res, p => { index++ const pd = p.dataValues const { code, name } = pd log(index, count, code, name, 2) const arr = [] pd.children = _.map(_.filter(p.cities, c => { const { dataValues: { name }, areas } = c if (f.includes(name)) { arr.push(..._.map(areas, a => _.pick(a.dataValues, cField))) return false } return true }), c => _.pick(c.dataValues, cField)) pd.children.push(...arr) r[pd.name] = pd.children.map(c => c.name) return _.pick(pd, fField) })
/** * Generate local raw info for INFO packet * * @memberof Registry */ regenerateLocalRawInfo(incSeq) { let node = this.nodes.localNode; if (incSeq) node.seq++; const rawInfo = _.pick(node, ["ipList", "hostname", "instanceID", "client", "config", "port", "seq", "metadata"]); if (this.broker.started) rawInfo.services = this.services.getLocalNodeServices(); else rawInfo.services = []; // Make to be safety node.rawInfo = utils.safetyObject(rawInfo, this.broker.options); return node.rawInfo; }
handler(ctx) { // this.logger.debug("Get post...", ctx.params); let post = _.cloneDeep(posts.find(post => post.id == ctx.params.id)); return ctx.call("users.get", { id: post.author }).then(user => { post.author = _.pick(user, ["userName", "email", "id", "firstName", "lastName"]); return post; }); }
/** * Assign extra metrics taking into account action definitions * * @param {Context} ctx * @param {string} name Field of the context to be assigned. * @param {any} payload Object for assignment. * * @private */ assignExtraMetrics(ctx, name, payload) { let def = ctx.action.metrics[name]; // if metrics definitions is boolean do default, metrics=true if (def === true) { payload[name] = ctx[name]; } else if (Array.isArray(def)) { payload[name] = _.pick(ctx[name], def); } else if (isFunction(def)) { payload[name] = def(ctx[name]); } }
handler(ctx) { //this.logger.debug("Find posts..."); let result = _.cloneDeep(posts); // Resolve authors let promises = result.map(post => { return ctx.call("users.get", { id: post.author }).then(user => post.author = _.pick(user, ["userName", "email", "id", "firstName", "lastName"])); }); return Promise.all(promises).then(() => { return result; }); }
_.map(res, p => { index++ const pd = p.dataValues const { code, name } = pd r[pd.name] = {} log(index, count, code, name, 4) pd.children = _.map(p.cities, c => { const cd = c.dataValues const { code, name } = cd r[pd.name][cd.name] = {} log(index, count, code, name, 4) cd.children = _.map(c.areas, a => { const ad = a.dataValues const { code, name } = ad log(index, count, code, name, 4) ad.children = _.map(a.streets, s => { // 特殊处理:第四级(乡级)过滤掉“办事处”后缀 const sd = s.dataValues sd.name = sd.name.replace('办事处', '') return _.pick(sd, cField) }) r[pd.name][cd.name][ad.name] = _.map(ad.children, s => s.name) return _.pick(ad, fField) }) return _.pick(cd, fField) }) return _.pick(pd, fField) })
_.map(res, p => { index++ const pd = p.dataValues const { code, name } = pd r[pd.name] = {} log(index, count, code, name, 3) pd.children = _.map(p.cities, c => { const cd = c.dataValues const { code, name } = cd log(index, count, code, name, 3) const idx = f.indexOf(code) if (idx !== -1) { cd.children = _.map(streets[idx], s => { // 特殊处理:第四级(乡级)过滤掉“办事处”后缀 const sd = s.dataValues sd.name = sd.name.replace('办事处', '') return _.pick(sd, cField) }) } else { cd.children = _.map(c.areas, a => _.pick(a.dataValues, cField)) } r[pd.name][cd.name] = _.map(cd.children, i => i.name) return _.pick(cd, fField) }) return _.pick(pd, fField) })
handler(ctx) { let post = _.cloneDeep(posts.find(post => post.id == ctx.params.id)); return ctx.call("v2.users.get", { id: post.author, withPostCount: true }).then(user => { post.author = _.pick(user, ["userName", "email", "id", "firstName", "lastName", "postsCount"]); return post; }); }
function getAPI({ user, previews = [], request }) { const github = new Octokit({ auth: user.githubAccessToken, previews, request: { timeout: 10000 }, log: { info(msg, info) { logger.info(`Github API log: ${msg}`, { ..._.omit(info, 'headers', 'request', 'body'), user: _.pick(user, '_id', 'githubUsername', 'githubId'), ..._.pick(request, 'ip', 'hostname'), }); }, }, }); return github; }