feat(client_address): add LogifloraIsAllowed
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-04-06 14:48:22 +02:00
parent 43fcd0c473
commit afc03fc60e
7 changed files with 89 additions and 2 deletions

View File

@ -15,6 +15,9 @@ describe('Address updateAddress', () => {
try {
const options = {transaction: tx};
const ctx = {
req: {
accessToken: {userId: 1}
},
args: {
provinceFk: provinceId,
customsAgentFk: customAgentOneId
@ -41,6 +44,9 @@ describe('Address updateAddress', () => {
try {
const options = {transaction: tx};
const ctx = {
req: {
accessToken: {userId: 1}
},
args: {
provinceFk: provinceId,
incotermsFk: incotermsId
@ -67,6 +73,9 @@ describe('Address updateAddress', () => {
const expectedResult = 'My edited address';
const ctx = {
req: {
accessToken: {userId: 1}
},
args: {
provinceFk: provinceId,
nickname: expectedResult,
@ -88,6 +97,56 @@ 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};
const ctx = {
req: {
accessToken: {userId: 1}
},
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({});
try {
const options = {transaction: tx};
const ctx = {
req: {
accessToken: {userId: 21}
},
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() => {
const tx = await models.Client.beginTransaction({});
@ -96,6 +155,9 @@ describe('Address updateAddress', () => {
const expectedResult = 'My second time edited address';
const ctx = {
req: {
accessToken: {userId: 1}
},
args: {
nickname: expectedResult
}

View File

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

View File

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

View File

@ -38,7 +38,13 @@
label="Is equalizated"
ng-model="$ctrl.address.isEqualizated"
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-textfield

View File

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

View File

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

View File

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