diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 2b19280..d383d2b 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -22,6 +22,7 @@ import { getUserSession, hashPassword, matchPassword, + newAccountExportId, newFeedbackId, newStoreId, newUserId, @@ -687,17 +688,8 @@ export async function ExportUserAccount(req: Request, res: Response) { (async () => { try { - // send email with user data - console.log("email"); - - // simulate delay - - await new Promise((resolve) => setTimeout(resolve, 5000)); - // create json file with user data - console.log("file"); - const exportData = { user: { user_id: user.user_id, @@ -714,7 +706,10 @@ export async function ExportUserAccount(req: Request, res: Response) { }, }; - fs.writeJson(`./user-profile-exports/${user.user_id}.json`, exportData); + fs.writeJson( + `./user-profile-exports/${newAccountExportId()}.json`, + exportData + ); // send email with file @@ -722,8 +717,8 @@ export async function ExportUserAccount(req: Request, res: Response) { process.env.RABBITMQ_MAIL_QUEUE as string, Buffer.from( JSON.stringify({ - m: "test@roese.dev", // UserMail - t: "userAccountExportFinish", // TemplateId + m: email, // UserMail + t: "dashboardUserAccountExportFinish", // TemplateId l: "de", // LanguageId // BodyData b: { @@ -748,20 +743,23 @@ export async function ExportUserAccount(req: Request, res: Response) { export function GetExportedUserAccount(req: Request, res: Response) { try { - const { userId } = req.params; + const { id } = req.params; - if (!userId) { + if (!id) { return res.status(400).send({ err: "invalid request" }); } - const file = `./user-profile-exports/${userId}.json`; + const file = `./user-profile-exports/${id}.json`; res.download(file, (err) => { if (err) { - logger.error(err); res.status(500).send({ err: "invalid request" }); } }); + + // delete file after download + + fs.remove(file); } catch (error) { logger.error(error); res.status(500).send({ err: "invalid request" }); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 3f883b9..0a56028 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -50,6 +50,10 @@ export function newFeedbackId() { return uuidv4(); } +export function newAccountExportId() { + return uuidv4(); +} + export async function saveSession( req: Request, res: Response, diff --git a/user-profile-exports/4417984c-de81-4930-8ae7-9f178d98ddf7.json b/user-profile-exports/4417984c-de81-4930-8ae7-9f178d98ddf7.json deleted file mode 100644 index 4ab971d..0000000 --- a/user-profile-exports/4417984c-de81-4930-8ae7-9f178d98ddf7.json +++ /dev/null @@ -1 +0,0 @@ -{"user":{"user_id":"4417984c-de81-4930-8ae7-9f178d98ddf7","username":"Alexander","account_name":"alex","calendar_max_future_booking_days":13,"calendar_min_earliest_booking_time":8,"calendar_using_primary_calendar":true,"language":"de","analytics_enabled":false}} diff --git a/user-profile-exports/6d86ae13-05cb-4d3d-a9c2-112783d133b9.json b/user-profile-exports/6d86ae13-05cb-4d3d-a9c2-112783d133b9.json new file mode 100644 index 0000000..46273c0 --- /dev/null +++ b/user-profile-exports/6d86ae13-05cb-4d3d-a9c2-112783d133b9.json @@ -0,0 +1 @@ +{"user":{"user_id":"6d86ae13-05cb-4d3d-a9c2-112783d133b9","username":"Mikael cool","account_name":"mikael","calendar_max_future_booking_days":null,"calendar_min_earliest_booking_time":null,"calendar_using_primary_calendar":true,"language":"de","analytics_enabled":true}}