summaryrefslogtreecommitdiff
path: root/src/services/user/hooks/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/user/hooks/index.js')
-rw-r--r--src/services/user/hooks/index.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/services/user/hooks/index.js b/src/services/user/hooks/index.js
index 85f8e04..c4ed466 100644
--- a/src/services/user/hooks/index.js
+++ b/src/services/user/hooks/index.js
@@ -69,6 +69,21 @@ function validateRoleOnUpdate () {
}
}
+function removeUserMeals () {
+ return function(hook) {
+ var _this = this;
+
+ return new Promise(function (resolve, reject) {
+ // Set provider as undefined so we avoid an infinite loop if this hook is
+ // set on the resource we are requesting.
+ var params = Object.assign({}, hook.params, { provider: undefined });
+ return hook.app.service('meals').remove(null, { userid: hook.userid }).then(function (data) {
+ resolve(hook);
+ }).catch(reject);
+ });
+ }
+}
+
const roleConfig = {
fieldName: 'role',
roles: ['manager','admin'],
@@ -112,6 +127,7 @@ exports.before = {
auth.populateUser(),
auth.restrictToAuthenticated(),
validateRoleOnUpdate(),
+ removeUserMeals(),
]
};
@@ -122,7 +138,5 @@ exports.after = {
create: [],
update: [],
patch: [],
- remove: [
- // remove user's meals
- ],
+ remove: [],
};