6956-2410_devTest #2112
|
@ -35,11 +35,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"auth:after": {
|
"auth:after": {
|
||||||
|
"./middleware/validate-model": {},
|
||||||
"./middleware/current-user": {},
|
"./middleware/current-user": {},
|
||||||
"./middleware/salix-version": {}
|
"./middleware/salix-version": {}
|
||||||
},
|
},
|
||||||
"parse": {
|
"parse": {
|
||||||
"body-parser#json":{}
|
"body-parser#json":{}
|
||||||
},
|
},
|
||||||
"routes": {
|
"routes": {
|
||||||
"loopback#rest": {
|
"loopback#rest": {
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
const validatorBodyModel = require('../../../modules/client/back/methods/client/body_model_validator');
|
||||||
|
const makeSingular = s => {
|
||||||
|
if (s == null || s.length == 0)
|
||||||
|
return s;
|
||||||
|
|
||||||
|
return s.substring(0, s.length - 1);
|
||||||
|
};
|
||||||
|
function blobToB64(data) {
|
||||||
|
return new Uint8Array(data).reduce(function(data, byte) {
|
||||||
|
return data + String.fromCharCode(byte);
|
||||||
|
}, '');
|
||||||
|
}
|
||||||
|
module.exports = function(options) {
|
||||||
|
return function(req, res, next) {
|
||||||
|
const {method, originalUrl} = req;
|
||||||
|
if (['GET', 'DELETE'].includes(method)) return next();
|
||||||
|
let [module, id, path] = originalUrl.split('api/')[1].split('/');
|
||||||
|
|
||||||
|
let model = models[module];
|
||||||
|
if (!model) {
|
||||||
|
module = makeSingular(module);
|
||||||
|
model = models[module];
|
||||||
|
}
|
||||||
|
const properties = model.definition.rawProperties;
|
||||||
|
const data = JSON.parse(blobToB64(req.readableBuffer.tail.data));
|
||||||
|
let isValid = validatorBodyModel(properties, data);
|
||||||
|
|
||||||
|
if (!isValid.isValid)
|
||||||
|
next();
|
||||||
|
return next();
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue