6956-2410_devTest #2112

Merged
alexm merged 150 commits from 6956-2410_devTest into test 2024-02-29 09:17:58 +00:00
2 changed files with 35 additions and 1 deletions
Showing only changes of commit ce3da6841c - Show all commits

View File

@ -35,11 +35,12 @@
}
},
"auth:after": {
"./middleware/validate-model": {},
"./middleware/current-user": {},
"./middleware/salix-version": {}
},
"parse": {
"body-parser#json":{}
"body-parser#json":{}
},
"routes": {
"loopback#rest": {

View File

@ -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();
};
};