ismx-nexo-node-app 0.4.98 → 0.4.100

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.
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const LoopbackBusiness_1 = __importDefault(require("./LoopbackBusiness"));
16
+ const RepositoryRest_1 = __importDefault(require("../repository/RepositoryRest"));
16
17
  class FormalLoopbackBusiness extends LoopbackBusiness_1.default {
17
18
  constructor() {
18
19
  super();
@@ -79,7 +80,8 @@ class FormalLoopbackBusiness extends LoopbackBusiness_1.default {
79
80
  return __awaiter(this, void 0, void 0, function* () {
80
81
  let result = yield call();
81
82
  if (result.ok) {
82
- let wrapper = yield result.json();
83
+ let content = yield result.text();
84
+ let wrapper = JSON.parse(content, RepositoryRest_1.default.defaultReviver);
83
85
  return wrapper.data;
84
86
  }
85
87
  else {
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ProxyBusiness_1 = __importDefault(require("./ProxyBusiness"));
16
+ const RepositoryRest_1 = __importDefault(require("../repository/RepositoryRest"));
16
17
  class FormalProxyBusiness extends ProxyBusiness_1.default {
17
18
  constructor() {
18
19
  super();
@@ -79,7 +80,8 @@ class FormalProxyBusiness extends ProxyBusiness_1.default {
79
80
  return __awaiter(this, void 0, void 0, function* () {
80
81
  let result = yield call();
81
82
  if (result.ok) {
82
- let wrapper = yield result.json();
83
+ let content = yield result.text();
84
+ let wrapper = JSON.parse(content, RepositoryRest_1.default.defaultReviver);
83
85
  return wrapper.data;
84
86
  }
85
87
  else {
@@ -74,4 +74,10 @@ class RepositoryRest extends Repository_1.default {
74
74
  return value;
75
75
  }
76
76
  }
77
+ RepositoryRest.defaultReviver = (key, value) => {
78
+ if (DateUtils_1.default.isIsoDate(value))
79
+ return new Date(value);
80
+ else
81
+ return value;
82
+ };
77
83
  exports.default = RepositoryRest;
@@ -13,4 +13,5 @@ export default class RepositoryRest<Body = any, Res = any> extends Repository {
13
13
  constructor(baseUrl: string, options?: RestOptions);
14
14
  call<B = Body, E = Res>(method?: string, endpoint?: string, request?: HttpRequest<B>): Promise<HttpResponse<E>>;
15
15
  private reviver;
16
+ static defaultReviver: (key: string, value: string) => string | Date;
16
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.98",
3
+ "version": "0.4.100",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -4,6 +4,8 @@ import {Wrapper} from "../api/ServiceRestFormal";
4
4
  import Business from "./Business";
5
5
  import fetch from "node-fetch";
6
6
  import LoopbackBusiness from "./LoopbackBusiness";
7
+ import RepositoryRestFormal from "../repository/RepositoryRestFormal";
8
+ import RepositoryRest from "../repository/RepositoryRest";
7
9
 
8
10
  export default class FormalLoopbackBusiness extends LoopbackBusiness {
9
11
 
@@ -58,8 +60,9 @@ export default class FormalLoopbackBusiness extends LoopbackBusiness {
58
60
  private async deformalize<Res>(call: () => Promise<fetch.Response>): Promise<Res> {
59
61
  let result = await call();
60
62
  if (result.ok) {
61
- let wrapper = await result.json() as Wrapper<Res>;
62
- return wrapper.data;
63
+ let content = await result.text();
64
+ let wrapper = JSON.parse(content, RepositoryRest.defaultReviver);
65
+ return wrapper.data as Res;
63
66
  } else {
64
67
  const errorBody = await result.json();
65
68
  throw new Error(JSON.stringify(errorBody));
@@ -3,6 +3,7 @@ import ProxyBusiness from "./ProxyBusiness";
3
3
  import {Wrapper} from "../api/ServiceRestFormal";
4
4
  import Business from "./Business";
5
5
  import fetch from "node-fetch";
6
+ import RepositoryRest from "../repository/RepositoryRest";
6
7
 
7
8
  export default class FormalProxyBusiness extends ProxyBusiness {
8
9
 
@@ -57,8 +58,9 @@ export default class FormalProxyBusiness extends ProxyBusiness {
57
58
  private async deformalize<Res>(call: () => Promise<fetch.Response>): Promise<Res> {
58
59
  let result = await call();
59
60
  if (result.ok) {
60
- let wrapper = await result.json() as Wrapper<Res>;
61
- return wrapper.data;
61
+ let content = await result.text();
62
+ let wrapper = JSON.parse(content, RepositoryRest.defaultReviver);
63
+ return wrapper.data as Res;
62
64
  } else {
63
65
  const errorBody = await result.json();
64
66
  throw new Error(JSON.stringify(errorBody));
@@ -86,5 +86,10 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
86
86
  return value;
87
87
  }
88
88
 
89
+ static defaultReviver = (key: string, value: string) => {
90
+ if (DateUtils.isIsoDate(value)) return new Date(value);
91
+ else return value;
92
+ }
93
+
89
94
 
90
95
  }