Default values for blueprint create
and update
actions.
Note: Before using
req.options.value
, confirm that it exists and create it if necessary.
To default to using the logged-in user’s name when creating a new record:
// In config/policies/createWithUserName.js
module.exports = function createWithUserName (req, res, next) {
if (req.session.user) {
// Use existing req.options.values, or initialize it to an empty object
req.options.values = req.options.values || {};
// Set the default `name` for "create" and "updates" blueprints
req.options.values.name = req.session.user.name;
}
return next();
}
Then apply this policy to the desired blueprint actions.