@riocrypto/common-server 1.0.1577 → 1.0.1579

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.
@@ -1,3 +1,2 @@
1
- import { User } from "@riocrypto/common";
2
1
  import { CustomValidator } from "express-validator";
3
- export declare const requireAdminAuthIfDefined: (user: User) => CustomValidator;
2
+ export declare const requireAdminAuthIfDefined: CustomValidator;
@@ -1,15 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireAdminAuthIfDefined = void 0;
4
- const common_1 = require("@riocrypto/common");
5
- const requireAdminAuthIfDefined = (user) => (value, { req, path }) => {
4
+ const requireAdminAuthIfDefined = (value, { req, path }) => {
5
+ console.log("path", path);
6
+ console.log("value", value);
7
+ console.log("current value", getValueByPath(req.userToUpdate, path));
6
8
  if (value !== undefined &&
7
9
  value !== "" &&
8
10
  !req.adminAuth &&
9
11
  // @ts-ignore
10
- (user[path] !== undefined || user[path] !== "")) {
11
- throw new common_1.AdminOnlyError();
12
+ getValueByPath(req.userToUpdate, path) !== undefined &&
13
+ getValueByPath(req.userToUpdate, path) !== "" &&
14
+ // @ts-ignore
15
+ getValueByPath(req.userToUpdate, path) !== value) {
16
+ return false;
12
17
  }
13
18
  return true;
14
19
  };
15
20
  exports.requireAdminAuthIfDefined = requireAdminAuthIfDefined;
21
+ function getValueByPath(obj, path) {
22
+ const keys = path.split(".");
23
+ let current = obj;
24
+ for (let key of keys) {
25
+ // @ts-ignore
26
+ if (!current[key]) {
27
+ return undefined;
28
+ }
29
+ // @ts-ignore
30
+ current = current[key];
31
+ }
32
+ return current;
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1577",
3
+ "version": "1.0.1579",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@google-cloud/storage": "^6.9.5",
29
29
  "@google-cloud/vision": "^4.0.2",
30
30
  "@hyperdx/node-opentelemetry": "^0.4.2",
31
- "@riocrypto/common": "^1.0.1406",
31
+ "@riocrypto/common": "^1.0.1407",
32
32
  "@types/express": "^4.17.13",
33
33
  "axios": "^1.6.0",
34
34
  "ccxt": "^3.0.30",