Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 2484973

Browse files
committed
add seneca action for getting user by rpi profileId
1 parent c498250 commit 2484973

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

users.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = function (options) {
2424
seneca.add({role: plugin, cmd: 'register'}, cmd_register);
2525
seneca.add({role: plugin, cmd: 'promote'}, cmd_promote);
2626
seneca.add({role: plugin, cmd: 'get_users_by_emails'}, cmd_get_users_by_emails);
27+
seneca.add({role: plugin, cmd: 'get_user_by_profile_id'}, cmd_get_user_by_profile_id);
2728
seneca.add({role: plugin, cmd: 'update'}, cmd_update);
2829
seneca.add({role: plugin, cmd: 'get_init_user_types'}, cmd_get_init_user_types);
2930
seneca.add({role: plugin, cmd: 'is_champion'}, cmd_is_champion);
@@ -305,6 +306,28 @@ module.exports = function (options) {
305306
}
306307
}
307308

309+
function cmd_get_user_by_profile_id(args, done) {
310+
var seneca = this;
311+
var query = {};
312+
313+
query.profileId = args.profileId;
314+
query.limit$ = query.limit$ ? query.limit$ : 1;
315+
316+
seneca.make(ENTITY_NS).list$(query, function (err, users) {
317+
if (err) {
318+
return done(err);
319+
}
320+
321+
users = _.map(users, function (user) {
322+
return {email: user.email, id: user.id, name: user.name };
323+
});
324+
325+
users = _.uniq(users, 'email');
326+
327+
done(null, users[0] || {});
328+
});
329+
}
330+
308331
function cmd_update (args, done) {
309332
var seneca = this;
310333
var user = args.user;

0 commit comments

Comments
 (0)