Skip to content

Commit

Permalink
temp/makeaccountpublic now uses MongooseSession library for session h…
Browse files Browse the repository at this point in the history
…andling
  • Loading branch information
Sebastian-Webster committed Oct 19, 2023
1 parent 18da4fd commit 5fbd2b5
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions controllers/Temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3243,22 +3243,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 the Mongoose session:', error)
}).finally(() => {
User.bulkWrite(dbUpdates, {session}).then(() => {
mongooseSessionHelper.commitTransaction(session).then(() => {
return resolve(HTTPWTHandler.OK('Account is now public.'))
}).catch(() => {
return resolve(HTTPWTHandler.serverError('An error occurred while making account public. Please try again.'))
})
}).catch(error => {
console.error('An error occurred while making bulkWrite database updates to the User collection and commiting transaction. The updates were:', dbUpdates, '. The error was:', error)
session.abortTransaction().catch(error => {
console.error('An error occurred while aborting a Mongoose transaction:', error)
}).finally(() => {
session.endSession().catch(error => {
console.error('An error occurred while ending a Mongoose session:', error)
}).finally(() => {
return resolve(HTTPWTHandler.serverError('An error occurred while adding users that requested to follow you to your followers list. 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 making account public. Please try again.'))
})
})
}).catch(error => {
Expand Down

0 comments on commit 5fbd2b5

Please sign in to comment.