refs #5128 creado método setRating
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
83dd386eed
commit
4c18efa589
|
@ -13,4 +13,4 @@ CREATE TABLE `vn`.`clientInforma` (
|
|||
KEY `informaClientFk` (`clientFk`),
|
||||
CONSTRAINT `informa_ClienteFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `informa_workers_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
) ENGINE=InnoDB CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='información proporcionada por Informa, se actualiza desde el hook de client (salix)';
|
|
@ -0,0 +1,62 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('setRating', {
|
||||
description: 'Change role and hasGrant if user has setRating',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The user id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'rating',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'recommendedCredit',
|
||||
type: 'number'
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/:id/setRating`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.setRating = async function(ctx, id, rating, recommendedCredit, options) {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const isFinancial = await models.Account.hasRole(userId, 'financial', myOptions);
|
||||
if (!isFinancial)
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
|
||||
const client = await Self.findById(id, null, myOptions);
|
||||
const clientUpdated = await client.updateAttributes({
|
||||
rating: rating,
|
||||
recommendedCredit: recommendedCredit
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return clientUpdated;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -47,4 +47,5 @@ module.exports = Self => {
|
|||
require('../methods/client/consumptionSendQueued')(Self);
|
||||
require('../methods/client/filter')(Self);
|
||||
require('../methods/client/getClientOrSupplierReference')(Self);
|
||||
require('../methods/client/setRating')(Self);
|
||||
};
|
||||
|
|
|
@ -447,44 +447,8 @@ module.exports = Self => {
|
|||
|
||||
Self.changeCreditManagement = async function changeCreditManagement(ctx, finalState, changes) {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.options.accessToken.userId;
|
||||
|
||||
// const isFinancialBoss = await models.Account.hasRole(userId, 'financialBoss', ctx.options);
|
||||
// if (!isFinancialBoss) {
|
||||
// const lastCredit = await models.ClientCredit.findOne({
|
||||
// where: {
|
||||
// clientFk: finalState.id
|
||||
// },
|
||||
// order: 'id DESC'
|
||||
// }, ctx.options);
|
||||
|
||||
// const lastAmount = lastCredit && lastCredit.amount;
|
||||
// const lastWorkerId = lastCredit && lastCredit.workerFk;
|
||||
// const lastWorkerIsFinancialBoss = await models.Account.hasRole(lastWorkerId, 'financialBoss', ctx.options);
|
||||
|
||||
// if (lastAmount == 0 && lastWorkerIsFinancialBoss)
|
||||
// throw new UserError(`You can't change the credit set to zero from a financialBoss`);
|
||||
|
||||
// const creditLimits = await models.ClientCreditLimit.find({
|
||||
// fields: ['roleFk'],
|
||||
// where: {
|
||||
// maxAmount: {gte: changes.credit}
|
||||
// }
|
||||
// }, ctx.options);
|
||||
|
||||
// const requiredRoles = [];
|
||||
// for (limit of creditLimits)
|
||||
// requiredRoles.push(limit.roleFk);
|
||||
|
||||
// const userRequiredRoles = await models.RoleMapping.count({
|
||||
// roleId: {inq: requiredRoles},
|
||||
// principalType: 'USER',
|
||||
// principalId: userId
|
||||
// }, ctx.options);
|
||||
|
||||
// if (userRequiredRoles <= 0)
|
||||
// throw new UserError(`You don't have enough privileges to set this credit amount`);
|
||||
// }
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
const userId = loopBackContext.active.accessToken.userId;
|
||||
|
||||
await models.ClientInforma.create({
|
||||
clientFk: finalState.id,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<mg-ajax path="Clients/{{patch.params.id}}" options="vnPatch"></mg-ajax>
|
||||
<mg-ajax path="Clients/{{post.params.id}}/setRating" options="vnPost"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
url="Clients"
|
||||
data="$ctrl.client"
|
||||
id-value="$ctrl.$params.id"
|
||||
form="form"
|
||||
save="patch">
|
||||
save="post">
|
||||
</vn-watcher>
|
||||
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
|
||||
<vn-card class="vn-pa-lg">
|
||||
|
@ -37,6 +37,7 @@
|
|||
</vn-button-bar>
|
||||
</form>
|
||||
|
||||
|
||||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="ClientInformas"
|
||||
|
|
|
@ -65,3 +65,5 @@ Amount to return: Cantidad a devolver
|
|||
Delivered amount: Cantidad entregada
|
||||
Unpaid: Impagado
|
||||
Credit management: Gestión de crédito
|
||||
Credit opinion: Opinión de crédito
|
||||
|
||||
|
|
|
@ -23,6 +23,14 @@
|
|||
{"state": "client.card.recovery.index", "icon": "icon-recovery"},
|
||||
{"state": "client.card.webAccess", "icon": "cloud"},
|
||||
{"state": "client.card.log", "icon": "history"},
|
||||
{
|
||||
"description": "Credit management",
|
||||
"icon": "monetization_on",
|
||||
"childs": [
|
||||
{"state": "client.card.creditInsurance.index", "icon": "icon-solunion"},
|
||||
{"state": "client.card.creditManagement", "icon": "contact_support"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Others",
|
||||
"icon": "more",
|
||||
|
@ -30,12 +38,10 @@
|
|||
{"state": "client.card.sample.index", "icon": "mail"},
|
||||
{"state": "client.card.consumption", "icon": "show_chart"},
|
||||
{"state": "client.card.mandate", "icon": "pan_tool"},
|
||||
{"state": "client.card.creditInsurance.index", "icon": "icon-solunion"},
|
||||
{"state": "client.card.contact", "icon": "contact_phone"},
|
||||
{"state": "client.card.webPayment", "icon": "icon-onlinepayment"},
|
||||
{"state": "client.card.dms.index", "icon": "cloud_upload"},
|
||||
{"state": "client.card.unpaid", "icon": "icon-defaulter"},
|
||||
{"state": "client.card.creditManagement", "icon": "contact_support"}
|
||||
{"state": "client.card.unpaid", "icon": "icon-defaulter"}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -436,7 +442,7 @@
|
|||
"state": "client.card.creditManagement",
|
||||
"component": "vn-client-credit-management",
|
||||
"acl": ["financial"],
|
||||
"description": "Credit management"
|
||||
"description": "Credit opinion"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue