@dnax/core 0.3.9 → 0.4.1
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/driver/mongo/rest.ts +15 -1
- package/package.json +1 -1
package/driver/mongo/rest.ts
CHANGED
|
@@ -40,6 +40,7 @@ type optionCb = {
|
|
|
40
40
|
useHook?: boolean;
|
|
41
41
|
cleanDeep?: boolean;
|
|
42
42
|
useCustomApi?: boolean;
|
|
43
|
+
elementAt: Number | null;
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
const omitUpdate = [
|
|
@@ -238,6 +239,10 @@ class useRest {
|
|
|
238
239
|
|
|
239
240
|
var { valid, output, error } = this.validator(collection, data);
|
|
240
241
|
if (!valid) fn.error(error, 400);
|
|
242
|
+
data = {
|
|
243
|
+
...output,
|
|
244
|
+
...data,
|
|
245
|
+
};
|
|
241
246
|
|
|
242
247
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
243
248
|
await col.hooks.beforeOperation({
|
|
@@ -338,7 +343,12 @@ class useRest {
|
|
|
338
343
|
d = await hashPasswordAuto(d, col);
|
|
339
344
|
d = deepSetId(col, d);
|
|
340
345
|
var { valid, output, error } = this.validator(collection, d);
|
|
346
|
+
|
|
341
347
|
if (!valid) fn.error(error, 400);
|
|
348
|
+
d = {
|
|
349
|
+
...output,
|
|
350
|
+
...d,
|
|
351
|
+
};
|
|
342
352
|
}
|
|
343
353
|
|
|
344
354
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
@@ -503,7 +513,11 @@ class useRest {
|
|
|
503
513
|
});
|
|
504
514
|
}
|
|
505
515
|
|
|
506
|
-
|
|
516
|
+
let resultDocs = toJson(result.docs);
|
|
517
|
+
if (typeof options?.elementAt == "number") {
|
|
518
|
+
resultDocs = resultDocs[options?.elementAt] || null;
|
|
519
|
+
}
|
|
520
|
+
return resolve(resultDocs);
|
|
507
521
|
} catch (err) {
|
|
508
522
|
return reject(err);
|
|
509
523
|
}
|