speedly 1.2.44 → 1.2.46

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/dist/cjs/db/db.js CHANGED
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
8
8
  const strToObj_1 = __importDefault(require("../util/strToObj"));
9
9
  const getConfig_1 = __importDefault(require("../util/getConfig"));
10
10
  const translator_1 = __importDefault(require("../util/translator"));
11
+ const utils_1 = require("./utils");
11
12
  let configs = {
12
13
  dbType: "mongodb",
13
14
  path: "../models",
@@ -349,14 +350,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
349
350
  break;
350
351
  case "findOneAndUpdate":
351
352
  req.document = await model.findOne(match);
352
- data = model?.[queryState.action]?.call(model, match, {
353
- $set: {
354
- ...req.body,
355
- ...(typeof queryState.body == "function"
356
- ? queryState.body(req)
357
- : queryState.body),
358
- },
359
- }, { new: true });
353
+ data = model?.[queryState.action]?.call(model, match, (0, utils_1.createUpdateObject)(req, queryState.body || {}), { new: true });
360
354
  break;
361
355
  case "findOneAndDelete":
362
356
  data = model?.[queryState.action]?.call(model, match);
@@ -0,0 +1,3 @@
1
+ import { Request } from "express";
2
+ declare const createUpdateObject: (req: Request, additionalFields: Record<string, any> | ((req: Request) => Record<string, any>)) => Record<string, any>;
3
+ export { createUpdateObject };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUpdateObject = void 0;
4
+ const createUpdateObject = (req, additionalFields) => {
5
+ let updateObject = { $set: { ...req.body } };
6
+ const additionalObject = typeof additionalFields === "function"
7
+ ? additionalFields(req)
8
+ : additionalFields;
9
+ if (Object.keys(additionalObject).find((key) => key.startsWith("$")))
10
+ updateObject = { ...updateObject, ...additionalObject };
11
+ else
12
+ updateObject.$set = { ...updateObject.$set, ...additionalObject };
13
+ return updateObject;
14
+ };
15
+ exports.createUpdateObject = createUpdateObject;
@@ -126,6 +126,54 @@ function routeAnalyzer(route, routerName) {
126
126
  };
127
127
  }
128
128
  }
129
+ // Response
130
+ doc.responses = {
131
+ "200": {
132
+ content: {
133
+ "application/json": {
134
+ schema: {
135
+ type: "object",
136
+ properties: {
137
+ message: { type: "string", example: "find successfully" },
138
+ content: {
139
+ oneOf: [
140
+ {
141
+ type: "array",
142
+ items: {
143
+ type: "object",
144
+ properties: {
145
+ id: { type: "string" },
146
+ name: { type: "string" },
147
+ },
148
+ },
149
+ },
150
+ {
151
+ type: "object",
152
+ properties: {
153
+ id: { type: "string" },
154
+ name: { type: "string" },
155
+ },
156
+ },
157
+ ],
158
+ },
159
+ },
160
+ },
161
+ },
162
+ },
163
+ },
164
+ "400": {
165
+ content: {
166
+ "application/json": {
167
+ schema: {
168
+ type: "object",
169
+ properties: {
170
+ message: { type: "string", example: "module not found" },
171
+ },
172
+ },
173
+ },
174
+ },
175
+ },
176
+ };
129
177
  // Auth
130
178
  const auth = getAuthStatus(detail.middlewares);
131
179
  if (auth.type === "required") {
package/dist/esm/db/db.js CHANGED
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
8
8
  const strToObj_1 = __importDefault(require("../util/strToObj"));
9
9
  const getConfig_1 = __importDefault(require("../util/getConfig"));
10
10
  const translator_1 = __importDefault(require("../util/translator"));
11
+ const utils_1 = require("./utils");
11
12
  let configs = {
12
13
  dbType: "mongodb",
13
14
  path: "../models",
@@ -349,14 +350,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
349
350
  break;
350
351
  case "findOneAndUpdate":
351
352
  req.document = await model.findOne(match);
352
- data = model?.[queryState.action]?.call(model, match, {
353
- $set: {
354
- ...req.body,
355
- ...(typeof queryState.body == "function"
356
- ? queryState.body(req)
357
- : queryState.body),
358
- },
359
- }, { new: true });
353
+ data = model?.[queryState.action]?.call(model, match, (0, utils_1.createUpdateObject)(req, queryState.body || {}), { new: true });
360
354
  break;
361
355
  case "findOneAndDelete":
362
356
  data = model?.[queryState.action]?.call(model, match);
@@ -0,0 +1,3 @@
1
+ import { Request } from "express";
2
+ declare const createUpdateObject: (req: Request, additionalFields: Record<string, any> | ((req: Request) => Record<string, any>)) => Record<string, any>;
3
+ export { createUpdateObject };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUpdateObject = void 0;
4
+ const createUpdateObject = (req, additionalFields) => {
5
+ let updateObject = { $set: { ...req.body } };
6
+ const additionalObject = typeof additionalFields === "function"
7
+ ? additionalFields(req)
8
+ : additionalFields;
9
+ if (Object.keys(additionalObject).find((key) => key.startsWith("$")))
10
+ updateObject = { ...updateObject, ...additionalObject };
11
+ else
12
+ updateObject.$set = { ...updateObject.$set, ...additionalObject };
13
+ return updateObject;
14
+ };
15
+ exports.createUpdateObject = createUpdateObject;
@@ -126,6 +126,54 @@ function routeAnalyzer(route, routerName) {
126
126
  };
127
127
  }
128
128
  }
129
+ // Response
130
+ doc.responses = {
131
+ "200": {
132
+ content: {
133
+ "application/json": {
134
+ schema: {
135
+ type: "object",
136
+ properties: {
137
+ message: { type: "string", example: "find successfully" },
138
+ content: {
139
+ oneOf: [
140
+ {
141
+ type: "array",
142
+ items: {
143
+ type: "object",
144
+ properties: {
145
+ id: { type: "string" },
146
+ name: { type: "string" },
147
+ },
148
+ },
149
+ },
150
+ {
151
+ type: "object",
152
+ properties: {
153
+ id: { type: "string" },
154
+ name: { type: "string" },
155
+ },
156
+ },
157
+ ],
158
+ },
159
+ },
160
+ },
161
+ },
162
+ },
163
+ },
164
+ "400": {
165
+ content: {
166
+ "application/json": {
167
+ schema: {
168
+ type: "object",
169
+ properties: {
170
+ message: { type: "string", example: "module not found" },
171
+ },
172
+ },
173
+ },
174
+ },
175
+ },
176
+ };
129
177
  // Auth
130
178
  const auth = getAuthStatus(detail.middlewares);
131
179
  if (auth.type === "required") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "1.2.44",
3
+ "version": "1.2.46",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",