From 4f0edbda6bb1d95f98554b2f5e21f7b1e47ebd3e Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Jan 2022 10:03:59 +0100 Subject: [PATCH] add prefix +34 --- modules/client/back/methods/sms/send.js | 8 ++++++-- modules/client/back/methods/sms/send.spec.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/client/back/methods/sms/send.js b/modules/client/back/methods/sms/send.js index 325e2e60d3..4e088d6ee3 100644 --- a/modules/client/back/methods/sms/send.js +++ b/modules/client/back/methods/sms/send.js @@ -34,8 +34,12 @@ module.exports = Self => { Self.send = async(ctx, destinationFk, destination, message) => { const userId = ctx.req.accessToken.userId; const smsConfig = await Self.app.models.SmsConfig.findOne(); - /* if (destination.length <= 9) - destination = '34' + destination;*/ + + if (destination.length == 9) { + const spainPrefix = '0034'; + destination = spainPrefix + destination; + } + const params = { api_key: smsConfig.apiKey, messages: [{ diff --git a/modules/client/back/methods/sms/send.spec.js b/modules/client/back/methods/sms/send.spec.js index 910b7d7b21..7ca78b2149 100644 --- a/modules/client/back/methods/sms/send.spec.js +++ b/modules/client/back/methods/sms/send.spec.js @@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server'); describe('sms send()', () => { it('should not return status error', async() => { const ctx = {req: {accessToken: {userId: 1}}}; - const result = await app.models.Sms.send(ctx, 1105, '123123123', 'My SMS Body'); + const result = await app.models.Sms.send(ctx, 1105, '123456789', 'My SMS Body'); expect(result.status).toBeUndefined(); });