Skip to content

Commit

Permalink
Merge pull request #125 from SquareTable/124-tempdeleteaccount-does-n…
Browse files Browse the repository at this point in the history
…ot-abort-transaction-on-error

temp/deleteaccount API now aborts transactions on error and ends session
  • Loading branch information
Sebastian-Webster authored Sep 10, 2023
2 parents 62cefd7 + 866f014 commit b739bb1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions controllers/Temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5437,10 +5437,22 @@ class TempController {
User.deleteOne({_id: {$eq: userId}})
]).then(() => session.commitTransaction()).then(() => {
console.log('User with id:', userId, 'has been successfully deleted along with all associated data.')
return resolve(HTTPWTHandler.OK('Successfully deleted account and all associated data.'))
session.endSession().catch(error => {
console.error('An error occurred while ending session after deleting account. The error was:', error)
}).finally(() => {
return resolve(HTTPWTHandler.OK('Successfully deleted account and all associated data.'))
})
}).catch(error => {
console.error('An error occured while deleting account data for user with id:', userId, '. The error was:', error)
return resolve(HTTPWTHandler.serverError('An error occurred while deleting data. Please try again.'))
session.abortTransaction().catch(error => {
console.error('An error occurred while aborting transaction after deleting account. The error was:', error)
}).finally(() => {
session.endSession().catch(error => {
console.error('An error occurred while ending session after deleting account data. The error was:', error)
}).finally(() => {
console.error('An error occured while deleting account data for user with id:', userId, '. The error was:', error)
return resolve(HTTPWTHandler.serverError('An error occurred while deleting data. Please try again.'))
})
})
})
}).catch(error => {
console.log('An error occurred while starting Mongoose session. The error was:', error)
Expand Down

0 comments on commit b739bb1

Please sign in to comment.