I have a situation where I'd like to use Sails' create blueprint on a Model. However, I need to access a session variable on that create:
URL: /api/myModel/create [post]
Model: module.exports = {
adapter: 'mongo',
schema: true,
attributes: {
user: {
model:'user',
required:true,
index:true
},
item: {
model:'item',
required:true,
index:true
},
quantity: {
required:true,
type: 'integer',
defaultsTo: 1,
min: 0
},
size: {
required:true,
type:'string'
},
container: {
required:true,
type:'string'
},
dateManuf: {
required:true,
date:true
}
},
beforeValidation:function(values, next) {
/* I want to automatically set the logged in
USERID here */
next();
}
};
I want to automatically set the value of the logged in user session userid in the field. Do I have to create my own custom route/controller action to do that to properly have access to the "req" field?