feat(Salix): refs #6427 #6427 unpublish send method

This commit is contained in:
Javier Segarra 2024-06-14 15:48:30 +02:00
parent 5f1086d9e3
commit cd7f0e3c24
2 changed files with 11 additions and 33 deletions

View File

@ -3,33 +3,8 @@ const isProduction = require('vn-loopback/server/boot/isProduction');
const {models} = require('vn-loopback/server/server');
module.exports = Self => {
Self.remoteMethod('send', {
description: 'Sends SMS to a destination phone',
accessType: 'WRITE',
accepts: [
{
arg: 'destination',
type: 'string',
required: true,
},
{
arg: 'message',
type: 'string',
required: true,
}
],
returns: {
type: 'object',
root: true
},
http: {
path: `/send`,
verb: 'POST'
}
});
Self.send = async(ctx, destination, message) => {
Self.send = async(senderFk, destination, message, options) => {
const smsConfig = await models.SmsConfig.findOne();
const userId = ctx.req.accessToken.userId;
if (destination.length == 9) {
const spainPrefix = '0034';
@ -50,25 +25,26 @@ module.exports = Self => {
if (!isProduction(false))
response = {result: [{status: 'ok'}]};
else {
const jsonTest = {
const body = {
json: params
};
response = await got.post(smsConfig.uri, jsonTest).json();
response = await got.post(smsConfig.uri, body).json();
}
} catch (e) {
console.error(e);
}
if (!options?.insert) return;
// return response;
const [result] = response.result;
const error = result.error_id;
if (senderFk) senderFk = ctx.req.accessToken.userId;
const newSms = {
senderFk: userId,
senderFk,
destination: destination,
message: message,
status: error
};
const sms = await Self.create(newSms);
if (error)

View File

@ -1,10 +1,10 @@
const UserError = require('vn-loopback/util/user-error');
const isProduction = require('vn-loopback/server/boot/isProduction');
const authCode = require('../../models/authCode');
module.exports = Self => {
Self.remoteMethod('recoverPasswordSMS', {
description: 'Send SMS to the user',
accepts: [
{
arg: 'user',
type: 'string',
@ -40,10 +40,12 @@ module.exports = Self => {
fields: ['id', 'name', 'recoveryPhone'],
where: filter
});
if (!account) return;
if (!account && !verificationCode) return;
user = account;
if (verificationCode) {
if (!account)
throw new UserError('Invalid or expired verification code');
await Self.validateCode(user.name, verificationCode);
return {
@ -55,7 +57,7 @@ module.exports = Self => {
if (!isProduction()) {
try {
await Self.app.models.Sms.send(+user.recoveryPhone, code);
await Self.app.models.Sms.send(null, +user.recoveryPhone, code, {insert: false});
} catch (e) {
throw new UserError(`We weren't able to send this SMS`);
}