Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Utils for the UserStamp mixin
'use strict';
module.exports = {
addUserInfoToOptions: function(context, unused, next) {
if (!context.req.currentUser || !context.req.currentUser.id) {
const noCurrentUserError = new Error(
'The request does not contain currentUser information'
);
noCurrentUserError.status = 401;
throw noCurrentUserError;
}
context.args.options.creatorId = context.req.currentUser.id;
next();
},
addUserInfoToInstance: function(options) {
return function(context, next) {
if (!options.creatorId) {
const noCurrentUserError = new Error(
'The userStamp mixin does not provides valide options'
);
noCurrentUserError.status = 500;
throw noCurrentUserError;
}
if (context.instance) {
context.instance[options.creatorId] =
context.instance[options.creatorId] || context.options.creatorId;
} else {
context.data[options.creatorId] =
context.data[options.creatorId] || context.options.creatorId;
}
next();
};
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.