diff --git a/package.json b/package.json index 8026a77..d20062b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dbc-tech/nest-neo4j", - "version": "0.6.0", + "version": "0.7.0", "description": "", "main": "dist/index.js", "types": "dist/index.d.js", diff --git a/src/neo4j.service.ts b/src/neo4j.service.ts index a662869..e8e5df2 100644 --- a/src/neo4j.service.ts +++ b/src/neo4j.service.ts @@ -76,16 +76,17 @@ export class Neo4jService implements OnApplicationShutdown { return res } - transaction = async ( - run?: (_: Transaction) => Promise, + async transaction( + run?: (_: Transaction) => Promise, onCommitError?: (error: Error) => Promise, - ) => { + ): Promise { const session = this.getWriteSession() const tx = await session.beginTransaction() try { - await run(tx) + const result = await run(tx) try { await tx.commit() + return result } catch (error) { if (onCommitError) await onCommitError(error) throw error // roll back