@riocrypto/common-server 1.0.2820 → 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.
- package/build/models/order.js +13 -0
- package/package.json +1 -1
package/build/models/order.js
CHANGED
|
@@ -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();
|