40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('sendSms', {
|
|
description: 'Sends a SMS to each client of the routes, each client only recieves the SMS once',
|
|
accessType: 'WRITE',
|
|
accepts: [
|
|
{
|
|
arg: 'destination',
|
|
type: 'string',
|
|
description: 'A comma separated string of destinations',
|
|
required: true,
|
|
},
|
|
{
|
|
arg: 'message',
|
|
type: 'string',
|
|
required: true,
|
|
}],
|
|
returns: {
|
|
type: 'object',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/sendSms`,
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
Self.sendSms = async(ctx, destination, message) => {
|
|
const targetClients = destination.split(',');
|
|
|
|
const allSms = [];
|
|
for (let client of targetClients) {
|
|
let sms = await Self.app.models.Sms.send(ctx, client, message);
|
|
allSms.push(sms);
|
|
}
|
|
|
|
return allSms;
|
|
};
|
|
};
|