@sdflc/backend-helpers 1.0.108 → 1.0.110

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/build/BaseCore.js CHANGED
@@ -129,18 +129,28 @@ class BaseCore {
129
129
  return result.toJS();
130
130
  }
131
131
  async checkResult(args) {
132
- const { hasTransaction, result, sameRequest, doingWhat } = args;
132
+ const { hasTransaction, result, sameRequest, doingWhat, skipCheckResult } = args;
133
133
  if (sameRequest) {
134
134
  return;
135
135
  }
136
- if (hasTransaction && result) {
137
- if (result.code >= api_helpers_1.OP_RESULT_CODES.OK) {
138
- this.logger.debug(`Commit DB transaction on ${doingWhat}`);
136
+ if (hasTransaction) {
137
+ if (skipCheckResult === true) {
138
+ this.logger.debug(`Skip result check and commit DB transaction on ${doingWhat}`);
139
139
  await this.getDb().commitTransaction();
140
140
  }
141
+ else if (result) {
142
+ if (result.code >= api_helpers_1.OP_RESULT_CODES.OK) {
143
+ this.logger.debug(`Commit DB transaction on ${doingWhat}`);
144
+ await this.getDb().commitTransaction();
145
+ }
146
+ else {
147
+ this.logger.debug(`Rollback DB transaction on ${doingWhat} as action result code is '${result.code}'`);
148
+ await this.getDb().rollbackTransaction();
149
+ }
150
+ }
141
151
  else {
142
- this.logger.debug(`Rollback DB transaction on ${doingWhat} as action result code is '${result.code}'`);
143
- await this.getDb().rollbackTransaction();
152
+ this.logger.debug(`Commit DB transaction on no result on ${doingWhat}`);
153
+ await this.getDb().commitTransaction();
144
154
  }
145
155
  }
146
156
  }
@@ -239,9 +249,7 @@ class BaseCore {
239
249
  let time = this.measureTool.stop();
240
250
  this.logger.debug(`Authorization and validation time for the ${doingWhat} took ${time.durationMs} ms`);
241
251
  const result = await action(args, { ...actionOpt, validatedItems, args });
242
- if (skipCheckResult !== true) {
243
- await this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
244
- }
252
+ await this.checkResult({ hasTransaction, result, sameRequest, doingWhat, skipCheckResult });
245
253
  time = this.measureTool.stop(doingWhat);
246
254
  this.logger.debug(`The ${time.name} process time is ${time.durationMs} ms`);
247
255
  return result;
@@ -123,18 +123,28 @@ class BaseCore {
123
123
  return result.toJS();
124
124
  }
125
125
  async checkResult(args) {
126
- const { hasTransaction, result, sameRequest, doingWhat } = args;
126
+ const { hasTransaction, result, sameRequest, doingWhat, skipCheckResult } = args;
127
127
  if (sameRequest) {
128
128
  return;
129
129
  }
130
- if (hasTransaction && result) {
131
- if (result.code >= OP_RESULT_CODES.OK) {
132
- this.logger.debug(`Commit DB transaction on ${doingWhat}`);
130
+ if (hasTransaction) {
131
+ if (skipCheckResult === true) {
132
+ this.logger.debug(`Skip result check and commit DB transaction on ${doingWhat}`);
133
133
  await this.getDb().commitTransaction();
134
134
  }
135
+ else if (result) {
136
+ if (result.code >= OP_RESULT_CODES.OK) {
137
+ this.logger.debug(`Commit DB transaction on ${doingWhat}`);
138
+ await this.getDb().commitTransaction();
139
+ }
140
+ else {
141
+ this.logger.debug(`Rollback DB transaction on ${doingWhat} as action result code is '${result.code}'`);
142
+ await this.getDb().rollbackTransaction();
143
+ }
144
+ }
135
145
  else {
136
- this.logger.debug(`Rollback DB transaction on ${doingWhat} as action result code is '${result.code}'`);
137
- await this.getDb().rollbackTransaction();
146
+ this.logger.debug(`Commit DB transaction on no result on ${doingWhat}`);
147
+ await this.getDb().commitTransaction();
138
148
  }
139
149
  }
140
150
  }
@@ -233,9 +243,7 @@ class BaseCore {
233
243
  let time = this.measureTool.stop();
234
244
  this.logger.debug(`Authorization and validation time for the ${doingWhat} took ${time.durationMs} ms`);
235
245
  const result = await action(args, { ...actionOpt, validatedItems, args });
236
- if (skipCheckResult !== true) {
237
- await this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
238
- }
246
+ await this.checkResult({ hasTransaction, result, sameRequest, doingWhat, skipCheckResult });
239
247
  time = this.measureTool.stop(doingWhat);
240
248
  this.logger.debug(`The ${time.name} process time is ${time.durationMs} ms`);
241
249
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.108",
3
+ "version": "1.0.110",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "type": "commonjs",
6
6
  "exports": {