add restrictions in claim detail
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
9d80ec11af
commit
b33f42d05e
|
@ -84,6 +84,7 @@
|
|||
"NO_AGENCY_AVAILABLE": "No hay una zona de reparto disponible con estos parámetros",
|
||||
"ERROR_PAST_SHIPMENT": "No puedes seleccionar una fecha de envío en pasado",
|
||||
"The current ticket can't be modified": "El ticket actual no puede ser modificado",
|
||||
"The current claim can't be modified": "La reclamación actual no puede ser modificada",
|
||||
"The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas",
|
||||
"Please select at least one sale": "Por favor selecciona al menos una linea",
|
||||
"All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket",
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('isEditable', {
|
||||
description: 'Check if a claim is editable',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'the claim id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/isEditable`,
|
||||
verb: 'get'
|
||||
}
|
||||
});
|
||||
|
||||
Self.isEditable = async(ctx, id) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant');
|
||||
|
||||
let claim = await Self.app.models.Claim.findById(id, {
|
||||
fields: ['claimStateFk'],
|
||||
include: [{
|
||||
relation: 'claimState'
|
||||
}]
|
||||
});
|
||||
|
||||
const isClaimResolved = claim && claim.claimState().code == 'resolved';
|
||||
|
||||
if (!claim || (isClaimResolved && !isSalesAssistant))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('claim isEditable()', () => {
|
||||
const salesPerdonId = 18;
|
||||
const salesAssistantId = 21;
|
||||
it('should return false if the given claim does not exist', async() => {
|
||||
let ctx = {req: {accessToken: {userId: salesAssistantId}}};
|
||||
let result = await app.models.Claim.isEditable(ctx, 99999);
|
||||
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
||||
it('should not be able to edit a resolved claim for a salesPerson', async() => {
|
||||
let ctx = {req: {accessToken: {userId: salesPerdonId}}};
|
||||
let result = await app.models.Claim.isEditable(ctx, 4);
|
||||
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
||||
it('should be able to edit a resolved claim for a salesAssistant', async() => {
|
||||
let ctx = {req: {accessToken: {userId: salesAssistantId}}};
|
||||
let result = await app.models.Claim.isEditable(ctx, 4);
|
||||
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
it('should be able to edit a claim for a salesAssistant', async() => {
|
||||
let ctx = {req: {accessToken: {userId: salesPerdonId}}};
|
||||
let result = await app.models.Claim.isEditable(ctx, 1);
|
||||
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
});
|
|
@ -1,7 +1,28 @@
|
|||
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
module.exports = Self => {
|
||||
require('../methods/claim-beginning/importToNewRefundTicket')(Self);
|
||||
|
||||
Self.validatesUniquenessOf('saleFk', {
|
||||
message: `A claim with that sale already exists`
|
||||
});
|
||||
Self.observe('before save', async ctx => {
|
||||
if (ctx.isNewInstance) return;
|
||||
await claimIsEditable(ctx);
|
||||
});
|
||||
Self.observe('before delete', async ctx => {
|
||||
if (ctx.isNewInstance) return;
|
||||
await claimIsEditable(ctx);
|
||||
});
|
||||
|
||||
async function claimIsEditable(ctx) {
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
const httpCtx = {req: loopBackContext.active};
|
||||
const isEditable = await Self.app.models.Claim.isEditable(httpCtx, ctx.where.id);
|
||||
|
||||
if (!isEditable)
|
||||
throw new UserError(`The current claim can't be modified`);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,4 +6,5 @@ module.exports = Self => {
|
|||
require('../methods/claim/regularizeClaim')(Self);
|
||||
require('../methods/claim/uploadFile')(Self);
|
||||
require('../methods/claim/updateClaimAction')(Self);
|
||||
require('../methods/claim/isEditable')(Self);
|
||||
};
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<vn-input-number
|
||||
min="0"
|
||||
step="1"
|
||||
disabled="!$ctrl.isRewritable"
|
||||
ng-model="saleClaimed.quantity"
|
||||
on-change="$ctrl.setClaimedQuantity(saleClaimed.id, saleClaimed.quantity)"
|
||||
class="dense">
|
||||
|
@ -66,6 +67,7 @@
|
|||
<vn-td shrink>
|
||||
<vn-icon-button
|
||||
vn-tooltip="Remove sale"
|
||||
ng-if ="$ctrl.isRewritable"
|
||||
icon="delete"
|
||||
ng-click="$ctrl.deleteClaimedSale($index)"
|
||||
tabindex="-1">
|
||||
|
@ -76,9 +78,13 @@
|
|||
</vn-table>
|
||||
</vn-card>
|
||||
</vn-data-viewer>
|
||||
<a ng-click="$ctrl.openAddSalesDialog()" vn-tooltip="Add sale item" vn-bind="+" fixed-bottom-right>
|
||||
<vn-float-button icon="add"></vn-float-button>
|
||||
</a>
|
||||
<vn-float-button
|
||||
icon="add"
|
||||
ng-if="$ctrl.isRewritable"
|
||||
ng-click="$ctrl.openAddSalesDialog()"
|
||||
vn-tooltip="Add sale item" vn-bind="+"
|
||||
fixed-bottom-right>
|
||||
</vn-float-button>
|
||||
<!-- Add Lines Dialog -->
|
||||
<vn-dialog vn-id="add-sales" class="modal-form">
|
||||
<tpl-title>
|
||||
|
|
|
@ -133,6 +133,12 @@ class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
isClaimEditable() {
|
||||
this.$http.get(`Claims/${this.claim.id}/isEditable`).then(res => {
|
||||
this.isRewritable = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
updateDiscount() {
|
||||
const claimedSale = this.saleClaimed.sale;
|
||||
if (this.newDiscount != claimedSale.discount) {
|
||||
|
|
Loading…
Reference in New Issue