@riocrypto/common-server 1.0.1757 → 1.0.1759
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.
|
@@ -2,14 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateReference = void 0;
|
|
4
4
|
const generateReference = (order) => {
|
|
5
|
-
|
|
6
|
-
const mongoIdRegex = /^[a-f\d]{24}$/i;
|
|
7
|
-
if (!mongoIdRegex.test(order.userId) || !mongoIdRegex.test(order.id)) {
|
|
8
|
-
throw new Error("Invalid MongoDB ObjectID format");
|
|
9
|
-
}
|
|
10
|
-
const userIdLast2 = order.userId.slice(-2);
|
|
11
|
-
const orderIdLast4 = order.id.slice(-4);
|
|
12
|
-
const referenceNumber = userIdLast2 + orderIdLast4;
|
|
5
|
+
const referenceNumber = order.id.slice(-6);
|
|
13
6
|
return referenceNumber;
|
|
14
7
|
};
|
|
15
8
|
exports.generateReference = generateReference;
|
|
@@ -11,29 +11,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getOrderFromReference = void 0;
|
|
13
13
|
const order_1 = require("../models/order");
|
|
14
|
-
const
|
|
14
|
+
const common_1 = require("@riocrypto/common");
|
|
15
15
|
const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const User = (0, user_1.buildUser)(mongoose);
|
|
20
|
-
const users = yield User.find().exec();
|
|
21
|
-
// Ensure userIdPart is defined and only contains two characters
|
|
22
|
-
if (!userIdPart || userIdPart.length !== 2) {
|
|
23
|
-
throw new Error("Invalid userIdPart. It must be exactly 2 characters long.");
|
|
24
|
-
}
|
|
25
|
-
// Find the user whose id ends with the given part
|
|
26
|
-
const user = users.find((user) => {
|
|
27
|
-
const userIdStr = user.id.toString(); // Convert id to string if it isn't
|
|
28
|
-
return userIdStr.endsWith(userIdPart);
|
|
29
|
-
});
|
|
30
|
-
if (!user) {
|
|
31
|
-
throw new Error("User not found");
|
|
16
|
+
// Ensure reference is defined and exactly 6 characters long
|
|
17
|
+
if (!reference || reference.length !== 6) {
|
|
18
|
+
throw new Error("Invalid reference. It must be exactly 6 characters long.");
|
|
32
19
|
}
|
|
20
|
+
// Convert reference to lowercase to ensure case-insensitive comparison
|
|
21
|
+
const orderIdPart = reference.toLowerCase();
|
|
33
22
|
const Order = (0, order_1.buildOrder)(mongoose);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
const orders = yield Order.find({
|
|
24
|
+
status: { $in: [common_1.OrderStatus.AwaitingPayment, common_1.OrderStatus.Processing] },
|
|
25
|
+
});
|
|
26
|
+
const order = orders.find((order) => order.id.toString().endsWith(orderIdPart));
|
|
37
27
|
if (!order) {
|
|
38
28
|
throw new Error("Order not found");
|
|
39
29
|
}
|