@sdflc/backend-helpers 1.0.34 → 1.0.37

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
@@ -752,6 +752,9 @@ var BaseCore = /** @class */ (function () {
752
752
  switch (_a.label) {
753
753
  case 0:
754
754
  context = this.config.context;
755
+ if (context.space) {
756
+ return [2 /*return*/, [true, context.space]];
757
+ }
755
758
  space = null;
756
759
  if (!context.spaceGw) return [3 /*break*/, 2];
757
760
  if (!context.spaceId) {
@@ -115,14 +115,17 @@ var BaseGateway = /** @class */ (function () {
115
115
  BaseGateway.prototype.onUpdateFilter = function (query, filterParams) {
116
116
  return __awaiter(this, void 0, void 0, function () {
117
117
  var _a, hasStatus, hasVersion, idName;
118
- return __generator(this, function (_b) {
118
+ var _b;
119
+ return __generator(this, function (_c) {
119
120
  _a = this.config, hasStatus = _a.hasStatus, hasVersion = _a.hasVersion;
120
121
  idName = this.getIdField();
121
122
  if (filterParams[idName]) {
122
123
  query.where(idName, filterParams[idName]);
123
124
  }
124
- if (hasVersion && filterParams[constants_1.FIELDS.VERSION]) {
125
- query.where(constants_1.FIELDS.VERSION, filterParams[constants_1.FIELDS.VERSION]);
125
+ if (hasVersion) {
126
+ if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
127
+ query.where((_b = {}, _b[constants_1.FIELDS.VERSION] = filterParams[constants_1.FIELDS.VERSION], _b));
128
+ }
126
129
  }
127
130
  if (hasStatus) {
128
131
  if (Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS])) {
@@ -152,9 +155,9 @@ var BaseGateway = /** @class */ (function () {
152
155
  };
153
156
  BaseGateway.prototype.transformOnCreate = function (args) {
154
157
  return __awaiter(this, void 0, void 0, function () {
155
- var _a, hasCreatedAt, hasCreatedBy;
158
+ var _a, hasCreatedAt, hasCreatedBy, hasSpace, hasVersion;
156
159
  return __generator(this, function (_b) {
157
- _a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy;
160
+ _a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy, hasSpace = _a.hasSpace, hasVersion = _a.hasVersion;
158
161
  if (hasCreatedAt) {
159
162
  args[constants_1.FIELDS.CREATED_AT] = this.dateTime.dbFormat(this.dateTimeNow);
160
163
  }
@@ -163,15 +166,21 @@ var BaseGateway = /** @class */ (function () {
163
166
  args[constants_1.FIELDS.CREATED_BY] = this.getContext().userId;
164
167
  }
165
168
  }
169
+ if (hasSpace) {
170
+ args[constants_1.FIELDS.SPACE_ID] = this.getContext().spaceId;
171
+ }
172
+ if (hasVersion) {
173
+ args[constants_1.FIELDS.VERSION] = 0;
174
+ }
166
175
  return [2 /*return*/, args];
167
176
  });
168
177
  });
169
178
  };
170
179
  BaseGateway.prototype.transformOnUpdate = function (params, where) {
171
180
  return __awaiter(this, void 0, void 0, function () {
172
- var _a, hasUpdatedAt, hasUpdatedBy;
181
+ var _a, hasUpdatedAt, hasUpdatedBy, hasVersion;
173
182
  return __generator(this, function (_b) {
174
- _a = this.config, hasUpdatedAt = _a.hasUpdatedAt, hasUpdatedBy = _a.hasUpdatedBy;
183
+ _a = this.config, hasUpdatedAt = _a.hasUpdatedAt, hasUpdatedBy = _a.hasUpdatedBy, hasVersion = _a.hasVersion;
175
184
  if (hasUpdatedAt) {
176
185
  params[constants_1.FIELDS.UPDATED_AT] = this.dateTime.dbFormat(this.dateTimeNow);
177
186
  }
@@ -180,6 +189,11 @@ var BaseGateway = /** @class */ (function () {
180
189
  params[constants_1.FIELDS.UPDATED_BY] = this.getContext().userId;
181
190
  }
182
191
  }
192
+ if (hasVersion) {
193
+ if (params[constants_1.FIELDS.VERSION] != null && !isNaN(params[constants_1.FIELDS.VERSION])) {
194
+ params[constants_1.FIELDS.VERSION] = params[constants_1.FIELDS.VERSION] + 1;
195
+ }
196
+ }
183
197
  return [2 /*return*/, params];
184
198
  });
185
199
  });
@@ -132,7 +132,7 @@ var createContextDefault = function (args) { return __awaiter(void 0, void 0, vo
132
132
  ipAddress = req.headers[constants_1.HEADERS.IP_ADDRESS] || req.connection.remoteAddress;
133
133
  acceptLanguage = req.headers[constants_1.HEADERS.ACCEPT_LANGUAGE];
134
134
  languages = (0, utils_1.extractLanguages)(acceptLanguage);
135
- requestedLang = req.headers[constants_1.HEADERS.ACCEPT_LANGUAGE] || req.query[constants_1.HEADERS.ACCEPT_LANGUAGE];
135
+ requestedLang = req.headers[constants_1.HEADERS.REQUESTED_LANGUAGE] || (languages === null || languages === void 0 ? void 0 : languages[0]) || 'en';
136
136
  requestId = (0, uuid_1.v4)();
137
137
  db = new Database_1.Database({
138
138
  knexConfig: knexConfig,
@@ -160,11 +160,21 @@ var createContextDefault = function (args) { return __awaiter(void 0, void 0, vo
160
160
  requestId: requestId,
161
161
  extendContext: function (_a) {
162
162
  var context = _a.context, req = _a.req;
163
- context.db = db;
164
- Object.assign(context, sharedContext);
165
- if (typeof extendContext === 'function') {
166
- extendContext({ context: context, req: req });
167
- }
163
+ return __awaiter(void 0, void 0, void 0, function () {
164
+ return __generator(this, function (_b) {
165
+ switch (_b.label) {
166
+ case 0:
167
+ context.db = db;
168
+ Object.assign(context, sharedContext);
169
+ if (!(typeof extendContext === 'function')) return [3 /*break*/, 2];
170
+ return [4 /*yield*/, extendContext({ context: context, req: req })];
171
+ case 1:
172
+ _b.sent();
173
+ _b.label = 2;
174
+ case 2: return [2 /*return*/];
175
+ }
176
+ });
177
+ });
168
178
  },
169
179
  getCoreContext: function (args) { return __awaiter(void 0, void 0, void 0, function () {
170
180
  var extendCoreConext;
@@ -84,7 +84,7 @@ var validateCreate = function (_a) {
84
84
  return [2 /*return*/, [paramsCheck, {}]];
85
85
  }
86
86
  result = rules.validateSync(params)[0];
87
- if (result !== true) {
87
+ if (result) {
88
88
  return [2 /*return*/, [(0, checkItHelpers_1.createErrorOnCheckError)(result), {}]];
89
89
  }
90
90
  return [2 /*return*/, [true, {}]];
@@ -107,7 +107,7 @@ var validateUpdate = function (_a) {
107
107
  return [2 /*return*/, [paramsCheck, {}]];
108
108
  }
109
109
  result = rules.validateSync(params)[0];
110
- if (result !== true) {
110
+ if (result) {
111
111
  return [2 /*return*/, [(0, checkItHelpers_1.createErrorOnCheckError)(result), {}]];
112
112
  }
113
113
  return [2 /*return*/, [true, {}]];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.34",
3
+ "version": "1.0.37",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -22,7 +22,6 @@
22
22
  },
23
23
  "author": "Sergey Demidenko",
24
24
  "license": "ISC",
25
- "peerDependencies": {},
26
25
  "devDependencies": {
27
26
  "@types/bcrypt": "^5.0.0",
28
27
  "@types/bluebird": "^3.5.36",
@@ -54,6 +53,7 @@
54
53
  "@sdflc/utils": "^1.0.19",
55
54
  "bcrypt": "^5.0.1",
56
55
  "bluebird": "^3.7.2",
56
+ "checkit": "^0.7.0",
57
57
  "dataloader": "^2.0.0",
58
58
  "dayjs": "^1.10.7",
59
59
  "dotenv-safe": "^8.2.0",