@riocrypto/common-server 1.0.2819 → 1.0.2821

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.
@@ -14,6 +14,7 @@ const sanitizeOrderDoc = (doc) => {
14
14
  delete obj.managedWallet;
15
15
  delete obj.exchangeRateOrders;
16
16
  delete obj.autoFXDisabled;
17
+ delete obj.rootUserId;
17
18
  delete obj.marketPriceWithoutAssetPrice;
18
19
  delete obj.discount;
19
20
  delete obj.markup;
@@ -386,6 +386,19 @@ const buildOrder = (mongoose) => {
386
386
  orderSchema.index({ brokerId: 1, "TWAP.sessionId": 1, createdAt: 1 });
387
387
  orderSchema.index({ clientReferenceId: 1 }, { sparse: true });
388
388
  orderSchema.index({ "paymentsReceived.blockchainTxId": 1 }, { sparse: true });
389
+ // At most one order per real quoteId. Imported orders use quoteId "" and are
390
+ // excluded by the partial filter (which also serves the createOrder lookup).
391
+ orderSchema.index({ quoteId: 1 }, { unique: true, partialFilterExpression: { quoteId: { $gt: "" } } });
392
+ // At most one order per (broker family, clientReferenceId). rootUserId is
393
+ // brokerId || userId; orders without a clientReferenceId (or, defensively,
394
+ // without rootUserId) are excluded from the constraint.
395
+ orderSchema.index({ rootUserId: 1, clientReferenceId: 1 }, {
396
+ unique: true,
397
+ partialFilterExpression: {
398
+ clientReferenceId: { $type: "string" },
399
+ rootUserId: { $type: "string" },
400
+ },
401
+ });
389
402
  orderSchema.pre("validate", function (next) {
390
403
  this.rootUserId = this.brokerId || this.userId;
391
404
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2819",
3
+ "version": "1.0.2821",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",