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

45 lines
1.0 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('sendSms', {
description: 'Log the message in clientLog and call the send method',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The client 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);
await models.ClientSms.create({
clientFk: id,
smsFk: sms.id
});
return sms;
};
};