hiteshchoudhary / chai-backend

A video series on chai aur code youtube channel
5.34k stars 803 forks source link

Remove file from /public/temp if user already exists #151

Open Sage-Enc opened 3 months ago

Sage-Enc commented 3 months ago

When user already existed, the registerUser wasn't removing the file from /public/temp/. So, to solve this issue:

  1. I swapped Step 3 and 4 in registerUser in src/controllers/user.controller.js.
  2. Added fs.unlinksync() on the condition if user already exists.
  3. Throw the error after removing the files. Handled the file when user already exist.

So now when user already exists in the database the server will handle the locally stored file before throwing the error.