From 90bbe1bd020a115bb21bda21fbb7b79ae7928e2d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Apr 2019 07:59:12 +0200 Subject: [PATCH] Log sent sms #1324 --- modules/client/back/methods/sms/send.js | 25 +++++++++++++----------- modules/client/back/models/sms.json | 6 +++++- modules/client/front/sms/index.html | 4 ++-- modules/client/front/sms/index.js | 6 +----- modules/client/front/sms/locale/es.yml | 2 +- modules/ticket/front/descriptor/index.js | 3 ++- modules/ticket/front/sale/index.js | 3 ++- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/modules/client/back/methods/sms/send.js b/modules/client/back/methods/sms/send.js index 539b6e546..d11b722f5 100644 --- a/modules/client/back/methods/sms/send.js +++ b/modules/client/back/methods/sms/send.js @@ -6,11 +6,11 @@ module.exports = Self => { Self.remoteMethodCtx('send', { description: 'Sends SMS to a destination phone', accepts: [{ - arg: 'recipientFk', + arg: 'destinationFk', type: 'Integer' }, { - arg: 'recipient', + arg: 'destination', type: 'String', required: true, }, @@ -20,7 +20,7 @@ module.exports = Self => { required: true, }], returns: { - type: 'boolean', + type: 'Object', root: true }, 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 smsConfig = await Self.app.models.SmsConfig.findOne(); const soapClient = await soap.createClientAsync(smsConfig.uri); @@ -37,7 +37,7 @@ module.exports = Self => { user: smsConfig.user, pass: smsConfig.password, src: smsConfig.title, - dst: recipient, + dst: destination, msg: message }; @@ -61,18 +61,21 @@ module.exports = Self => { console.error(e); } + const statusCode = status.codigo[0]; + const statusDescription = status.descripcion[0]; + const newSms = { senderFk: userId, - destinationFk: recipientFk || null, - destination: recipient, + destinationFk: destinationFk || null, + destination: destination, message: message, - statusCode: status.codigo, - status: status.descripcion + statusCode: statusCode, + 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`); return sms; diff --git a/modules/client/back/models/sms.json b/modules/client/back/models/sms.json index ec458e73d..aa9737478 100644 --- a/modules/client/back/models/sms.json +++ b/modules/client/back/models/sms.json @@ -1,7 +1,11 @@ { "name": "Sms", "description": "Sms sent to client", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ClientLog", + "relation": "recipient" + }, "options": { "mysql": { "table": "sms" diff --git a/modules/client/front/sms/index.html b/modules/client/front/sms/index.html index 30bf2dcc8..9d907e5c2 100644 --- a/modules/client/front/sms/index.html +++ b/modules/client/front/sms/index.html @@ -5,8 +5,8 @@
Send SMS
+ label="Destination" + model="$ctrl.sms.destination"> diff --git a/modules/client/front/sms/index.js b/modules/client/front/sms/index.js index 03bafdec0..19d9ab3ea 100644 --- a/modules/client/front/sms/index.js +++ b/modules/client/front/sms/index.js @@ -18,11 +18,7 @@ class Controller extends Component { onResponse(response) { if (response === 'ACCEPT') { - let params = { - recipient: this.sms.recipient, - message: this.sms.message - }; - this.$http.post(`/client/api/Sms/send`, params).then(res => { + this.$http.post(`/client/api/Sms/send`, this.sms).then(res => { this.vnApp.showMessage(this.$translate.instant('SMS sent!')); if (res.data) this.emit('send', {response: res.data}); diff --git a/modules/client/front/sms/locale/es.yml b/modules/client/front/sms/locale/es.yml index 28933f774..10247b926 100644 --- a/modules/client/front/sms/locale/es.yml +++ b/modules/client/front/sms/locale/es.yml @@ -1,4 +1,4 @@ Send SMS: Enviar SMS -Recipient: Destinatario +Destination: Destinatario Message: Mensaje SMS sent!: ¡SMS enviado! \ No newline at end of file diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index f61c94d23..1708a73d3 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -182,7 +182,8 @@ class Controller { showSMSDialog() { const address = this.ticket.address; this.newSMS = { - recipient: address.mobile || null, + destinationFk: this.ticket.clientFk, + destination: address.mobile || null, message: this.$translate.instant('SMSPayment') }; this.$scope.sms.open(); diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 492dd831c..16b668c4e 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -331,7 +331,8 @@ class Controller { notAvailables }; this.newSMS = { - recipient: address.mobile || null, + destinationFk: this.ticket.clientFk, + destination: address.mobile || null, message: this.$translate.instant('SMSAvailability', params) }; this.$scope.sms.open();