salix/modules/ticket/back/methods/ticket/sendSms.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-01-15 12:27:14 +00:00
module.exports = Self => {
Self.remoteMethodCtx('sendSms', {
description: 'Log the message in ticketLog and call the send method',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'number',
2020-01-15 12:27:14 +00:00
required: true,
description: 'The ticket id',
http: {source: 'path'}
},
{
arg: 'destination',
type: 'string',
2020-01-15 12:27:14 +00:00
required: true,
},
{
arg: 'message',
type: 'string',
2020-01-15 12:27:14 +00:00
required: true,
}],
returns: {
type: 'object',
2020-01-15 12:27:14 +00:00
root: true
},
http: {
path: `/:id/sendSms`,
verb: 'POST'
}
});
2023-06-25 17:08:13 +00:00
Self.sendSms = async(ctx, id, destination, message) => {
const models = Self.app.models;
2023-06-25 17:08:13 +00:00
const sms = await models.Sms.send(ctx, destination, message);
const {clientFk} = await models.Ticket.findById(id);
await models.ClientSms.create({
clientFk,
2023-06-25 17:08:13 +00:00
ticketFk: id,
smsFk: sms.id
});
2020-01-15 12:27:14 +00:00
};
};