async function read(params) { const repository = joi.attempt(params, readSchema) // at least one field is required in the condition // filter out undefined values const condition = fp.omitBy(fp.isUndefined, { [`${tableName}.id`]: repository.id, [`${tableName}.full_name`]: repository.full_name }) // get the columns of the user table // add alias prefixes to avoid column name collisions const userColumns = await getColumns(User.tableName) .then(addPrefixAliasToColumns(User.tableName)) const selection = [`${tableName}.*`, ...userColumns] const repo = await db(tableName) .where(condition) .leftJoin(User.tableName, `${tableName}.owner`, `${User.tableName}.id`) .select(selection) .first() if (!repo) { return undefined } const omitUserColumns = fp.omitBy((value, column) => fp.startsWith(`${User.tableName}_`, column)) return Object.assign(omitUserColumns(repo), { owner: getColumnsByTableNamePrefix(User.tableName, repo), }) }
const normalize = (post) => omitBy(isNull, { ...post, children: post.children ? map(post.children, c => c.id) : null, communities: map(post.communities, c => c.id), numComments: post.num_comments || post.numComments, num_comments: null })
function androidNotificationParams ({ deviceToken, playerId, alert, path }) { return omitBy(isNull, { include_android_reg_ids: deviceToken ? [deviceToken] : null, include_player_ids: playerId ? [playerId] : null, contents: {en: alert}, data: {alert, path} }) }
function iosBadgeUpdateParams ({ deviceToken, playerId, badgeNo }) { return omitBy(isNull, { include_ios_tokens: deviceToken ? [deviceToken] : null, include_player_ids: playerId ? [playerId] : null, ios_badgeType: 'SetTo', ios_badgeCount: badgeNo, content_available: true }) }
const normalize = person => { return omitBy(isNull, { ...person, recent_request: null, recent_offer: null, recent_request_id: get(person.recent_request, 'id'), recent_offer_id: get(person.recent_offer, 'id'), left_nav_tags: null }) }
var log = function _log() { console.log.apply(console, arguments); }; var logErrAndQuit = function _logErrAndQuit() { console.error.apply(console, arguments); process.exit(1); }; module.exports = exports = { _: { toKV: toKV }, yargs: { consulOpts: _.flow(_.pick(['prefix', 'host', 'port', 'secure', 'consul-token']), _.omitBy(_.isUndefined)) }, json: { read: readJSON, parse: jsonParse, print: function print(doc) { return console.log(JSON.stringify(doc, null, 2)); } }, env: { read: readEnv, parse: envParse, print: _.flow(envFlatten, _.toPairs, _.map(function (kv) { return console.log("export %s='%s'", kv[0], JSON.stringify(kv[1]));
Aggregate.count(Comment.where(where)).then(count => Post.query().where('id', postId).update(omitBy(isNull, { num_comments: count, updated_at: commentId ? now : null }))),
import { identity, capitalize, omitBy, map, isObject, mapValues, keyBy, isEmpty, flow, split, trim } from 'lodash/fp'; const removeEmptyObjects = omitBy(o => isObject(o) && isEmpty(o)); const queryListFromTerm = (term, transform) => flow( map(field => ({ [field]: new RegExp(`^${transform(term)}`), })), ); // using case-insensitive regex makes it slow, so we do a little hack const queryForTerm = term => fields => ( { $or: [ ...queryListFromTerm(term, identity)(fields), ...queryListFromTerm(term, capitalize)(fields), ], } ); const termToTermList = term => term.match(/\w+|"(?:\\"|[^"])+"/g).map(k => k.replace(/"/g, '')).map(trim); export const createSearchQuery = (fields, terms) => ( { $and: map(term => queryForTerm(term)(fields))(terms), } ); /* eslint import/prefer-default-export: 0 */ export const filterToQuery = (filter, search, transformFilter = f => f) => { // console.log('got filter', filter); // console.log('got search', search);
import expect from 'expect' import L from 'lodash/fp' export const stripUndefined = L.omitBy(L.isUndefined) export const expectClean = L.pipe( stripUndefined, expect )