@riocrypto/common 1.0.424 → 1.0.426

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.
@@ -8,4 +8,4 @@ declare global {
8
8
  }
9
9
  }
10
10
  }
11
- export declare const getOrder: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose) => Promise<void>;
11
+ export declare const getOrder: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose, onlyBankOrders?: boolean) => Promise<void>;
@@ -12,8 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getOrder = void 0;
13
13
  const not_authorized_error_1 = require("../errors/not-authorized-error");
14
14
  const not_found_error_1 = require("../errors/not-found-error");
15
+ const wrong_processor_error_1 = require("../errors/wrong-processor-error");
15
16
  const order_1 = require("../models/order");
16
- const getOrder = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const processor_1 = require("../types/processor");
18
+ const getOrder = (req, res, next, mongoose, onlyBankOrders) => __awaiter(void 0, void 0, void 0, function* () {
17
19
  var _a;
18
20
  let orderId = "";
19
21
  if (req.body.orderId) {
@@ -25,22 +27,39 @@ const getOrder = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0,
25
27
  else if (req.query.orderId) {
26
28
  orderId = req.query.orderId;
27
29
  }
28
- if (!orderId) {
29
- throw new Error("Failed to provide orderId");
30
- }
31
- try {
32
- const Order = yield (0, order_1.buildOrder)(mongoose);
33
- const order = yield Order.findById(orderId);
34
- if (!order) {
35
- throw new Error();
30
+ if (orderId) {
31
+ try {
32
+ const Order = yield (0, order_1.buildOrder)(mongoose);
33
+ const order = yield Order.findById(orderId);
34
+ if (!order) {
35
+ throw new Error();
36
+ }
37
+ console.log("order", order.toJSON());
38
+ if (onlyBankOrders) {
39
+ if ([
40
+ processor_1.Processor.Interbank,
41
+ processor_1.Processor.SPEI,
42
+ processor_1.Processor.SWIFT,
43
+ processor_1.Processor.SPID,
44
+ ].includes(order.processor)) {
45
+ req.order = order;
46
+ }
47
+ else {
48
+ throw new wrong_processor_error_1.WrongProcessorError();
49
+ }
50
+ }
51
+ else {
52
+ req.order = order;
53
+ }
54
+ }
55
+ catch (error) {
56
+ console.log(error);
57
+ console.log("kakakaka");
58
+ throw new not_found_error_1.NotFoundError();
59
+ }
60
+ if (req.order.userId !== ((_a = req.user) === null || _a === void 0 ? void 0 : _a.toJSON().id) && !req.currentAdminAuth) {
61
+ throw new not_authorized_error_1.NotAuthorizedError();
36
62
  }
37
- req.order = order;
38
- }
39
- catch (error) {
40
- throw new not_found_error_1.NotFoundError();
41
- }
42
- if (req.order.userId !== ((_a = req.user) === null || _a === void 0 ? void 0 : _a.toJSON().id) && !req.currentAdminAuth) {
43
- throw new not_authorized_error_1.NotAuthorizedError();
44
63
  }
45
64
  next();
46
65
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.424",
3
+ "version": "1.0.426",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",