Skip to content

Commit

Permalink
fix: update route to new send method
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Jan 18, 2024
1 parent 80be7b1 commit 3957be1
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions app/api/users/me/recover/func.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
const app = require('@/app')
const errors = require('@/errors')
const app = require("@/app");
const errors = require("@/errors");

module.exports = async function(context) {
const { email } = context.body
if(!email) {
throw new errors.BadRequest.MissingParameter('email')
module.exports = async function (context) {
const { email } = context.body;
if (!email) {
throw new errors.BadRequest.MissingParameter("email");
}

/*
* Make sure email is a string to prevent NoSQL injections
*/
const Users = app.models.users
const user = await Users.findOne({ email: String(email)}).lean(true)
if(!user) {
throw new errors.BadRequest(`Invalid email: ${email}`)
const Users = app.models.users;
const user = await Users.findOne({ email: String(email) }).lean(true);
if (!user) {
throw new errors.BadRequest(`Invalid email: ${email}`);
}

const mailer = app.helpers.mailer
const TEMPLATE_ID = app.config.mailer.TEMPLATES.RECOVERY
const RECOVERY_URL = app.config.RECOVERY_URL
const mailer = app.helpers.mailer;
const TEMPLATE_ID = app.config.mailer.TEMPLATES.RECOVERY;
const RECOVERY_URL = app.config.RECOVERY_URL;

const payload = {
recipient: user.email,
body: {
recovery_facebook: `${RECOVERY_URL}/facebook?userId=${user._id}`,
recovery_google: `${RECOVERY_URL}/google?userId=${user._id}`
}
}
recovery_google: `${RECOVERY_URL}/google?userId=${user._id}`,
},
};

await mailer.send(payload, {}, TEMPLATE_ID)
}
await mailer.send(payload, TEMPLATE_ID);
};

0 comments on commit 3957be1

Please sign in to comment.