-
-
Save adelowo/63b0e3458fd6f639f18fd7332fc39eb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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