@dnax/core 0.73.3 → 0.73.5

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.
@@ -1637,6 +1637,14 @@ class useRest {
1637
1637
  if (!valid) fn.error(error, 400);
1638
1638
  }
1639
1639
 
1640
+ let $setOnInsert = update.$setOnInsert || {};
1641
+ // Processing before validation
1642
+ $setOnInsert = await setUUID($setOnInsert, col);
1643
+ $setOnInsert = await randomCode($setOnInsert, col);
1644
+ $setOnInsert = await hashPasswordAuto($setOnInsert, col);
1645
+ $setOnInsert = transformAllDate($setOnInsert);
1646
+ $setOnInsert = deepSetId(col, $setOnInsert);
1647
+
1640
1648
  let up_ = await this.#tenant.database.db
1641
1649
  ?.collection(collection)
1642
1650
  .updateMany(
@@ -1653,10 +1661,11 @@ class useRest {
1653
1661
  },
1654
1662
  $setOnInsert: {
1655
1663
  createdAt: new Date(),
1656
- ...formatData(update?.$setOnInsert || {}, {
1664
+ ...formatData($setOnInsert || {}, {
1657
1665
  collection: collection,
1658
1666
  tenant_id: this.#tenant_id,
1659
1667
  action: "updateMany",
1668
+ upsert: true,
1660
1669
  }),
1661
1670
  },
1662
1671
  },
@@ -1802,6 +1811,14 @@ class useRest {
1802
1811
  if (!valid) fn.error(error, 400);
1803
1812
  }
1804
1813
 
1814
+ let $setOnInsert = update.$setOnInsert || {};
1815
+ // Processing before validation
1816
+ $setOnInsert = await setUUID($setOnInsert, col);
1817
+ $setOnInsert = await randomCode($setOnInsert, col);
1818
+ $setOnInsert = await hashPasswordAuto($setOnInsert, col);
1819
+ $setOnInsert = transformAllDate($setOnInsert);
1820
+ $setOnInsert = deepSetId(col, $setOnInsert);
1821
+
1805
1822
  result.doc = await this.#tenant.database.db
1806
1823
  ?.collection(collection)
1807
1824
  .findOneAndUpdate(
@@ -1813,15 +1830,16 @@ class useRest {
1813
1830
  collection: collection,
1814
1831
  tenant_id: this.#tenant_id,
1815
1832
  }),
1833
+
1816
1834
  $setOnInsert: {
1817
- ...formatData(update?.$setOnInsert || {}, {
1835
+ ...formatData($setOnInsert || {}, {
1818
1836
  collection: collection,
1819
1837
  tenant_id: this.#tenant_id,
1820
1838
  action: "insertOne",
1839
+ upsert: true,
1821
1840
  }),
1822
- //updatedAt: new Date(),
1823
- createdAt: new Date(),
1824
1841
  },
1842
+
1825
1843
  $currentDate: {
1826
1844
  updatedAt: true,
1827
1845
  },
@@ -188,6 +188,7 @@ function transformAllDate(data: object) {
188
188
  function toBson<T>(
189
189
  data: object | T,
190
190
  options?: {
191
+ upsert?: boolean;
191
192
  action?:
192
193
  | "insertOne"
193
194
  | "insertMany"
@@ -204,14 +205,14 @@ function toBson<T>(
204
205
  // InsertOne
205
206
  if (options?.action == "insertOne") {
206
207
  data.createdAt = new Date();
207
- data.updatedAt = new Date();
208
+ if (!options?.upsert) data.updatedAt = new Date();
208
209
  }
209
210
 
210
211
  // insertMany
211
212
  if (options?.action == "insertMany" && Array.isArray(data)) {
212
213
  data?.map((d) => {
213
214
  d.createdAt = new Date();
214
- d.updatedAt = new Date();
215
+ if (!options?.upsert) d.updatedAt = new Date();
215
216
  });
216
217
  }
217
218
 
@@ -414,6 +415,7 @@ function formatData(
414
415
  collection?: string;
415
416
  action?: Actions;
416
417
  tenant_id: string;
418
+ upsert?: boolean;
417
419
  } = {
418
420
  tenant_id: "_",
419
421
  collection: "",
@@ -424,6 +426,7 @@ function formatData(
424
426
  data = deepSetId(col, data);
425
427
  }
426
428
  data = toBson(data, {
429
+ upsert: options?.upsert,
427
430
  action: options?.action,
428
431
  });
429
432
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.73.3",
3
+ "version": "0.73.5",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {},