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