Skip to content

Commit

Permalink
Revert "Revert "Implement draft Multi-Entry Transaction Commit Functi…
Browse files Browse the repository at this point in the history
…onality""

This reverts commit b220fd2.
  • Loading branch information
ChyzhykTech committed Feb 9, 2024
1 parent b220fd2 commit 90270be
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/helper/commit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Entry from "../Entry";
import { TransactionError } from "../errors";
import * as mongoose from "mongoose";

export async function commit(...entries: Entry[]) {
const mongooseSession = await mongoose.startSession();
try {
mongooseSession.startTransaction();
const journals = await Promise.all(entries.map(entry => entry.commit()));
await mongooseSession.commitTransaction();
return journals;
} catch (error) {
await mongooseSession.abortTransaction();
throw new TransactionError(`Failure to commit entries: ${(error as Error).message}`, entries.length,500);
} finally {
await mongooseSession.endSession();
}
}

0 comments on commit 90270be

Please sign in to comment.