replaced isActive by active as per it's model and updated original data in controller
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2022-06-16 16:25:21 +02:00
parent 869c9caf98
commit e151e35f7e
3 changed files with 13 additions and 14 deletions

View File

@ -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');

View File

@ -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) {

View File

@ -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();
});
}
}