@riocrypto/common-server 1.0.1755 → 1.0.1756
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.
|
@@ -16,18 +16,20 @@ const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0,
|
|
|
16
16
|
// Extract the last 2 characters (userId part) and the last 4 characters (orderId part)
|
|
17
17
|
const userIdPart = reference.slice(0, 2);
|
|
18
18
|
const orderIdPart = reference.slice(2, 6);
|
|
19
|
-
//
|
|
19
|
+
// Fetch all users and filter them by the last 2 characters of their ObjectId
|
|
20
20
|
const User = (0, user_1.buildUser)(mongoose);
|
|
21
|
-
const
|
|
21
|
+
const users = yield User.find().exec();
|
|
22
|
+
const user = users.find((user) => user.id.endsWith(userIdPart));
|
|
22
23
|
if (!user) {
|
|
23
24
|
throw new Error("User not found");
|
|
24
25
|
}
|
|
25
26
|
const Order = (0, order_1.buildOrder)(mongoose);
|
|
26
|
-
//
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
// Fetch all orders for the user and filter them by the last 4 characters of their ObjectId
|
|
28
|
+
const orders = yield Order.find({ userId: user._id }).exec();
|
|
29
|
+
const order = orders.find((order) => order.id.endsWith(orderIdPart));
|
|
30
|
+
if (!order) {
|
|
31
|
+
throw new Error("Order not found");
|
|
32
|
+
}
|
|
31
33
|
return order;
|
|
32
34
|
});
|
|
33
35
|
exports.getOrderFromReference = getOrderFromReference;
|