#5878 - FiscalData validations #1851

Merged
carlossa merged 58 commits from 5858-fiscalData-validations into dev 2024-02-28 13:53:34 +00:00
2 changed files with 76 additions and 65 deletions
Showing only changes of commit 334c5f03a5 - Show all commits

View File

@ -128,9 +128,7 @@ module.exports = Self => {
let tx;
const myOptions = {};
const models = Self.app.models;
const args = ctx.args;
const userId = ctx.req.accessToken.userId;
const $t = ctx.req.__;
const {args, req: {__: $t}} = ctx;
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -1,3 +1,65 @@
const validatorBodyModel = require('../../../../client/back/methods/client/body_model_validator');
const BODY_MODEL = [{
arg: 'name',
type: 'string'
},
{
arg: 'nif',
type: 'string'
},
{
arg: 'account',
type: 'any'
},
{
arg: 'sageTaxTypeFk',
type: 'any'
},
{
arg: 'sageWithholdingFk',
type: 'any'
},
{
arg: 'sageTransactionTypeFk',
type: 'any'
},
{
arg: 'postCode',
type: 'any'
},
{
arg: 'street',
type: 'any'
},
{
arg: 'city',
type: 'string'
},
{
arg: 'provinceFk',
type: 'any'
},
{
arg: 'countryFk',
type: 'any'
},
{
arg: 'supplierActivityFk',
type: 'string'
},
{
arg: 'healthRegister',
type: 'string'
},
{
arg: 'isVies',
type: 'boolean'
},
{
arg: 'isTrucker',
type: 'boolean'
}];
module.exports = Self => {
Self.remoteMethod('updateFiscalData', {
description: 'Updates fiscal data of a supplier',
@ -14,65 +76,11 @@ module.exports = Self => {
http: {source: 'path'}
},
{
arg: 'name',
type: 'string'
},
{
arg: 'nif',
type: 'string'
},
{
arg: 'account',
type: 'any'
},
{
arg: 'sageTaxTypeFk',
type: 'any'
},
{
arg: 'sageWithholdingFk',
type: 'any'
},
{
arg: 'sageTransactionTypeFk',
type: 'any'
},
{
arg: 'postCode',
type: 'any'
},
{
arg: 'street',
type: 'any'
},
{
arg: 'city',
type: 'string'
},
{
arg: 'provinceFk',
type: 'any'
},
{
arg: 'countryFk',
type: 'any'
},
{
arg: 'supplierActivityFk',
type: 'string'
},
{
arg: 'healthRegister',
type: 'string'
},
{
arg: 'isVies',
type: 'boolean'
},
{
arg: 'isTrucker',
type: 'boolean'
}],
arg: 'data',
type: 'object',
http: {source: 'body'}
}
],
returns: {
arg: 'res',
type: 'string',
@ -86,13 +94,18 @@ module.exports = Self => {
Self.updateFiscalData = async(ctx, supplierId) => {
const models = Self.app.models;
const args = ctx.args;
const {args} = ctx;
const supplier = await models.Supplier.findById(supplierId);
// Remove unwanted properties
delete args.ctx;
delete args.id;
return supplier.updateAttributes(args);
const {isValid, tag} = validatorBodyModel(BODY_MODEL, args.data);
if (!isValid) {
const key = $t(`${tag}`);
throw new Error($t('Model is not valid', {key})
);
}
return supplier.updateAttributes(args.data);
};
};