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

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 Self.app.models.Account.hasRole(userId, 'salesAssistant', myOptions);
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
if (ctx.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