Bug #331 Revisar los ACL en back-end
This commit is contained in:
parent
dce8d16077
commit
ef9b72b78c
|
@ -1,4 +1,4 @@
|
|||
<mg-ajax path="/client/api/Clients/{{patch.params.id}}" options="vnPatch"></mg-ajax>
|
||||
<mg-ajax path="/client/api/Clients/{{patch.params.id}}/updateBasicData" options="vnPatch"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.client"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<mg-ajax path="/client/api/Clients/{{patch.params.id}}" options="vnPatch"></mg-ajax>
|
||||
<mg-ajax path="/client/api/Clients/{{patch.params.id}}/updateBillingData" options="vnPatch"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.client"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<mg-ajax path="/client/api/Clients/{{patch.params.id}}" options="vnPatch"></mg-ajax>
|
||||
<mg-ajax path="/client/api/Clients/{{patch.params.id}}/updateFiscalData/" options="vnPatch"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.client"
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('updateBasicData', {
|
||||
description: 'Updates billing data of a client',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'data',
|
||||
type: 'Object',
|
||||
required: true,
|
||||
description: 'Params to update',
|
||||
http: {source: 'body'}
|
||||
}, {
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Model id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'Worker',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/updateBasicData`,
|
||||
verb: 'PATCH'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateBasicData = async(params, id) => {
|
||||
let validUpdateParams = ['id', 'name', 'email', 'phone', 'mobile', 'salesPerson', 'contactChanelFk'];
|
||||
for (const key in params) {
|
||||
if (validUpdateParams.indexOf(key) === -1)
|
||||
throw new Error(`You don't have enough privileges to do that`);
|
||||
}
|
||||
|
||||
return await Self.app.models.Client.update({id: id}, params);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,53 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateBillingData', {
|
||||
description: 'Updates billing data of a client',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'data',
|
||||
type: 'Object',
|
||||
required: true,
|
||||
description: 'Params to update',
|
||||
http: {source: 'body'}
|
||||
}, {
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Model id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'Worker',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/updateBillingData`,
|
||||
verb: 'PATCH'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateBillingData = async(ctx, params, id) => {
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let isAdministrative = await Self.app.models.Account.hasRole(userId, 'administrative');
|
||||
|
||||
let [taxData] = await Self.app.models.Client.find({where: {id: id}, fields: ['isTaxDataChecked']});
|
||||
if (!isAdministrative && taxData.isTaxDataChecked)
|
||||
throw new Error(`You don't have enough privileges to do that`);
|
||||
|
||||
let validUpdateParams = [
|
||||
'payMethodFk',
|
||||
'dueDay',
|
||||
'iban',
|
||||
'hasLcr',
|
||||
'hasCoreVnl',
|
||||
'hasSepaVnl'
|
||||
];
|
||||
|
||||
for (const key in params) {
|
||||
if (validUpdateParams.indexOf(key) === -1)
|
||||
throw new Error(`You don't have enough privileges to do that`);
|
||||
}
|
||||
|
||||
return await Self.app.models.Client.update({id: id}, params);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,64 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateFiscalData', {
|
||||
description: 'Updates billing data of a client',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'data',
|
||||
type: 'Object',
|
||||
required: true,
|
||||
description: 'Params to update',
|
||||
http: {source: 'body'}
|
||||
}, {
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Model id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
arg: 'res',
|
||||
type: 'String',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/updateFiscalData`,
|
||||
verb: 'PATCH'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateFiscalData = async(ctx, params, id) => {
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let isAdministrative = await Self.app.models.Account.hasRole(userId, 'administrative');
|
||||
|
||||
let [taxData] = await Self.app.models.Client.find({where: {id: id}, fields: ['isTaxDataChecked']});
|
||||
if (!isAdministrative && taxData.isTaxDataChecked)
|
||||
throw new Error(`You don't have enough privileges to do that`);
|
||||
|
||||
let validUpdateParams = [
|
||||
'id',
|
||||
'socialName',
|
||||
'fi',
|
||||
'street',
|
||||
'postcode',
|
||||
'city',
|
||||
'countryFk',
|
||||
'provinceFk',
|
||||
'isActive',
|
||||
'isFreezed',
|
||||
'hasToInvoice',
|
||||
'isVies',
|
||||
'isToBeMailed',
|
||||
'hasToInvoiceByAddress',
|
||||
'isEqualizated',
|
||||
'isTaxDataVerified'
|
||||
];
|
||||
|
||||
for (const key in params) {
|
||||
if (validUpdateParams.indexOf(key) === -1)
|
||||
throw new Error(`You don't have enough privileges to do that`);
|
||||
}
|
||||
|
||||
params.id = id;
|
||||
return await Self.app.models.Client.update({id: id}, params);
|
||||
};
|
||||
};
|
|
@ -37,10 +37,14 @@ module.exports = Self => {
|
|||
}
|
||||
}],
|
||||
fields: ['id', 'clientFk']
|
||||
}).catch(e => {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
let componentToUse;
|
||||
let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket[0].client().salesPersonFk}, fields: 'amount'});
|
||||
let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket[0].client().salesPersonFk}, fields: 'amount'}).catch(e => {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
if (usesMana)
|
||||
componentToUse = 37;
|
||||
|
@ -48,15 +52,23 @@ module.exports = Self => {
|
|||
componentToUse = 34;
|
||||
|
||||
for (let i = 0; i < params.editLines.length; i++) {
|
||||
let currentLine = await model.Sale.findOne({where: {id: params.editLines[i].id}, fields: 'price'});
|
||||
let currentLine = await model.Sale.findOne({where: {id: params.editLines[i].id}, fields: 'price'}).catch(e => {
|
||||
console.log(e);
|
||||
});
|
||||
let value = (-currentLine.price * params.editLines[i].discount / 100);
|
||||
await model.SaleComponent.upsert({saleFk: params.editLines[i].id, value: value, componentFk: componentToUse});
|
||||
await model.SaleComponent.upsert({saleFk: params.editLines[i].id, value: value, componentFk: componentToUse}).catch(e => {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
await model.Sale.update({id: params.editLines[i].id}, {discount: params.editLines[i].discount});
|
||||
await model.Sale.update({id: params.editLines[i].id}, {discount: params.editLines[i].discount}).catch(e => {
|
||||
console.log(e);
|
||||
});
|
||||
}
|
||||
|
||||
query = `
|
||||
call vn.manaSpellersRequery(?)`;
|
||||
await Self.rawSql(query, [ticket[0].client().salesPersonFk]);
|
||||
await Self.rawSql(query, [ticket[0].client().salesPersonFk]).catch(e => {
|
||||
console.log(e);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -18,6 +18,9 @@ module.exports = Self => {
|
|||
require('../methods/client/getMana')(Self);
|
||||
require('../methods/client/getAverageInvoiced')(Self);
|
||||
require('../methods/client/summary')(Self);
|
||||
require('../methods/client/updateFiscalData')(Self);
|
||||
require('../methods/client/updateBillingData')(Self);
|
||||
require('../methods/client/updateBasicData')(Self);
|
||||
|
||||
// Validations
|
||||
|
||||
|
|
Loading…
Reference in New Issue