Bug #307 Modificar changeState en ticket.sale

This commit is contained in:
gerard 2018-05-17 13:29:18 +02:00
parent 595d878f93
commit 983e66d7ee
6 changed files with 45 additions and 7 deletions

View File

@ -13,8 +13,10 @@
"forceId": false
},
"updated": {
"type": "Date",
"required": false
"type": "Date"
},
"alertLevel": {
"type": "Number"
}
},
"relations": {
@ -32,11 +34,6 @@
"type": "belongsTo",
"model": "Worker",
"foreignKey": "workerFk"
},
"alertLevel": {
"type": "belongsTo",
"model": "State",
"foreignKey": "alertLevel"
}
}
}

View File

@ -86,6 +86,11 @@
"type": "hasMany",
"model": "TicketObservation",
"foreignKey": "ticketFk"
},
"alertLevel": {
"type": "hasOne",
"model": "TicketState",
"foreignKey": "ticketFk"
}
}
}

View File

@ -0,0 +1,3 @@
{
"You don't have enough privileges to change the state of this ticket": "You don't have enough privileges to change the state of this ticket"
}

View File

@ -0,0 +1,3 @@
{
"You don't have enough privileges to change the state of this ticket": "No tienes permisos para cambiar el estado de este ticket"
}

View File

@ -0,0 +1,29 @@
module.exports = Self => {
Self.remoteMethod('changeState', {
description: 'Change the state of a ticket',
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: 'ticketFk',
http: {source: 'body'}
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/changeState`,
verb: 'post'
}
});
Self.changeState = async (params, ctx) => {
let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
if (isEditable)
return await Self.app.models.TicketTracking.create(params);
throw new Error(`You don't have enough privileges to change the state of this ticket`);
};
};

View File

@ -1,5 +1,6 @@
module.exports = function(Self) {
require('../methods/ticket-tracking/filter')(Self);
require('../methods/ticket-tracking/changeState')(Self);
Self.validatesPresenceOf('stateFk', {message: 'State cannot be blank'});