@@ -8,7 +8,7 @@ var moment = require('moment');
8
8
module . exports = function ( options ) {
9
9
var seneca = this ;
10
10
11
- var PARENT_GUARDIAN_PROFILE_ENTITY = 'cd/profiles' ;
11
+ var ENTITY_NS = 'cd/profiles' ;
12
12
var plugin = 'cd-profiles' ;
13
13
var _ = require ( 'lodash' ) ;
14
14
var async = require ( 'async' ) ;
@@ -93,6 +93,7 @@ module.exports = function (options) {
93
93
seneca . add ( { role : plugin , cmd : 'create' } , cmd_create ) ;
94
94
seneca . add ( { role : plugin , cmd : 'user_profile_data' } , cmd_user_profile_data ) ;
95
95
seneca . add ( { role : plugin , cmd : 'load' } , cmd_load ) ;
96
+ seneca . add ( { role : plugin , cmd : 'load_user_profile' } , cmd_load_user_profile ) ;
96
97
seneca . add ( { role : plugin , cmd : 'save-youth-profile' } , cmd_save_youth_profile ) ;
97
98
seneca . add ( { role : plugin , cmd : 'save' } , cmd_save ) ;
98
99
seneca . add ( { role : plugin , cmd : 'update-youth-profile' } , cmd_update_youth ) ;
@@ -113,7 +114,7 @@ module.exports = function (options) {
113
114
return done ( new Error ( 'Empty query' ) ) ;
114
115
}
115
116
116
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . list$ ( args . query , done ) ;
117
+ seneca . make$ ( ENTITY_NS ) . list$ ( args . query , done ) ;
117
118
}
118
119
119
120
function cmd_create ( args , done ) {
@@ -129,7 +130,7 @@ module.exports = function (options) {
129
130
} ) ;
130
131
131
132
function validateRequest ( done ) {
132
- var profileEntity = seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) ;
133
+ var profileEntity = seneca . make$ ( ENTITY_NS ) ;
133
134
profileEntity . load$ ( profile . id , function ( err , originalProfile ) {
134
135
if ( err ) return done ( err ) ;
135
136
if ( ! originalProfile ) return done ( ) ;
@@ -154,7 +155,7 @@ module.exports = function (options) {
154
155
if ( profile . id ) {
155
156
profile = _ . omit ( profile , immutableFields ) ;
156
157
}
157
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . save$ ( profile , function ( err , profile ) {
158
+ seneca . make$ ( ENTITY_NS ) . save$ ( profile , function ( err , profile ) {
158
159
if ( err ) return done ( err ) ;
159
160
160
161
if ( process . env . SALESFORCE_ENABLED === 'true' ) {
@@ -185,7 +186,7 @@ module.exports = function (options) {
185
186
}
186
187
187
188
function updateSalesForce ( profile ) {
188
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . load$ ( profile . id , function ( err , res ) {
189
+ seneca . make$ ( ENTITY_NS ) . load$ ( profile . id , function ( err , res ) {
189
190
if ( err ) return salesForceLogger ( 'error' , '[error][salesforce] profile id: ' + profile . id + ' not present' ) ;
190
191
191
192
if ( res . userType . toLowerCase ( ) === 'champion' ) {
@@ -338,7 +339,7 @@ module.exports = function (options) {
338
339
var fieldsToBeRemoved = _ . union ( derivedFields , immutableFields ) ;
339
340
340
341
profile = _ . omit ( profile , fieldsToBeRemoved ) ;
341
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . save$ ( profile , function ( err , profile ) {
342
+ seneca . make$ ( ENTITY_NS ) . save$ ( profile , function ( err , profile ) {
342
343
if ( err ) {
343
344
return done ( err ) ;
344
345
}
@@ -353,12 +354,12 @@ module.exports = function (options) {
353
354
354
355
function saveChild ( profile , parentId , done ) {
355
356
if ( _ . contains ( profile . parents , parentId ) ) {
356
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . save$ ( profile , function ( err , profile ) {
357
+ seneca . make$ ( ENTITY_NS ) . save$ ( profile , function ( err , profile ) {
357
358
if ( err ) {
358
359
return done ( err ) ;
359
360
}
360
361
361
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . list$ ( { userId : parentId } , function ( err , results ) {
362
+ seneca . make$ ( ENTITY_NS ) . list$ ( { userId : parentId } , function ( err , results ) {
362
363
var parent = results [ 0 ] ;
363
364
364
365
if ( err ) {
@@ -400,6 +401,7 @@ module.exports = function (options) {
400
401
addFlags ,
401
402
optionalFieldsFilter ,
402
403
privateFilter ,
404
+ privateFilter ,
403
405
publicProfilesFilter ,
404
406
under13Filter ,
405
407
resolveChildren ,
@@ -414,7 +416,7 @@ module.exports = function (options) {
414
416
function getProfile ( done ) {
415
417
var query = args . query ;
416
418
417
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . list$ ( { userId : query . userId } , function ( err , results ) {
419
+ seneca . make$ ( ENTITY_NS ) . list$ ( { userId : query . userId } , function ( err , results ) {
418
420
if ( err ) {
419
421
return done ( err ) ;
420
422
}
@@ -590,7 +592,7 @@ module.exports = function (options) {
590
592
591
593
if ( ! _ . isEmpty ( profile . children ) && ( _ . contains ( profile . userTypes , 'parent-guardian' ) || _ . contains ( profile . user . roles , 'cdf-admin' ) ) ) {
592
594
async . each ( profile . children , function ( child , callback ) {
593
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . list$ ( { userId : child } , function ( err , results ) {
595
+ seneca . make$ ( ENTITY_NS ) . list$ ( { userId : child } , function ( err , results ) {
594
596
if ( err ) {
595
597
return callback ( err ) ;
596
598
}
@@ -618,7 +620,7 @@ module.exports = function (options) {
618
620
619
621
if ( ! _ . isEmpty ( profile . parents ) ) {
620
622
async . each ( profile . parents , function ( parent , callback ) {
621
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . list$ ( { userId : parent } , function ( err , results ) {
623
+ seneca . make$ ( ENTITY_NS ) . list$ ( { userId : parent } , function ( err , results ) {
622
624
if ( err ) {
623
625
return callback ( err ) ;
624
626
}
@@ -649,7 +651,7 @@ module.exports = function (options) {
649
651
var missingKeys = _ . difference ( requiredProfileFields , profileKeys ) ;
650
652
if ( _ . isEmpty ( missingKeys ) ) profile . requiredFieldsComplete = true ;
651
653
652
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . save$ ( profile , done ) ;
654
+ seneca . make$ ( ENTITY_NS ) . save$ ( profile , done ) ;
653
655
}
654
656
655
657
function cmd_invite_parent_guardian ( args , done ) {
@@ -882,7 +884,7 @@ module.exports = function (options) {
882
884
return done ( err ) ;
883
885
}
884
886
885
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . load$ ( profile . id , function ( err , profile ) {
887
+ seneca . make$ ( ENTITY_NS ) . load$ ( profile . id , function ( err , profile ) {
886
888
if ( err ) seneca . log . error ( err ) ;
887
889
888
890
var protocol = process . env . PROTOCOL || 'http' ;
@@ -975,15 +977,19 @@ module.exports = function (options) {
975
977
} ) ;
976
978
}
977
979
980
+ function cmd_load_user_profile ( args , done ) {
981
+ seneca . make$ ( ENTITY_NS ) . load$ ( { userId : args . userId } , done ) ;
982
+ }
983
+
978
984
function cmd_load ( args , done ) {
979
- seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) . load$ ( args . id , done ) ;
985
+ seneca . make$ ( ENTITY_NS ) . load$ ( args . id , done ) ;
980
986
}
981
987
982
988
function cmd_list ( args , done ) {
983
989
var query = args . query || { } ;
984
990
if ( ! query . limit$ ) query . limit$ = 'NULL' ;
985
991
986
- var profilesEntity = seneca . make$ ( PARENT_GUARDIAN_PROFILE_ENTITY ) ;
992
+ var profilesEntity = seneca . make$ ( ENTITY_NS ) ;
987
993
profilesEntity . list$ ( query , done ) ;
988
994
}
989
995
0 commit comments