add prefix +34
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-01-11 10:03:59 +01:00
parent 9e491082e7
commit 4f0edbda6b
2 changed files with 7 additions and 3 deletions

View File

@ -34,8 +34,12 @@ module.exports = Self => {
Self.send = async(ctx, destinationFk, destination, 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();
/* if (destination.length <= 9)
destination = '34' + destination;*/ if (destination.length == 9) {
const spainPrefix = '0034';
destination = spainPrefix + destination;
}
const params = { const params = {
api_key: smsConfig.apiKey, api_key: smsConfig.apiKey,
messages: [{ messages: [{

View File

@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server');
describe('sms send()', () => { describe('sms send()', () => {
it('should not return status error', async() => { it('should not return status error', async() => {
const ctx = {req: {accessToken: {userId: 1}}}; 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(); expect(result.status).toBeUndefined();
}); });