anote-server-libs 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anote-server-libs",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -10,7 +10,7 @@ function withTransaction(repo, logger, previousMethod, lock, commitIfLost = true
10
10
  return function (req, res, next) {
11
11
  let commit = true;
12
12
  if (!commitIfLost) {
13
- req.once('close', () => commit = false);
13
+ res.once('close', () => commit = false);
14
14
  }
15
15
  const endTerminator = res.end.bind(res);
16
16
  const jsonTerminator = (obj) => {
@@ -71,7 +71,7 @@ function withTransaction(repo, logger, previousMethod, lock, commitIfLost = true
71
71
  }
72
72
  else {
73
73
  res.locals.dbClientCommit((err) => {
74
- if (err) {
74
+ if (err && commitIfLost) {
75
75
  res.status(500);
76
76
  jsonTerminator({
77
77
  error: {
@@ -99,7 +99,7 @@ function withTransaction(repo, logger, previousMethod, lock, commitIfLost = true
99
99
  }
100
100
  else {
101
101
  res.locals.dbClientCommit((err) => {
102
- if (err) {
102
+ if (err && commitIfLost) {
103
103
  res.status(500);
104
104
  jsonTerminator({
105
105
  error: {
@@ -17,7 +17,7 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
17
17
  return function(req: Request, res: Response, next: NextFunction) {
18
18
  let commit = true;
19
19
  if(!commitIfLost) {
20
- req.once('close', () => commit = false);
20
+ res.once('close', () => commit = false);
21
21
  }
22
22
  const endTerminator = res.end.bind(res);
23
23
  const jsonTerminator = (obj: any) => {
@@ -76,7 +76,7 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
76
76
  });
77
77
  } else {
78
78
  res.locals.dbClientCommit((err: any) => {
79
- if(err) {
79
+ if(err && commitIfLost) {
80
80
  res.status(500);
81
81
  jsonTerminator({
82
82
  error: {
@@ -100,7 +100,7 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
100
100
  });
101
101
  } else {
102
102
  res.locals.dbClientCommit((err: any) => {
103
- if(err) {
103
+ if(err && commitIfLost) {
104
104
  res.status(500);
105
105
  jsonTerminator({
106
106
  error: {