@riocrypto/common-server 1.0.1756 → 1.0.1757

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.
@@ -10,22 +10,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getOrderFromReference = void 0;
13
- const user_1 = require("../models/user");
14
13
  const order_1 = require("../models/order");
14
+ const user_1 = require("../models/user");
15
15
  const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  // Extract the last 2 characters (userId part) and the last 4 characters (orderId part)
17
- const userIdPart = reference.slice(0, 2);
18
- const orderIdPart = reference.slice(2, 6);
19
- // Fetch all users and filter them by the last 2 characters of their ObjectId
17
+ const userIdPart = reference.slice(0, 2).toLocaleLowerCase();
18
+ const orderIdPart = reference.slice(2, 6).toLocaleLowerCase();
20
19
  const User = (0, user_1.buildUser)(mongoose);
21
20
  const users = yield User.find().exec();
22
- const user = users.find((user) => user.id.endsWith(userIdPart));
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
+ });
23
30
  if (!user) {
24
31
  throw new Error("User not found");
25
32
  }
26
33
  const Order = (0, order_1.buildOrder)(mongoose);
27
34
  // 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();
35
+ const orders = yield Order.find({ userId: user.id }).exec();
29
36
  const order = orders.find((order) => order.id.endsWith(orderIdPart));
30
37
  if (!order) {
31
38
  throw new Error("Order not found");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1756",
3
+ "version": "1.0.1757",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",