2019-04-05 13:20:12 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('deny', {
|
2019-07-25 07:55:09 +00:00
|
|
|
description: 'sets a ticket request to denied and returns the changes',
|
2019-04-05 13:20:12 +00:00
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'id',
|
2021-10-07 07:57:07 +00:00
|
|
|
type: 'number',
|
2019-04-05 13:20:12 +00:00
|
|
|
required: true,
|
|
|
|
description: 'The request ID',
|
|
|
|
}, {
|
|
|
|
arg: 'observation',
|
|
|
|
type: 'String',
|
|
|
|
required: true,
|
|
|
|
description: 'The request observation',
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'number',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/deny`,
|
|
|
|
verb: 'post'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
Self.deny = async(ctx, options) => {
|
2021-10-27 10:16:37 +00:00
|
|
|
const models = Self.app.models;
|
|
|
|
const $t = ctx.req.__; // $translate
|
2021-10-07 07:57:07 +00:00
|
|
|
const myOptions = {};
|
|
|
|
let tx;
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const userId = ctx.req.accessToken.userId;
|
2023-09-20 09:58:36 +00:00
|
|
|
const worker = await Self.app.models.Worker.findOne({where: {id: userId}}, myOptions);
|
2021-10-07 07:57:07 +00:00
|
|
|
|
|
|
|
const params = {
|
|
|
|
isOk: false,
|
|
|
|
attenderFk: worker.id,
|
|
|
|
response: ctx.args.observation,
|
|
|
|
};
|
2019-04-05 13:20:12 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions);
|
|
|
|
await request.updateAttributes(params, myOptions);
|
2019-04-05 13:20:12 +00:00
|
|
|
|
2021-10-27 10:16:37 +00:00
|
|
|
const origin = ctx.req.headers.origin;
|
2021-10-27 10:22:32 +00:00
|
|
|
const requesterId = request.requesterFk;
|
2021-10-27 10:16:37 +00:00
|
|
|
|
|
|
|
const message = $t('Deny buy request', {
|
|
|
|
ticketId: request.ticketFk,
|
|
|
|
url: `${origin}/#!/ticket/${request.ticketFk}/request/index`,
|
|
|
|
observation: params.response
|
|
|
|
});
|
2021-10-27 10:22:32 +00:00
|
|
|
|
|
|
|
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions);
|
2021-10-27 10:16:37 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
if (tx) await tx.commit();
|
|
|
|
|
|
|
|
return request;
|
|
|
|
} catch (e) {
|
|
|
|
if (tx) await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2019-04-05 13:20:12 +00:00
|
|
|
};
|
|
|
|
};
|