3756-client_address_isLogifloraAllowed #930

Merged
joan merged 6 commits from 3756-client_address_isLogifloraAllowed into dev 2022-04-08 07:49:46 +00:00
7 changed files with 88 additions and 23 deletions

View File

@ -6,6 +6,12 @@ describe('Address updateAddress', () => {
const provinceId = 5; const provinceId = 5;
const incotermsId = 'FAS'; const incotermsId = 'FAS';
const customAgentOneId = 1; const customAgentOneId = 1;
const employeeId = 1;
const ctx = {
req: {
accessToken: {userId: employeeId}
}
};
it('should throw the non uee member error if no incoterms is defined', async() => { it('should throw the non uee member error if no incoterms is defined', async() => {
const tx = await models.Client.beginTransaction({}); const tx = await models.Client.beginTransaction({});
@ -14,11 +20,9 @@ describe('Address updateAddress', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const ctx = { ctx.args = {
args: { provinceFk: provinceId,
provinceFk: provinceId, customsAgentFk: customAgentOneId
customsAgentFk: customAgentOneId
}
}; };
await models.Client.updateAddress(ctx, clientId, addressId, options); await models.Client.updateAddress(ctx, clientId, addressId, options);
@ -40,11 +44,9 @@ describe('Address updateAddress', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const ctx = { ctx.args = {
args: { provinceFk: provinceId,
provinceFk: provinceId, incotermsFk: incotermsId
incotermsFk: incotermsId
}
}; };
await models.Client.updateAddress(ctx, clientId, addressId, options); await models.Client.updateAddress(ctx, clientId, addressId, options);
@ -66,13 +68,11 @@ describe('Address updateAddress', () => {
const options = {transaction: tx}; const options = {transaction: tx};
const expectedResult = 'My edited address'; const expectedResult = 'My edited address';
const ctx = { ctx.args = {
args: { provinceFk: provinceId,
provinceFk: provinceId, nickname: expectedResult,
nickname: expectedResult, incotermsFk: incotermsId,
incotermsFk: incotermsId, customsAgentFk: customAgentOneId
customsAgentFk: customAgentOneId
}
}; };
await models.Client.updateAddress(ctx, clientId, addressId, options); await models.Client.updateAddress(ctx, clientId, addressId, options);
@ -88,6 +88,48 @@ describe('Address updateAddress', () => {
} }
}); });
it('should return an error for a user without enough privileges', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
ctx.args = {
isLogifloraAllowed: true
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toEqual(`You don't have enough privileges`);
});
it('should update isLogifloraAllowed', async() => {
const tx = await models.Client.beginTransaction({});
const salesAssistantId = 21;
try {
const options = {transaction: tx};
ctx.req.accessToken.userId = salesAssistantId;
ctx.args = {
isLogifloraAllowed: true
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
const address = await models.Address.findById(addressId, null, options);
expect(address.isLogifloraAllowed).toEqual(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should update the address', async() => { it('should update the address', async() => {
const tx = await models.Client.beginTransaction({}); const tx = await models.Client.beginTransaction({});
@ -95,10 +137,8 @@ describe('Address updateAddress', () => {
const options = {transaction: tx}; const options = {transaction: tx};
const expectedResult = 'My second time edited address'; const expectedResult = 'My second time edited address';
const ctx = { ctx.args = {
args: { nickname: expectedResult
nickname: expectedResult
}
}; };
await models.Client.updateAddress(ctx, clientId, addressId, options); await models.Client.updateAddress(ctx, clientId, addressId, options);

View File

@ -68,6 +68,10 @@ module.exports = function(Self) {
{ {
arg: 'isEqualizated', arg: 'isEqualizated',
type: 'boolean' type: 'boolean'
},
{
arg: 'isLogifloraAllowed',
type: 'boolean'
} }
], ],
returns: { returns: {
@ -83,11 +87,16 @@ module.exports = function(Self) {
Self.updateAddress = async(ctx, clientId, addressId, options) => { Self.updateAddress = async(ctx, clientId, addressId, options) => {
const models = Self.app.models; const models = Self.app.models;
const args = ctx.args; const args = ctx.args;
const userId = ctx.req.accessToken.userId;
const myOptions = {}; const myOptions = {};
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
if (args.isLogifloraAllowed && !isSalesAssistant)
throw new UserError(`You don't have enough privileges`);
const address = await models.Address.findOne({ const address = await models.Address.findOne({
where: { where: {
id: addressId, id: addressId,

View File

@ -50,6 +50,9 @@
}, },
"isEqualizated": { "isEqualizated": {
"type": "boolean" "type": "boolean"
},
"isLogifloraAllowed": {
"type": "boolean"
} }
}, },
"validations": [], "validations": [],

View File

@ -39,6 +39,12 @@
ng-model="$ctrl.address.isEqualizated" ng-model="$ctrl.address.isEqualizated"
vn-acl="administrative, salesAssistant"> vn-acl="administrative, salesAssistant">
</vn-check> </vn-check>
<vn-check
vn-one
label="Is Logiflora allowed"
ng-model="$ctrl.address.isLogifloraAllowed"
vn-acl="salesAssistant">
</vn-check>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield

View File

@ -60,6 +60,11 @@
ng-model="address.isEqualizated" ng-model="address.isEqualizated"
disabled="true"> disabled="true">
</vn-check> </vn-check>
<vn-check
vn-one label="Is Logiflora allowed"
ng-model="address.isLogifloraAllowed"
disabled="true">
</vn-check>
</vn-one> </vn-one>
<vn-vertical <vn-vertical
vn-one vn-one

View File

@ -17,6 +17,7 @@ class Controller extends Section {
'phone', 'phone',
'mobile', 'mobile',
'isEqualizated', 'isEqualizated',
'isLogifloraAllowed',
'postalCode' 'postalCode'
], ],
order: [ order: [

View File

@ -27,3 +27,4 @@ Mobile: Móvil
# Common # Common
Fiscal name: Nombre fiscal Fiscal name: Nombre fiscal
Street: Dirección fiscal Street: Dirección fiscal
Is Logiflora allowed: Compra directa en Holanda