Skip to content

Commit

Permalink
temp/blockaccount now uses MongooseSession library for session handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Webster committed Oct 19, 2023
1 parent 1bf12ff commit d000813
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions controllers/Temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3490,22 +3490,16 @@ class TempController {
mongoose.startSession().then(session => {
session.startTransaction();

User.bulkWrite(dbUpdates, {session}).then(() => session.commitTransaction()).then(() => {
session.endSession().catch(error => {
console.error('An error occurred while ending Mongoose session. The error was:', error)
}).finally(() => {
return resolve(HTTPWTHandler.OK('Blocked user.'))
User.bulkWrite(dbUpdates, {session}).then(() => {
mongooseSessionHelper.commitTransaction(session).then(() => {
return resolve(HTTPWTHandler.OK('Successfully blocked account'))
}).catch(() => {
return resolve(HTTPWTHandler.serverError('An error occurred while blocking account. Please try again.'))
})
}).catch(error => {
console.error('An error occurred while making a bulkWrite operation on the User collection. The database updates were:', dbUpdates, '. The error was:', error)
session.abortTransaction().catch(error => {
console.error('An error occurred while aborting Mongoose transaction. The error was:', error)
}).finally(() => {
session.endSession().catch(error => {
console.error('An error occurred while ending Mongoose session. The error was:', error)
}).finally(() => {
return resolve(HTTPWTHandler.serverError('An error occurred while blocking user. Please try again.'))
})
console.error('An error occurred while making a bulkWrite operation on the User collection:', dbUpdates, '. The error was:', error)
mongooseSessionHelper.abortTransaction(session).then(() => {
return resolve(HTTPWTHandler.serverError('An error occurred while blocking account. Please try again.'))
})
})
}).catch(error => {
Expand Down

0 comments on commit d000813

Please sign in to comment.