feat(salix): refs #6427 #6427 Update Params method

This commit is contained in:
Javier Segarra 2024-04-27 21:28:01 +02:00
parent a35847f7b9
commit 719979f252
1 changed files with 6 additions and 11 deletions

View File

@ -4,16 +4,11 @@ module.exports = Self => {
Self.remoteMethod('recoverPasswordSMS', { Self.remoteMethod('recoverPasswordSMS', {
description: 'Send SMS to the user', description: 'Send SMS to the user',
accepts: [ accepts: [
{ {
arg: 'id', arg: 'recoveryPhone',
type: 'string', type: 'string',
description: 'The user id', description: 'The recoveryPhone user\'s',
required: true
},
{
arg: 'phone',
type: 'string',
description: 'The phone user\'s recovery',
required: true required: true
}, },
{ {
@ -32,7 +27,7 @@ module.exports = Self => {
} }
}); });
Self.recoverPasswordSMS = async function(id, phone, otp, options) { Self.recoverPasswordSMS = async function(recoveryPhone, otp, options) {
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
@ -40,7 +35,7 @@ module.exports = Self => {
const user = await Self.findOne({ const user = await Self.findOne({
fields: ['id', 'recoveryPhone', 'email', 'name'], fields: ['id', 'recoveryPhone', 'email', 'name'],
where: {id, recoveryPhone: phone} where: {recoveryPhone}
}); });
if (!user) throw new UserError('Credentials not valid'); if (!user) throw new UserError('Credentials not valid');
@ -56,7 +51,7 @@ module.exports = Self => {
const code = await authCode(user, myOptions); const code = await authCode(user, myOptions);
if (process.env.NODE_ENV === 'production') if (process.env.NODE_ENV === 'production')
await Self.app.models.Sms.send({req: {accessToken: {userId: id}}}, +phone, code); await Self.app.models.Sms.send({req: {accessToken: {userId: id}}}, +recoveryPhone, code);
return {otp: true}; return {otp: true};
} catch (err) { } catch (err) {
if (err.code === 'EMAIL_NOT_FOUND') if (err.code === 'EMAIL_NOT_FOUND')