diff --git a/modules/client/back/methods/client/specs/updateUser.spec.js b/modules/client/back/methods/client/specs/updateUser.spec.js index 49acfda97..4dc969906 100644 --- a/modules/client/back/methods/client/specs/updateUser.spec.js +++ b/modules/client/back/methods/client/specs/updateUser.spec.js @@ -10,7 +10,10 @@ describe('Client updateUser', () => { } } }; - const ctx = {req: {accessToken: {userId: employeeId}}}; + const ctx = { + req: {accessToken: {userId: employeeId}}, + args: {name: 'test', active: true} + }; beforeEach(() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ @@ -21,7 +24,8 @@ describe('Client updateUser', () => { it('should throw an error the target user is not just a client but a worker', async() => { let error; try { - await models.Client.updateUser(ctx, 1106, 'test', true); + const clientID = 1106; + await models.Client.updateUser(ctx, clientID); } catch (e) { error = e; } @@ -38,8 +42,7 @@ describe('Client updateUser', () => { const options = {transaction: tx}; const clientID = 1105; - - await models.Client.updateUser(ctx, clientID, 'test', true, options); + await models.Client.updateUser(ctx, clientID, options); const client = await models.Account.findById(clientID, null, options); expect(client.name).toEqual('test'); diff --git a/modules/client/back/methods/client/updateUser.js b/modules/client/back/methods/client/updateUser.js index 26fcd6026..dd5b9f9fe 100644 --- a/modules/client/back/methods/client/updateUser.js +++ b/modules/client/back/methods/client/updateUser.js @@ -14,7 +14,7 @@ module.exports = Self => { description: 'the user name' }, { - arg: 'isActive', + arg: 'active', type: 'boolean', description: 'whether the user is active or not' }, @@ -25,7 +25,7 @@ module.exports = Self => { } }); - Self.updateUser = async function(ctx, id, name, isActive, options) { + Self.updateUser = async function(ctx, id, options) { const models = Self.app.models; let tx; const myOptions = {}; @@ -45,11 +45,7 @@ module.exports = Self => { const user = await models.Account.findById(id, null, myOptions); - const data = {}; - if (name) data.name = name; - if (isActive != undefined) data.active = isActive; - - await user.updateAttributes(data, myOptions); + await user.updateAttributes(ctx.args, myOptions); if (tx) await tx.commit(); } catch (e) { diff --git a/modules/client/front/web-access/index.js b/modules/client/front/web-access/index.js index eb72ecab3..71f876284 100644 --- a/modules/client/front/web-access/index.js +++ b/modules/client/front/web-access/index.js @@ -63,11 +63,11 @@ export default class Controller extends Section { onSubmit() { const data = { name: this.account.name, - isActive: this.account.isActive, + active: this.account.active }; - this.$http.patch(`Clients/${this.client.id}/updateUser`, data).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); }); } }