ticket.sale editableState
This commit is contained in:
parent
8f519fd15b
commit
2f1472b9ee
|
@ -0,0 +1,36 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('editableStates', {
|
||||
description: 'Gets the editable states according the user role ',
|
||||
accessType: 'READ',
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/editableStates`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.editableStates = async ctx => {
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let models = Self.app.models;
|
||||
let statesList = await models.State.find();
|
||||
|
||||
let isProduction = await models.Account.hasRole(userId, 'production');
|
||||
let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
|
||||
let isAdministrative = await models.Account.hasRole(userId, 'administrative');
|
||||
|
||||
if (isProduction || isAdministrative)
|
||||
return statesList;
|
||||
|
||||
if (isSalesPerson) {
|
||||
return statesList = statesList.filter(stateList =>
|
||||
stateList.alertLevel === 0 || stateList.code === 'PICKER_DESIGNED'
|
||||
);
|
||||
}
|
||||
|
||||
return statesList.filter(stateList => stateList.alertLevel === 0);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket editableStates()', () => {
|
||||
it('should call the editableStates method with the production role and check that the result contain the DELIVERED state', async() => {
|
||||
const ctx = {req: {accessToken: {userId: 49}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'DELIVERED');
|
||||
|
||||
expect(codeExists).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should call the editableStates method with the salesPerson role and check that the result not contain the DELIVERED state`, async() => {
|
||||
const ctx = {req: {accessToken: {userId: 18}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'DELIVERED');
|
||||
|
||||
expect(codeExists).toBeFalsy();
|
||||
});
|
||||
|
||||
it(`should call the editableStates method with the salesPerson role and check that the result contain the PICKER_DESIGNED state`, async() => {
|
||||
const ctx = {req: {accessToken: {userId: 18}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'PICKER_DESIGNED');
|
||||
|
||||
expect(codeExists).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should call the editableStates method with the employee role and check that the result not contain the PICKER_DESIGNED state`, async() => {
|
||||
const ctx = {req: {accessToken: {userId: 1}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'PICKER_DESIGNED');
|
||||
|
||||
expect(codeExists).toBeFalsy();
|
||||
});
|
||||
});
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/state/editableStates')(Self);
|
||||
|
||||
/**
|
||||
* Checks if the alertLevel of a state is 0.
|
||||
*
|
||||
|
|
|
@ -28,11 +28,5 @@
|
|||
"type": "String",
|
||||
"required": false
|
||||
}
|
||||
},
|
||||
"scopes" : {
|
||||
"alertLevelIs0" : {
|
||||
"fields": ["id", "name"],
|
||||
"where": {"alertLevel": "0"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
disabled="!$ctrl.isEditable"
|
||||
label="State"
|
||||
value-field="id"
|
||||
url="/ticket/api/States/alertLevelIs0"
|
||||
url="/api/States/editableStates"
|
||||
on-change="$ctrl.onStateChange(value)">
|
||||
</vn-button-menu>
|
||||
<vn-button-menu
|
||||
|
|
Loading…
Reference in New Issue