diff --git a/db/changes/231401/00-aclClientInforma.sql b/db/changes/231601/00-aclClientInforma.sql
similarity index 100%
rename from db/changes/231401/00-aclClientInforma.sql
rename to db/changes/231601/00-aclClientInforma.sql
diff --git a/db/changes/231401/00-clientInforma.sql b/db/changes/231601/00-clientInforma.sql
similarity index 85%
rename from db/changes/231401/00-clientInforma.sql
rename to db/changes/231601/00-clientInforma.sql
index 25405ef4d..9bf757fc3 100644
--- a/db/changes/231401/00-clientInforma.sql
+++ b/db/changes/231601/00-clientInforma.sql
@@ -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)';
diff --git a/modules/client/back/methods/client/setRating.js b/modules/client/back/methods/client/setRating.js
new file mode 100644
index 000000000..06e7ebf1e
--- /dev/null
+++ b/modules/client/back/methods/client/setRating.js
@@ -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;
+ }
+ };
+};
diff --git a/modules/client/back/models/client-methods.js b/modules/client/back/models/client-methods.js
index 3538dbeb8..3b1a588ac 100644
--- a/modules/client/back/models/client-methods.js
+++ b/modules/client/back/models/client-methods.js
@@ -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);
};
diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js
index 579c6a8d4..94c583dcc 100644
--- a/modules/client/back/models/client.js
+++ b/modules/client/back/models/client.js
@@ -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,
diff --git a/modules/client/front/credit-management/index.html b/modules/client/front/credit-management/index.html
index 78cc6edb5..85ecb1f96 100644
--- a/modules/client/front/credit-management/index.html
+++ b/modules/client/front/credit-management/index.html
@@ -1,11 +1,11 @@
-