Skip to content

Instantly share code, notes, and snippets.

@adelowo
Last active March 17, 2020 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelowo/63b0e3458fd6f639f18fd7332fc39eb5 to your computer and use it in GitHub Desktop.
Save adelowo/63b0e3458fd6f639f18fd7332fc39eb5 to your computer and use it in GitHub Desktop.
// This code should come on Line 142 or 143
app.post("/users/export", async (req, res) => {
const userID = req.body.user_id;
const email = req.body.email;
if (email === undefined || email === "") {
res
.status(400)
.send({ status: true, message: "Please provide your email address" });
return;
}
if (userID == "" || userID === undefined) {
res
.status(400)
.send({ status: false, message: "Please provide your user ID" });
return;
}
try {
const data = await client.exportUser(userID);
res.status(200).send({
status: true,
message: `Your exported data has been sent to your email address, ${email}`
});
transport
.sendMail({
from: process.env.SMTP_FROM_ADDRESS,
to: email,
subject: "Your exported data",
text: "Kindly find the exported data as an attachment",
html: "<p>Kindly find the exported data as an attachment</p>",
attachments: [
{ filename: "data.json", content: Buffer.from(JSON.stringify(data)) }
]
})
.catch(err => {
console.log("an error occurred while sending an error", err);
});
} catch (err) {
console.log(err);
res.status(400).send({ status: false, message: "user not found" });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment