@riocrypto/common 1.0.462 → 1.0.463

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.
@@ -3,6 +3,7 @@ import { BusinessUserDoc } from "../models/business-user";
3
3
  import { UserDoc } from "../models/user";
4
4
  import { Mongoose } from "mongoose";
5
5
  import { AuthorizationType } from "../types/authorization-type";
6
+ import { PartnerDoc } from "../models/partner";
6
7
  interface AuthPayload {
7
8
  id: string;
8
9
  phoneNumber: string;
@@ -18,6 +19,7 @@ declare global {
18
19
  currentAuth?: AuthPayload;
19
20
  currentAdminAuth?: AdminAuthPayload;
20
21
  user?: UserDoc | BusinessUserDoc;
22
+ partner?: PartnerDoc;
21
23
  session?: any;
22
24
  }
23
25
  }
@@ -26,13 +26,15 @@ const missing_password_error_1 = require("../errors/missing-password-error");
26
26
  const missing_security_question_error_1 = require("../errors/missing-security-question-error");
27
27
  const admin_only_error_1 = require("../errors/admin-only-error");
28
28
  const not_broker_error_1 = require("../errors/not-broker-error");
29
+ const partner_1 = require("../models/partner");
29
30
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
30
31
  var _a, _b, _c, _d, _e, _f, _g, _h;
31
32
  let missingKYC = false;
32
33
  if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth) ||
33
34
  authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC) ||
34
35
  authorizationTypes.includes(authorization_type_1.AuthorizationType.User) ||
35
- authorizationTypes.includes(authorization_type_1.AuthorizationType.Broker)) {
36
+ authorizationTypes.includes(authorization_type_1.AuthorizationType.Broker) ||
37
+ authorizationTypes.includes(authorization_type_1.AuthorizationType.Partner)) {
36
38
  if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.jwt) {
37
39
  try {
38
40
  const payload = jsonwebtoken_1.default.verify(req.cookies.jwt, process.env.JWT_KEY);
@@ -56,6 +58,15 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
56
58
  catch (err) { }
57
59
  }
58
60
  }
61
+ if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Partner)) {
62
+ const Partner = yield (0, partner_1.buildPartner)(mongoose);
63
+ const partner = yield Partner.findOne({
64
+ authId: req.currentAuth.id,
65
+ });
66
+ if (partner) {
67
+ req.partner = partner;
68
+ }
69
+ }
59
70
  if (authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC)) {
60
71
  let individualUser;
61
72
  let businessUser;
@@ -149,7 +160,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
149
160
  req.user = user;
150
161
  }
151
162
  }
152
- if ((!req.currentAdminAuth && !req.currentAuth && !req.user) ||
163
+ if ((!req.currentAdminAuth && !req.currentAuth && !req.user && !req.partner) ||
153
164
  (req.currentAuth &&
154
165
  !authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth) &&
155
166
  !req.user)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.462",
3
+ "version": "1.0.463",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",