This commit is contained in:
parent
4032bde243
commit
7eea9d1d2c
|
@ -19,8 +19,8 @@ module.exports = Self => {
|
|||
next();
|
||||
});
|
||||
|
||||
Self.remoteMethod('getCurrentUserName', {
|
||||
description: 'Gets the current user name',
|
||||
Self.remoteMethod('getCurrentUserData', {
|
||||
description: 'Gets the current user data',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'context',
|
||||
|
@ -31,21 +31,22 @@ module.exports = Self => {
|
|||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'string',
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
verb: 'GET',
|
||||
path: '/getCurrentUserName'
|
||||
path: '/getCurrentUserData'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getCurrentUserName = async function(ctx) {
|
||||
Self.getCurrentUserData = async function(ctx) {
|
||||
let filter = {fields: ['name']};
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let account = await Self.findById(userId, filter);
|
||||
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}, fields: ['id']});
|
||||
|
||||
return account.name;
|
||||
return {accountName: account.name, workerId: worker.id};
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,17 +30,6 @@ describe('Ticket Create new tracking state path', () => {
|
|||
expect(result).toEqual('State cannot be blank');
|
||||
});
|
||||
|
||||
it(`should attempt create a new state then clear and save it`, async() => {
|
||||
let result = await nightmare
|
||||
.autocompleteSearch(selectors.createStateView.stateAutocomplete, '¿Fecha?')
|
||||
.waitToClick(selectors.createStateView.clearStateInputButton)
|
||||
.waitToClick(selectors.createStateView.saveStateButton)
|
||||
.waitForLastSnackbar();
|
||||
|
||||
expect(result).toEqual('State cannot be blank');
|
||||
});
|
||||
|
||||
|
||||
it(`should create a new state`, async() => {
|
||||
let result = await nightmare
|
||||
.autocompleteSearch(selectors.createStateView.stateAutocomplete, '¿Fecha?')
|
||||
|
@ -77,18 +66,16 @@ describe('Ticket Create new tracking state path', () => {
|
|||
expect(result).toEqual(`You don't have enough privileges`);
|
||||
});
|
||||
|
||||
it(`should attempt to create an state for the type salesPerson has rights but fail as worker is blank`, async() => {
|
||||
it(`should make sure the worker gets autocomplete uppon selecting the assigned state`, async() => {
|
||||
let result = await nightmare
|
||||
.autocompleteSearch(selectors.createStateView.stateAutocomplete, 'asignado')
|
||||
.waitToClick(selectors.createStateView.saveStateButton)
|
||||
.waitForLastSnackbar();
|
||||
.waitToGetProperty(`${selectors.createStateView.workerAutocomplete} input`, 'value');
|
||||
|
||||
expect(result).toEqual(`Worker cannot be blank`);
|
||||
expect(result).toEqual('salesPersonNick');
|
||||
});
|
||||
|
||||
it(`should create a new state with all it's data`, async() => {
|
||||
it(`should succesfully create a valid state`, async() => {
|
||||
let result = await nightmare
|
||||
.autocompleteSearch(selectors.createStateView.workerAutocomplete, 'replenisher')
|
||||
.waitToClick(selectors.createStateView.saveStateButton)
|
||||
.waitForLastSnackbar();
|
||||
|
||||
|
|
|
@ -69,14 +69,6 @@ describe('Ticket Summary path', () => {
|
|||
expect(exists).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should click on the SET OK button and throw a privileges error', async() => {
|
||||
let result = await nightmare
|
||||
.waitToClick(selectors.ticketSummary.setOk)
|
||||
.waitForLastSnackbar();
|
||||
|
||||
expect(result).toEqual(`You don't have enough privileges`);
|
||||
});
|
||||
|
||||
it('should log in as production then navigate to the summary of the same ticket', async() => {
|
||||
let url = await nightmare
|
||||
.loginAndModule('production', 'ticket')
|
||||
|
|
|
@ -16,9 +16,10 @@ export default class MainMenu {
|
|||
}
|
||||
|
||||
getCurrentUserName() {
|
||||
this.$http.get('/api/Accounts/getCurrentUserName')
|
||||
this.$http.get('/api/Accounts/getCurrentUserData')
|
||||
.then(json => {
|
||||
this.$.currentUserName = json.data;
|
||||
this.$.currentUserName = json.data.accountName;
|
||||
window.localStorage.currentUserWorkerId = json.data.workerId;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -35,29 +35,24 @@ module.exports = Self => {
|
|||
params.stateFk = state.id;
|
||||
}
|
||||
|
||||
let isProduction = await models.Account.hasRole(userId, 'production');
|
||||
let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
|
||||
if (!params.workerFk) {
|
||||
let worker = await models.Worker.findOne({where: {userFk: userId}});
|
||||
params.workerFk = worker.id;
|
||||
}
|
||||
|
||||
let ticket = await models.TicketState.findById(
|
||||
params.ticketFk,
|
||||
{fields: ['stateFk']}
|
||||
);
|
||||
|
||||
let oldState = await models.State.findById(ticket.stateFk);
|
||||
let newState = await models.State.findById(params.stateFk);
|
||||
let oldStateAllowed = await models.State.isEditable(ctx, ticket.stateFk);
|
||||
let newStateAllowed = await models.State.isEditable(ctx, params.stateFk);
|
||||
|
||||
let isAllowed = isProduction || isSalesPerson
|
||||
&& oldState.isEditable()
|
||||
&& newState.isEditable();
|
||||
let isAllowed = oldStateAllowed && newStateAllowed;
|
||||
|
||||
if (!isAllowed)
|
||||
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
||||
|
||||
if (newState.code != 'PICKER_DESIGNED') {
|
||||
let worker = await models.Worker.findOne({where: {userFk: userId}});
|
||||
params.workerFk = worker.id;
|
||||
}
|
||||
|
||||
return await models.TicketTracking.create(params);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -31,24 +31,9 @@ describe('ticket changeState()', () => {
|
|||
expect(errCode).toBe('ACCESS_DENIED');
|
||||
});
|
||||
|
||||
it('should throw an error if the state is assigned and theres not worker in params', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 18}}};
|
||||
let assignedState = await app.models.State.findOne({where: {code: 'PICKER_DESIGNED'}});
|
||||
let params = {ticketFk: 11, stateFk: assignedState.id};
|
||||
|
||||
let errCode;
|
||||
try {
|
||||
await app.models.TicketTracking.changeState(ctx, params);
|
||||
} catch (e) {
|
||||
errCode = e.details.codes.workerFk[0];
|
||||
}
|
||||
|
||||
expect(errCode).toEqual('presence');
|
||||
});
|
||||
|
||||
it('should throw an error if a worker thats not production tries to change the state to one thats not assigned', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 110}}};
|
||||
let params = {ticketFk: 11, stateFk: 3};
|
||||
it('should throw an error if a worker with employee role attemps to a forbidden state', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 1}}};
|
||||
let params = {ticketFk: 11, stateFk: 13};
|
||||
|
||||
let errCode;
|
||||
try {
|
||||
|
@ -72,7 +57,7 @@ describe('ticket changeState()', () => {
|
|||
expect(res.__data.id).toBeDefined();
|
||||
});
|
||||
|
||||
it('return an array with the created ticket tracking line', async() => {
|
||||
it('should return an array with the created ticket tracking line', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 49}}};
|
||||
let params = {ticketFk: ticket.id, stateFk: 3};
|
||||
let res = await app.models.TicketTracking.changeState(ctx, params);
|
||||
|
@ -83,7 +68,7 @@ describe('ticket changeState()', () => {
|
|||
expect(res.__data.id).toBeDefined();
|
||||
});
|
||||
|
||||
it('return an array with the created ticket tracking line when the user is salesperson, uses the state assigned and thes a workerFk given', async() => {
|
||||
it('should return an array with the created ticket tracking line when the user is salesperson, uses the state assigned and thes a workerFk given', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 18}}};
|
||||
let assignedState = await app.models.State.findOne({where: {code: 'PICKER_DESIGNED'}});
|
||||
let params = {ticketFk: ticket.id, stateFk: assignedState.id, workerFk: 1};
|
||||
|
|
|
@ -17,8 +17,4 @@ module.exports = Self => {
|
|||
);
|
||||
return result[0].alertLevel == 0;
|
||||
};
|
||||
|
||||
Self.prototype.isEditable = function() {
|
||||
return this.code == 'PICKER_DESIGNED' || this.alertLevel == 0;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -73,7 +73,7 @@ Volume: Volumen
|
|||
Expedition: Expedición
|
||||
New state: Nuevo estado
|
||||
Packages: Embalajes
|
||||
Tracking: Revisión
|
||||
Tracking: Estados
|
||||
Sale checked: Control clientes
|
||||
Components: Componentes
|
||||
Sale tracking: Líneas preparadas
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
</vn-autocomplete>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
url="/client/api/Clients/activeWorkersWithRole"
|
||||
ng-if="$ctrl.isPickerDesignedState"
|
||||
field="$ctrl.workerFk"
|
||||
url="/client/api/Clients/activeWorkersWithRole"
|
||||
show-field="nickname"
|
||||
search-function="{firstName: $search}"
|
||||
value-field="id"
|
||||
|
|
|
@ -20,6 +20,7 @@ class Controller {
|
|||
set stateFk(value) {
|
||||
this.params.stateFk = value;
|
||||
this.isPickerDesignedState = this.getIsPickerDesignedState(value);
|
||||
this.workerFk = window.localStorage.currentUserWorkerId;
|
||||
}
|
||||
|
||||
get stateFk() {
|
||||
|
|
Loading…
Reference in New Issue