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',
|
2021-09-21 16:48:59 +00:00
|
|
|
type: 'number',
|
2020-01-15 12:27:14 +00:00
|
|
|
required: true,
|
|
|
|
description: 'The ticket id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'destination',
|
2021-09-21 16:48:59 +00:00
|
|
|
type: 'string',
|
2020-01-15 12:27:14 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'message',
|
2021-09-21 16:48:59 +00:00
|
|
|
type: 'string',
|
2020-01-15 12:27:14 +00:00
|
|
|
required: true,
|
|
|
|
}],
|
|
|
|
returns: {
|
2021-09-21 16:48:59 +00:00
|
|
|
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) => {
|
2022-11-25 08:38:34 +00:00
|
|
|
const models = Self.app.models;
|
2023-06-25 17:08:13 +00:00
|
|
|
const sms = await models.Sms.send(ctx, destination, message);
|
2023-12-21 17:34:22 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
};
|