2018-08-02 07:49:00 +00:00
|
|
|
let UserError = require('../../helpers').UserError;
|
|
|
|
|
2018-07-13 10:37:58 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('updateBasicData', {
|
|
|
|
description: 'Updates billing data of a client',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'data',
|
|
|
|
type: 'Object',
|
|
|
|
required: true,
|
|
|
|
description: 'Params to update',
|
|
|
|
http: {source: 'body'}
|
|
|
|
}, {
|
|
|
|
arg: 'id',
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
description: 'Model id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
arg: 'data',
|
|
|
|
type: 'Worker',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/updateBasicData`,
|
|
|
|
verb: 'PATCH'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.updateBasicData = async(params, id) => {
|
2018-08-13 14:54:34 +00:00
|
|
|
let validUpdateParams = [
|
|
|
|
'contact',
|
|
|
|
'name',
|
|
|
|
'email',
|
|
|
|
'phone',
|
|
|
|
'mobile',
|
|
|
|
'salesPersonFk',
|
|
|
|
'contactChannelFk'
|
|
|
|
];
|
|
|
|
|
2018-07-13 10:37:58 +00:00
|
|
|
for (const key in params) {
|
|
|
|
if (validUpdateParams.indexOf(key) === -1)
|
2018-08-02 07:49:00 +00:00
|
|
|
throw new UserError(`You don't have enough privileges to do that`);
|
2018-07-13 10:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return await Self.app.models.Client.update({id: id}, params);
|
|
|
|
};
|
|
|
|
};
|