Skip to content

Commit

Permalink
feat: lodash 4, updated transport and mservice
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Jan 20, 2016
1 parent 376e14d commit 278b7a0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
"flake-idgen": "^1.0.0",
"ioredis": "^1.14.0",
"jsonwebtoken": "^5.5.4",
"lodash": "^3.10.1",
"lodash": "^4.0.0",
"moment": "^2.11.1",
"ms-amqp-conf": "^0.2.0",
"ms-amqp-transport": "^1.1.0",
"ms-amqp-transport": "^1.1.3",
"ms-mailer-client": "^1.0.0",
"ms-mailer-templates": "^0.3.0",
"ms-validation": "^1.0.1",
"mservice": "^1.3.0",
"mservice": "^1.5.0",
"node-uuid": "^1.4.7",
"password-generator": "^2.0.2",
"redis-filtered-sort": "^1.1.1",
Expand All @@ -50,7 +50,7 @@
"urlsafe-base64": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.4.0",
"babel-cli": "^6.4.5",
"babel-eslint": "^5.0.0-beta6",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
Expand Down
5 changes: 3 additions & 2 deletions src/actions/list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const Promise = require('bluebird');
const redisKey = require('../utils/key.js');
const ld = require('lodash');
const mapValues = require('lodash/mapValues');
const { filter: transformFilter } = require('redis-filtered-sort');
const JSONParse = JSON.parse.bind(JSON);

module.exports = function iterateOverActiveUsers(opts) {
const { redis, config } = this;
Expand Down Expand Up @@ -43,7 +44,7 @@ module.exports = function iterateOverActiveUsers(opts) {
const account = {
id,
metadata: {
[audience]: data ? ld.mapValues(data, JSON.parse, JSON) : {},
[audience]: data ? mapValues(data, JSONParse) : {},
},
};

Expand Down
7 changes: 4 additions & 3 deletions src/actions/register.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const Promise = require('bluebird');
const Errors = require('common-errors');
const request = require('request-promise');
const ld = require('lodash');
const defaults = require('lodash/defaults');
const pick = require('lodash/pick');
const setMetadata = require('../utils/updateMetadata.js');
const scrypt = require('../utils/scrypt.js');
const redisKey = require('../utils/key.js');
Expand Down Expand Up @@ -80,7 +81,7 @@ function makeCaptchaCheck(redis, username, captcha, captchaConfig) {
}
})
.then(function verifyGoogleCaptcha() {
return request.post({ uri, qs: ld.defaults(captcha, { secret }), json: true })
return request.post({ uri, qs: defaults(captcha, { secret }), json: true })
.then(function captchaSuccess(body) {
if (!body.success) {
return Promise.reject({ statusCode: 200, error: body });
Expand All @@ -89,7 +90,7 @@ function makeCaptchaCheck(redis, username, captcha, captchaConfig) {
return true;
})
.catch(function captchaError(err) {
const errData = JSON.stringify(ld.pick(err, ['statusCode', 'error']));
const errData = JSON.stringify(pick(err, ['statusCode', 'error']));
throw new Errors.HttpStatusError(412, fmt('Captcha response: %s', errData));
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/custom/cappasity-users-activate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ld = require('lodash');
const find = require('lodash/find');
const moment = require('moment');
const setMetadata = require('../utils/updateMetadata.js');

Expand All @@ -17,7 +17,7 @@ module.exports = function mixPlan(username, audience) {
.publishAndWait(route, id, { timeout: 5000 })
.bind(this)
.then(function mix(plan) {
const subscription = ld.findWhere(plan.subs, { name: 'month' });
const subscription = find(plan.subs, ['name', 'month']);
const nextCycle = moment().add(1, 'month').valueOf();
const update = {
username,
Expand Down
4 changes: 2 additions & 2 deletions src/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const Mailer = require('ms-mailer-client');
const Promise = require('bluebird');
const Errors = require('common-errors');
const ld = require('lodash');
const merge = require('lodash/merge');
const fsort = require('redis-filtered-sort');
const { NotImplementedError } = Errors;

Expand Down Expand Up @@ -121,7 +121,7 @@ module.exports = class Users extends Mservice {
* @return {Users}
*/
constructor(opts = {}) {
super(ld.merge({}, Users.defaultOpts, opts));
super(merge({}, Users.defaultOpts, opts));
const config = this.config;

const { error } = this.validateSync('config', config);
Expand Down
5 changes: 3 additions & 2 deletions src/utils/getMetadata.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const ld = require('lodash');
const mapValues = require('lodash/mapValues');
const redisKey = require('../utils/key.js');
const Promise = require('bluebird');
const { isArray } = Array;
const JSONParse = JSON.parse.bind(JSON);

module.exports = function getMetadata(username, _audience) {
const { redis } = this;
Expand All @@ -15,7 +16,7 @@ module.exports = function getMetadata(username, _audience) {
audience.forEach(function transform(aud, idx) {
const datum = data[idx];
if (datum) {
output[aud] = ld.mapValues(datum, JSON.parse, JSON);
output[aud] = mapValues(datum, JSONParse);
} else {
output[aud] = {};
}
Expand Down
5 changes: 3 additions & 2 deletions src/utils/updateMetadata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ld = require('lodash');
const mapValues = require('lodash/mapValues');
const redisKey = require('../utils/key.js');
const JSONStringify = JSON.stringify.bind(JSON);

/**
* Updates metadata on a user object
Expand All @@ -23,7 +24,7 @@ module.exports = function updateMetadata(opts) {
const $setKeys = $set && Object.keys($set);
const $setLength = $setKeys && $setKeys.length || 0;
if ($setLength > 0) {
pipeline.hmset(metadataKey, ld.mapValues($set, JSON.stringify, JSON));
pipeline.hmset(metadataKey, mapValues($set, JSONStringify));
}

const $incr = metadata.$incr;
Expand Down
5 changes: 4 additions & 1 deletion test/suites/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ describe('#list', function listSuite() {
promises.push(this.users._redis
.pipeline()
.sadd(userSet, user.id)
.hmset(redisKey(user.id, 'metadata', audience), ld.mapValues(user.metadata, JSON.stringify, JSON))
.hmset(
redisKey(user.id, 'metadata', audience),
ld.mapValues(user.metadata, JSON.stringify.bind(JSON))
)
.exec()
);
});
Expand Down

0 comments on commit 278b7a0

Please sign in to comment.