44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('sendSms', {
|
|
description: 'Log the message in ticketLog and call the send method',
|
|
accessType: 'WRITE',
|
|
accepts: [{
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'The ticket id',
|
|
http: {source: 'path'}
|
|
},
|
|
{
|
|
arg: 'destination',
|
|
type: 'string',
|
|
required: true,
|
|
},
|
|
{
|
|
arg: 'message',
|
|
type: 'string',
|
|
required: true,
|
|
}],
|
|
returns: {
|
|
type: 'object',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/sendSms`,
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
Self.sendSms = async(ctx, id, destination, message) => {
|
|
const models = Self.app.models;
|
|
const sms = await models.Sms.send(ctx, destination, message);
|
|
const {clientFk} = await models.Ticket.findById(id);
|
|
await models.ClientSms.create({
|
|
clientFk,
|
|
ticketFk: id,
|
|
smsFk: sms.id
|
|
});
|
|
};
|
|
};
|