@riocrypto/common-server 1.0.2674 → 1.0.2675
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.
|
@@ -38,17 +38,26 @@ const getBulkPaymentFromReference = (reference, mongoose) => __awaiter(void 0, v
|
|
|
38
38
|
if (!referenceText.includes("bp")) {
|
|
39
39
|
throw new Error("Bulk payment not found");
|
|
40
40
|
}
|
|
41
|
-
//
|
|
42
|
-
const
|
|
41
|
+
// Priority 1: New format - 2 chars from random portion (8-9) + last 6 chars
|
|
42
|
+
const bulkPaymentNewFormat = bulkPayments.find((bulkPayment) => {
|
|
43
43
|
const bulkPaymentId = bulkPayment.id.toString().toLowerCase();
|
|
44
44
|
const randomPrefix = bulkPaymentId.slice(8, 10);
|
|
45
45
|
const last6 = bulkPaymentId.slice(-6);
|
|
46
46
|
const reference8Chars = randomPrefix + last6;
|
|
47
47
|
return referenceText.includes(reference8Chars);
|
|
48
48
|
});
|
|
49
|
-
if (
|
|
49
|
+
if (bulkPaymentNewFormat) {
|
|
50
|
+
return bulkPaymentNewFormat;
|
|
51
|
+
}
|
|
52
|
+
// Priority 2: Old format - just last 6 chars (backwards compatibility)
|
|
53
|
+
const bulkPaymentOldFormat = bulkPayments.find((bulkPayment) => {
|
|
54
|
+
const bulkPaymentId = bulkPayment.id.toString().toLowerCase();
|
|
55
|
+
const last6 = bulkPaymentId.slice(-6);
|
|
56
|
+
return referenceText.includes(last6);
|
|
57
|
+
});
|
|
58
|
+
if (!bulkPaymentOldFormat) {
|
|
50
59
|
throw new Error("Bulk payment not found");
|
|
51
60
|
}
|
|
52
|
-
return
|
|
61
|
+
return bulkPaymentOldFormat;
|
|
53
62
|
});
|
|
54
63
|
exports.getBulkPaymentFromReference = getBulkPaymentFromReference;
|
|
@@ -33,6 +33,7 @@ const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0,
|
|
|
33
33
|
const batchSize = 1000;
|
|
34
34
|
let skip = 0;
|
|
35
35
|
let foundOrder = null;
|
|
36
|
+
let foundOrderOldFormat = null;
|
|
36
37
|
while (!foundOrder) {
|
|
37
38
|
// Query only active orders (exclude completed/cancelled/failed) in batches
|
|
38
39
|
const orders = yield Order.find({
|
|
@@ -47,19 +48,29 @@ const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0,
|
|
|
47
48
|
break;
|
|
48
49
|
}
|
|
49
50
|
// Check each order ID against the reference
|
|
50
|
-
//
|
|
51
|
+
// Priority 1: New format - 2 chars from random portion (8-9) + last 6 chars
|
|
52
|
+
// Priority 2: Old format - just last 6 chars (backwards compatibility)
|
|
51
53
|
for (const order of orders) {
|
|
52
54
|
const orderId = order._id.toString().toLowerCase();
|
|
53
55
|
const randomPrefix = orderId.slice(8, 10);
|
|
54
56
|
const last6 = orderId.slice(-6);
|
|
55
57
|
const reference8Chars = randomPrefix + last6;
|
|
58
|
+
// Check new 8-char format first (takes priority)
|
|
56
59
|
if (referenceText.includes(reference8Chars)) {
|
|
57
60
|
foundOrder = yield Order.findById(order._id);
|
|
58
61
|
break;
|
|
59
62
|
}
|
|
63
|
+
// Track old 6-char format match as fallback (only if no 8-char match yet)
|
|
64
|
+
if (!foundOrderOldFormat && referenceText.includes(last6)) {
|
|
65
|
+
foundOrderOldFormat = yield Order.findById(order._id);
|
|
66
|
+
}
|
|
60
67
|
}
|
|
61
68
|
skip += batchSize;
|
|
62
69
|
}
|
|
70
|
+
// Use 8-char match if found, otherwise fall back to 6-char match
|
|
71
|
+
if (!foundOrder && foundOrderOldFormat) {
|
|
72
|
+
foundOrder = foundOrderOldFormat;
|
|
73
|
+
}
|
|
63
74
|
if (!foundOrder) {
|
|
64
75
|
throw new Error("Order not found");
|
|
65
76
|
}
|