@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
- // Find the user whose ID ends with the extracted userIdPart
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 user = yield User.findOne({ _id: { $regex: userIdPart + "$" } }).exec();
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
- // Find the order whose ID ends with the extracted orderIdPart and belongs to the user
27
- const order = yield Order.findOne({
28
- _id: { $regex: orderIdPart + "$" },
29
- userId: user._id,
30
- }).exec();
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1755",
3
+ "version": "1.0.1756",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",