Created
May 4, 2018 09:15
-
-
Save ClementWalter/c7ebb049c7d3bf2fe46651769d1efc7d to your computer and use it in GitHub Desktop.
The UserStamp mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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