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

Commit 7bd319d

Browse files
DanielBriertonWardormeur
authored andcommitted
Gracefully handle when child/parent profile isn't found
1 parent b8216b7 commit 7bd319d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/users/is-parent-of.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ function isParentOf (args, cb) {
3333
seneca.log.error(seneca.customValidatorLogFormatter('cd-profiles', 'isParentOf', err, {userId: userId, childrenId: childrenId}));
3434
return done(null, false);
3535
}
36-
return done(null, _.includes(user.children, childrenId));
36+
if (user && user.children) {
37+
return done(null, _.includes(user.children, childrenId));
38+
} else {
39+
return done(null, false);
40+
}
3741
});
3842
},
3943
childHasParent: function (done) {
@@ -43,7 +47,11 @@ function isParentOf (args, cb) {
4347
seneca.log.error(seneca.customValidatorLogFormatter('cd-profiles', 'isParentOf', err, {userId: userId, childrenId: childrenId}));
4448
return done(null, false);
4549
}
46-
return done(null, _.includes(user.parents, userId));
50+
if (user && user.parents) {
51+
return done(null, _.includes(user.parents, userId));
52+
} else {
53+
return done(null, false);
54+
}
4755
});
4856
}
4957
}, function (err, results) {

0 commit comments

Comments
 (0)