Merge pull request 'Remove manager restriction to edit client credits' (#483) from 2679-client_credit_change into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #483
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2020-12-17 15:54:43 +00:00
commit d347fcb997
1 changed files with 0 additions and 23 deletions

View File

@ -339,28 +339,5 @@ module.exports = Self => {
if (count <= 0)
throw new UserError('The role cannot set this credit amount');
// Si se puso a 0 por gerencia, solo gerencia puede aumentarlo
let query = 'SELECT * FROM clientCredit WHERE clientFk = ? ORDER BY created DESC LIMIT 1';
let instances = await Self.rawSql(query, [finalState.id]);
if (instances.length !== 1 || instances[0].amount > 0)
return;
query = `
SELECT COUNT(*) AS hasRoleManager
FROM worker em
JOIN account.user ac ON ac.id = em.userFk
JOIN salix.RoleMapping rm ON rm.principalId = ac.id
JOIN account.role r on r.id = rm.roleId
WHERE em.id = ?
AND rm.principalType = 'USER'
AND r.name = 'manager'`;
let instance = await Self.rawSql(query, [instances[0].workerFk]);
if (instance[0].hasRoleManager)
throw new UserError('Only manager can change the credit');
}
};