41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
const UserError = require('../../../common/helpers').UserError;
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('deleted', {
|
|
description: 'Sets the isDeleted value of a ticket to 1',
|
|
accessType: '',
|
|
accepts: [{
|
|
arg: 'ticketFk',
|
|
type: 'Object',
|
|
required: true,
|
|
description: 'TicketFk',
|
|
http: {source: 'body'}
|
|
}],
|
|
returns: {
|
|
type: 'string',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/deleted`,
|
|
verb: 'post'
|
|
}
|
|
});
|
|
|
|
Self.deleted = async (ctx, params) => {
|
|
let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}});
|
|
if (claimOfATicket)
|
|
throw new UserError('You must delete the claim id %d first', claimOfATicket.id);
|
|
|
|
let currentTicket = await Self.app.models.Ticket.findById(params.id);
|
|
await currentTicket.updateAttributes({isDeleted: '1'});
|
|
|
|
if (ctx.req.accessToken) {
|
|
let token = ctx.req.accessToken;
|
|
let currentUserId = token && token.userId;
|
|
let worker = await Self.app.models.Worker.findOne({where: {userFk: currentUserId}});
|
|
params.workerFk = worker.id;
|
|
}
|
|
return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: 17, workerFk: params.workerFk});
|
|
};
|
|
};
|