Log sent sms #1324

This commit is contained in:
Joan Sanchez 2019-04-16 07:59:12 +02:00
parent 34a630dcde
commit 90bbe1bd02
7 changed files with 27 additions and 22 deletions

View File

@ -6,11 +6,11 @@ module.exports = Self => {
Self.remoteMethodCtx('send', { Self.remoteMethodCtx('send', {
description: 'Sends SMS to a destination phone', description: 'Sends SMS to a destination phone',
accepts: [{ accepts: [{
arg: 'recipientFk', arg: 'destinationFk',
type: 'Integer' type: 'Integer'
}, },
{ {
arg: 'recipient', arg: 'destination',
type: 'String', type: 'String',
required: true, required: true,
}, },
@ -20,7 +20,7 @@ module.exports = Self => {
required: true, required: true,
}], }],
returns: { returns: {
type: 'boolean', type: 'Object',
root: true root: true
}, },
http: { http: {
@ -29,7 +29,7 @@ module.exports = Self => {
} }
}); });
Self.send = async(ctx, recipientFk, recipient, message) => { Self.send = async(ctx, destinationFk, destination, message) => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const smsConfig = await Self.app.models.SmsConfig.findOne(); const smsConfig = await Self.app.models.SmsConfig.findOne();
const soapClient = await soap.createClientAsync(smsConfig.uri); const soapClient = await soap.createClientAsync(smsConfig.uri);
@ -37,7 +37,7 @@ module.exports = Self => {
user: smsConfig.user, user: smsConfig.user,
pass: smsConfig.password, pass: smsConfig.password,
src: smsConfig.title, src: smsConfig.title,
dst: recipient, dst: destination,
msg: message msg: message
}; };
@ -61,18 +61,21 @@ module.exports = Self => {
console.error(e); console.error(e);
} }
const statusCode = status.codigo[0];
const statusDescription = status.descripcion[0];
const newSms = { const newSms = {
senderFk: userId, senderFk: userId,
destinationFk: recipientFk || null, destinationFk: destinationFk || null,
destination: recipient, destination: destination,
message: message, message: message,
statusCode: status.codigo, statusCode: statusCode,
status: status.descripcion status: statusDescription
}; };
const sms = Self.create(newSms); const sms = await Self.create(newSms);
if (status.codigo != 200) if (statusCode != 200)
throw new UserError(`We weren't able to send this SMS`); throw new UserError(`We weren't able to send this SMS`);
return sms; return sms;

View File

@ -1,7 +1,11 @@
{ {
"name": "Sms", "name": "Sms",
"description": "Sms sent to client", "description": "Sms sent to client",
"base": "VnModel", "base": "Loggable",
"log": {
"model":"ClientLog",
"relation": "recipient"
},
"options": { "options": {
"mysql": { "mysql": {
"table": "sms" "table": "sms"

View File

@ -5,8 +5,8 @@
<h5 pad-small-v translate>Send SMS</h5> <h5 pad-small-v translate>Send SMS</h5>
<vn-horizontal> <vn-horizontal>
<vn-textfield vn-one <vn-textfield vn-one
label="Recipient" label="Destination"
model="$ctrl.sms.recipient"> model="$ctrl.sms.destination">
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal > <vn-horizontal >

View File

@ -18,11 +18,7 @@ class Controller extends Component {
onResponse(response) { onResponse(response) {
if (response === 'ACCEPT') { if (response === 'ACCEPT') {
let params = { this.$http.post(`/client/api/Sms/send`, this.sms).then(res => {
recipient: this.sms.recipient,
message: this.sms.message
};
this.$http.post(`/client/api/Sms/send`, params).then(res => {
this.vnApp.showMessage(this.$translate.instant('SMS sent!')); this.vnApp.showMessage(this.$translate.instant('SMS sent!'));
if (res.data) this.emit('send', {response: res.data}); if (res.data) this.emit('send', {response: res.data});

View File

@ -1,4 +1,4 @@
Send SMS: Enviar SMS Send SMS: Enviar SMS
Recipient: Destinatario Destination: Destinatario
Message: Mensaje Message: Mensaje
SMS sent!: ¡SMS enviado! SMS sent!: ¡SMS enviado!

View File

@ -182,7 +182,8 @@ class Controller {
showSMSDialog() { showSMSDialog() {
const address = this.ticket.address; const address = this.ticket.address;
this.newSMS = { this.newSMS = {
recipient: address.mobile || null, destinationFk: this.ticket.clientFk,
destination: address.mobile || null,
message: this.$translate.instant('SMSPayment') message: this.$translate.instant('SMSPayment')
}; };
this.$scope.sms.open(); this.$scope.sms.open();

View File

@ -331,7 +331,8 @@ class Controller {
notAvailables notAvailables
}; };
this.newSMS = { this.newSMS = {
recipient: address.mobile || null, destinationFk: this.ticket.clientFk,
destination: address.mobile || null,
message: this.$translate.instant('SMSAvailability', params) message: this.$translate.instant('SMSAvailability', params)
}; };
this.$scope.sms.open(); this.$scope.sms.open();