58 lines
1.4 KiB
JavaScript
58 lines
1.4 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 userId = ctx.req.accessToken.userId;
|
|
|
|
let sms = await Self.app.models.Sms.send(ctx, id, destination, message);
|
|
let logRecord = {
|
|
originFk: id,
|
|
userFk: userId,
|
|
action: 'insert',
|
|
changedModel: 'sms',
|
|
newInstance: {
|
|
destinationFk: id,
|
|
destination: destination,
|
|
message: message,
|
|
statusCode: sms.statusCode,
|
|
status: sms.status
|
|
}
|
|
};
|
|
|
|
const ticketLog = await Self.app.models.TicketLog.create(logRecord);
|
|
|
|
sms.logId = ticketLog.id;
|
|
|
|
return sms;
|
|
};
|
|
};
|