Skip to content

Instantly share code, notes, and snippets.

@ClementWalter
Created May 4, 2018 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClementWalter/c7ebb049c7d3bf2fe46651769d1efc7d to your computer and use it in GitHub Desktop.
Save ClementWalter/c7ebb049c7d3bf2fe46651769d1efc7d to your computer and use it in GitHub Desktop.
The UserStamp mixin
'use strict';
const utils = require('./utils');
module.exports = function(Model, bootOptions) {
const options = Object.assign(
{
creatorId: 'creatorId',
required: true,
},
bootOptions
);
Model.dataSource.defineRelations(Model, {
creator: {
type: 'belongsTo',
model: 'user',
foreignKey: options.creatorId,
},
});
Model.beforeRemote('**', utils.addUserInfoToOptions);
Model.observe('before save', utils.addUserInfoToInstance(options));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment