@etsoo/appscript 1.3.6 → 1.3.8

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.
Files changed (112) hide show
  1. package/README.md +2 -14
  2. package/__tests__/app/CoreApp.ts +14 -14
  3. package/lib/cjs/address/AddressUtils.d.ts +0 -20
  4. package/lib/cjs/address/AddressUtils.js +0 -60
  5. package/lib/cjs/app/CoreApp.d.ts +11 -1
  6. package/lib/cjs/app/CoreApp.js +18 -2
  7. package/lib/cjs/app/IApp.d.ts +6 -0
  8. package/lib/cjs/erp/AddressApi.d.ts +13 -9
  9. package/lib/cjs/erp/AddressApi.js +23 -25
  10. package/lib/cjs/erp/BaseApi.d.ts +5 -3
  11. package/lib/cjs/erp/BaseApi.js +3 -1
  12. package/lib/cjs/erp/EntityApi.d.ts +78 -0
  13. package/lib/cjs/erp/EntityApi.js +91 -0
  14. package/lib/cjs/erp/OrgApi.d.ts +32 -5
  15. package/lib/cjs/erp/OrgApi.js +30 -12
  16. package/lib/cjs/erp/PublicApi.js +5 -5
  17. package/lib/cjs/{dto → erp/dto}/IdLabelDto.d.ts +0 -0
  18. package/lib/cjs/{dto → erp/dto}/IdLabelDto.js +0 -0
  19. package/lib/cjs/{dto → erp/dto}/IdLabelPrimaryDto.d.ts +0 -0
  20. package/lib/cjs/{dto → erp/dto}/IdLabelPrimaryDto.js +0 -0
  21. package/lib/cjs/{dto → erp/dto}/InitCallDto.d.ts +0 -0
  22. package/lib/cjs/{dto → erp/dto}/InitCallDto.js +0 -0
  23. package/lib/cjs/erp/dto/OrgQueryDto.d.ts +21 -0
  24. package/lib/cjs/{rq/LoginIdRQ.js → erp/dto/OrgQueryDto.js} +0 -0
  25. package/lib/cjs/erp/rq/OrgListRQ.d.ts +10 -0
  26. package/lib/cjs/{rq/LoginRQ.js → erp/rq/OrgListRQ.js} +0 -0
  27. package/lib/cjs/erp/rq/OrgQueryRQ.d.ts +14 -0
  28. package/lib/cjs/{rq/QueryRQ.js → erp/rq/OrgQueryRQ.js} +0 -0
  29. package/lib/cjs/erp/rq/OrgRQ.d.ts +25 -0
  30. package/lib/cjs/{rq/TiplistRQ.js → erp/rq/OrgRQ.js} +0 -0
  31. package/lib/cjs/{rq → erp/rq}/QueryRQ.d.ts +0 -0
  32. package/lib/cjs/erp/rq/QueryRQ.js +2 -0
  33. package/lib/cjs/erp/rq/RefreshTokenRQ.d.ts +29 -0
  34. package/lib/cjs/erp/rq/RefreshTokenRQ.js +2 -0
  35. package/lib/cjs/{rq → erp/rq}/TiplistRQ.d.ts +0 -0
  36. package/lib/cjs/erp/rq/TiplistRQ.js +2 -0
  37. package/lib/cjs/i18n/en-US.json +20 -0
  38. package/lib/cjs/i18n/zh-CN.json +20 -0
  39. package/lib/cjs/i18n/zh-HK.json +20 -0
  40. package/lib/cjs/index.d.ts +7 -7
  41. package/lib/cjs/index.js +10 -10
  42. package/lib/mjs/address/AddressUtils.d.ts +0 -20
  43. package/lib/mjs/address/AddressUtils.js +0 -37
  44. package/lib/mjs/app/CoreApp.d.ts +11 -1
  45. package/lib/mjs/app/CoreApp.js +18 -2
  46. package/lib/mjs/app/IApp.d.ts +6 -0
  47. package/lib/mjs/erp/AddressApi.d.ts +13 -9
  48. package/lib/mjs/erp/AddressApi.js +23 -25
  49. package/lib/mjs/erp/BaseApi.d.ts +5 -3
  50. package/lib/mjs/erp/BaseApi.js +3 -1
  51. package/lib/mjs/erp/EntityApi.d.ts +78 -0
  52. package/lib/mjs/erp/EntityApi.js +87 -0
  53. package/lib/mjs/erp/OrgApi.d.ts +32 -5
  54. package/lib/mjs/erp/OrgApi.js +30 -12
  55. package/lib/mjs/erp/PublicApi.js +5 -5
  56. package/lib/mjs/{dto → erp/dto}/IdLabelDto.d.ts +0 -0
  57. package/lib/mjs/{dto → erp/dto}/IdLabelDto.js +0 -0
  58. package/lib/mjs/{dto → erp/dto}/IdLabelPrimaryDto.d.ts +0 -0
  59. package/lib/mjs/{dto → erp/dto}/IdLabelPrimaryDto.js +0 -0
  60. package/lib/mjs/{dto → erp/dto}/InitCallDto.d.ts +0 -0
  61. package/lib/mjs/{dto → erp/dto}/InitCallDto.js +0 -0
  62. package/lib/mjs/erp/dto/OrgQueryDto.d.ts +21 -0
  63. package/lib/mjs/{rq/LoginIdRQ.js → erp/dto/OrgQueryDto.js} +0 -0
  64. package/lib/mjs/erp/rq/OrgListRQ.d.ts +10 -0
  65. package/lib/mjs/{rq/LoginRQ.js → erp/rq/OrgListRQ.js} +0 -0
  66. package/lib/mjs/erp/rq/OrgQueryRQ.d.ts +14 -0
  67. package/lib/mjs/{rq/QueryRQ.js → erp/rq/OrgQueryRQ.js} +0 -0
  68. package/lib/mjs/erp/rq/OrgRQ.d.ts +25 -0
  69. package/lib/mjs/{rq/TiplistRQ.js → erp/rq/OrgRQ.js} +0 -0
  70. package/lib/mjs/{rq → erp/rq}/QueryRQ.d.ts +0 -0
  71. package/lib/mjs/erp/rq/QueryRQ.js +1 -0
  72. package/lib/mjs/erp/rq/RefreshTokenRQ.d.ts +29 -0
  73. package/lib/mjs/erp/rq/RefreshTokenRQ.js +1 -0
  74. package/lib/mjs/{rq → erp/rq}/TiplistRQ.d.ts +0 -0
  75. package/lib/mjs/erp/rq/TiplistRQ.js +1 -0
  76. package/lib/mjs/i18n/en-US.json +20 -0
  77. package/lib/mjs/i18n/zh-CN.json +20 -0
  78. package/lib/mjs/i18n/zh-HK.json +20 -0
  79. package/lib/mjs/index.d.ts +7 -7
  80. package/lib/mjs/index.js +10 -10
  81. package/package.json +4 -4
  82. package/src/address/AddressUtils.ts +0 -45
  83. package/src/app/CoreApp.ts +21 -2
  84. package/src/app/IApp.ts +7 -0
  85. package/src/erp/AddressApi.ts +19 -22
  86. package/src/erp/BaseApi.ts +3 -2
  87. package/src/erp/EntityApi.ts +142 -0
  88. package/src/erp/OrgApi.ts +66 -19
  89. package/src/erp/PublicApi.ts +5 -7
  90. package/src/{dto → erp/dto}/IdLabelDto.ts +0 -0
  91. package/src/{dto → erp/dto}/IdLabelPrimaryDto.ts +0 -0
  92. package/src/{dto → erp/dto}/InitCallDto.ts +0 -0
  93. package/src/erp/dto/OrgQueryDto.ts +24 -0
  94. package/src/erp/rq/OrgListRQ.ts +11 -0
  95. package/src/erp/rq/OrgQueryRQ.ts +16 -0
  96. package/src/erp/rq/OrgRQ.ts +29 -0
  97. package/src/{rq → erp/rq}/QueryRQ.ts +0 -0
  98. package/src/erp/rq/RefreshTokenRQ.ts +34 -0
  99. package/src/{rq → erp/rq}/TiplistRQ.ts +0 -0
  100. package/src/i18n/en-US.json +20 -0
  101. package/src/i18n/zh-CN.json +20 -0
  102. package/src/i18n/zh-HK.json +20 -0
  103. package/src/index.ts +11 -12
  104. package/lib/cjs/rq/LoginIdRQ.d.ts +0 -17
  105. package/lib/cjs/rq/LoginRQ.d.ts +0 -22
  106. package/lib/mjs/rq/LoginIdRQ.d.ts +0 -17
  107. package/lib/mjs/rq/LoginRQ.d.ts +0 -22
  108. package/src/i18n/address.en-US.json +0 -21
  109. package/src/i18n/address.zh-CN.json +0 -21
  110. package/src/i18n/address.zh-HK.json +0 -21
  111. package/src/rq/LoginIdRQ.ts +0 -19
  112. package/src/rq/LoginRQ.ts +0 -26
package/README.md CHANGED
@@ -91,20 +91,6 @@ $ yarn add @etsoo/appscript
91
91
  #### ListItem.ts ####
92
92
  - ListItem - List item definition
93
93
 
94
- ### dto - Data transfer object
95
-
96
- #### IdDto.ts ####
97
- - IdDto - Dto with id field
98
-
99
- #### IdLabelDto.ts ####
100
- - IdLabelDto - Dto with id and label field
101
-
102
- #### IdLabelPrimaryDto.ts ####
103
- - IdLabelPrimaryDto - Dto with id, label and primary field
104
-
105
- #### IdLabelPrimaryDto.ts ####
106
- - InitCallDto - Init call dto
107
-
108
94
  ### i18n - Multiple cultures
109
95
 
110
96
  ### result - API action result
@@ -126,6 +112,8 @@ $ yarn add @etsoo/appscript
126
112
  - InitCallResultData - Init call result data
127
113
  - InitCallResult - Init call result
128
114
 
115
+ ### erp - SmartERP APIs
116
+
129
117
  ### state - State management
130
118
 
131
119
  #### Culture.ts ####
@@ -13,6 +13,7 @@ import {
13
13
  enUS,
14
14
  ExternalSettings,
15
15
  IUser,
16
+ OrgApi,
16
17
  PublicApi,
17
18
  UserRole
18
19
  } from '../../src';
@@ -130,12 +131,14 @@ class CoreAppTest extends CoreApp<
130
131
  }
131
132
  }
132
133
 
134
+ // Mixins example
133
135
  function EnhanceApp<TBase extends DataTypes.MConstructor<CoreAppTest>>(
134
136
  Base: TBase
135
137
  ) {
136
138
  return class extends Base {
137
139
  readonly addressApi = new AddressApi(this);
138
140
  readonly publicApi = new PublicApi(this);
141
+ readonly orgApi = new OrgApi(this);
139
142
  };
140
143
  }
141
144
 
@@ -143,6 +146,10 @@ const appClass = EnhanceApp(CoreAppTest);
143
146
  const app = new appClass();
144
147
  app.changeCulture(app.settings.cultures[0]);
145
148
 
149
+ test('Test for properties', () => {
150
+ expect(app.settings.currentRegion.label).toBe('中国大陆');
151
+ });
152
+
146
153
  test('Tests for addRootUrl', () => {
147
154
  expect(app.addRootUrl('/home')).toBe('/cms/home');
148
155
  expect(app.addRootUrl('./home')).toBe('/cms/./home');
@@ -201,10 +208,7 @@ test('Tests for addressApi', async () => {
201
208
  const continents = await app.addressApi.continents();
202
209
  expect(continents.length).toBe(7);
203
210
 
204
- const labels = await AddressUtils.getLabels('en-US');
205
- expect(labels['regionHK']).toBe('Hong Kong, China');
206
-
207
- const regions = await app.addressApi.regions('zh-CN');
211
+ const regions = await app.addressApi.regions();
208
212
  const cn = regions.find((r) => r.id === 'CN');
209
213
  expect(cn?.label).toBe('中国大陆');
210
214
  });
@@ -218,15 +222,11 @@ test('Tests for publicApi', async () => {
218
222
  const currencies = await app.publicApi.currencies(['NZD', 'AUD', 'USD']);
219
223
  expect(currencies[1].id).toBe('AUD');
220
224
 
221
- //const currenciesRemote = await app.publicApi.currencies();
222
- //console.log(currenciesRemote);
223
-
224
- //const history = await app.publicApi.exchangeRateHistory(['NZD', 'AUD'], 24);
225
- //console.log(history);
226
-
227
- //const qrcode = await app.publicApi.mobileQRCode('xz@etsoo.com');
228
- //console.log(qrcode);
225
+ /*
226
+ const orgs = await app.orgApi.list();
227
+ console.log(orgs);
229
228
 
230
- //const exchangeRate = await app.publicApi.exchangeRate('USD');
231
- //console.log(exchangeRate);
229
+ const orgsQuery = await app.orgApi.query({ currentPage: 1, batchSize: 2 });
230
+ console.log(orgsQuery);
231
+ */
232
232
  });
@@ -1,15 +1,8 @@
1
- import { DataTypes } from '@etsoo/shared';
2
1
  import { AddressRegion } from './AddressRegion';
3
2
  /**
4
3
  * Address utils
5
4
  */
6
5
  export declare namespace AddressUtils {
7
- /**
8
- * Get address labels
9
- * @param language Language
10
- * @returns Result
11
- */
12
- function getLabels(language: string): Promise<DataTypes.StringRecord>;
13
6
  /**
14
7
  * Get region from regions and detected region and language
15
8
  * @param regions Supported regions
@@ -17,17 +10,4 @@ export declare namespace AddressUtils {
17
10
  * @param detectedLanguage Detected language
18
11
  */
19
12
  function getRegion(regions: string[], detectedRegion?: string | null, detectedLanguage?: string | null): AddressRegion;
20
- /**
21
- * Get region label
22
- * @param id Region id
23
- * @param labels Labels
24
- * @returns Label
25
- */
26
- function getRegionLabel(id: string, labels: DataTypes.StringRecord): string;
27
- /**
28
- * Update region label
29
- * @param region Region
30
- * @param culture Culture
31
- */
32
- function updateRegionLabel(region: AddressRegion, culture: string): Promise<void>;
33
13
  }
@@ -1,51 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.AddressUtils = void 0;
27
4
  const AddressRegion_1 = require("./AddressRegion");
28
- const languageLabels = {};
29
5
  /**
30
6
  * Address utils
31
7
  */
32
8
  var AddressUtils;
33
9
  (function (AddressUtils) {
34
- /**
35
- * Get address labels
36
- * @param language Language
37
- * @returns Result
38
- */
39
- async function getLabels(language) {
40
- let labels = languageLabels[language];
41
- if (labels == null) {
42
- labels = await Promise.resolve().then(() => __importStar(require(`./../i18n/address.${language}.json`)));
43
- // Cache
44
- languageLabels[language] = labels;
45
- }
46
- return labels;
47
- }
48
- AddressUtils.getLabels = getLabels;
49
10
  /**
50
11
  * Get region from regions and detected region and language
51
12
  * @param regions Supported regions
@@ -71,25 +32,4 @@ var AddressUtils;
71
32
  return AddressRegion_1.AddressRegion.getById(regions[0]);
72
33
  }
73
34
  AddressUtils.getRegion = getRegion;
74
- /**
75
- * Get region label
76
- * @param id Region id
77
- * @param labels Labels
78
- * @returns Label
79
- */
80
- function getRegionLabel(id, labels) {
81
- var _a;
82
- return (_a = labels['region' + id]) !== null && _a !== void 0 ? _a : id;
83
- }
84
- AddressUtils.getRegionLabel = getRegionLabel;
85
- /**
86
- * Update region label
87
- * @param region Region
88
- * @param culture Culture
89
- */
90
- async function updateRegionLabel(region, culture) {
91
- const labels = await AddressUtils.getLabels(culture);
92
- region.label = getRegionLabel(region.id, labels);
93
- }
94
- AddressUtils.updateRegionLabel = updateRegionLabel;
95
35
  })(AddressUtils = exports.AddressUtils || (exports.AddressUtils = {}));
@@ -2,7 +2,7 @@ import { INotifier, NotificationAlign, NotificationCallProps, NotificationConten
2
2
  import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
3
3
  import { DataTypes, DateUtils, IStorage, ListType, ListType1 } from '@etsoo/shared';
4
4
  import { AddressRegion } from '../address/AddressRegion';
5
- import { InitCallDto } from '../dto/InitCallDto';
5
+ import { InitCallDto } from '../erp/dto/InitCallDto';
6
6
  import { IActionResult } from '../result/IActionResult';
7
7
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
8
8
  import { IUser } from '../state/User';
@@ -216,6 +216,10 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
216
216
  * @param culture New culture definition
217
217
  */
218
218
  changeCulture(culture: DataTypes.CultureDefinition): void;
219
+ /**
220
+ * Update current region label
221
+ */
222
+ protected updateRegionLabel(): void;
219
223
  /**
220
224
  * Check language is supported or not, return a valid language when supported
221
225
  * @param language Language
@@ -360,6 +364,12 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
360
364
  * @returns List
361
365
  */
362
366
  protected getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): ListType1[];
367
+ /**
368
+ * Get region label
369
+ * @param id Region id
370
+ * @returns Label
371
+ */
372
+ getRegionLabel(id: string): string;
363
373
  /**
364
374
  * Get all regions
365
375
  * @returns Regions
@@ -6,7 +6,6 @@ const restclient_1 = require("@etsoo/restclient");
6
6
  const shared_1 = require("@etsoo/shared");
7
7
  const crypto_js_1 = require("crypto-js");
8
8
  const AddressRegion_1 = require("../address/AddressRegion");
9
- const AddressUtils_1 = require("../address/AddressUtils");
10
9
  const BridgeUtils_1 = require("../bridges/BridgeUtils");
11
10
  const EntityStatus_1 = require("../business/EntityStatus");
12
11
  const ActionResultError_1 = require("../result/ActionResultError");
@@ -487,8 +486,8 @@ class CoreApp {
487
486
  this._currency = regionItem.currency;
488
487
  this._region = regionId;
489
488
  // Hold the current country or region
490
- AddressUtils_1.AddressUtils.updateRegionLabel(regionItem, this._culture);
491
489
  this.settings.currentRegion = regionItem;
490
+ this.updateRegionLabel();
492
491
  }
493
492
  /**
494
493
  * Change culture
@@ -509,6 +508,14 @@ class CoreApp {
509
508
  this._culture = name;
510
509
  // Hold the current resources
511
510
  this.settings.currentCulture = culture;
511
+ this.updateRegionLabel();
512
+ }
513
+ /**
514
+ * Update current region label
515
+ */
516
+ updateRegionLabel() {
517
+ const region = this.settings.currentRegion;
518
+ region.label = this.getRegionLabel(region.id);
512
519
  }
513
520
  /**
514
521
  * Check language is supported or not, return a valid language when supported
@@ -896,6 +903,15 @@ class CoreApp {
896
903
  }
897
904
  return list;
898
905
  }
906
+ /**
907
+ * Get region label
908
+ * @param id Region id
909
+ * @returns Label
910
+ */
911
+ getRegionLabel(id) {
912
+ var _a;
913
+ return (_a = this.get('region' + id)) !== null && _a !== void 0 ? _a : id;
914
+ }
899
915
  /**
900
916
  * Get all regions
901
917
  * @returns Regions
@@ -284,6 +284,12 @@ export interface IApp {
284
284
  * @returns Cached token
285
285
  */
286
286
  getCacheToken(): string | undefined;
287
+ /**
288
+ * Get region label
289
+ * @param id Region id
290
+ * @returns Label
291
+ */
292
+ getRegionLabel(id: string): string;
287
293
  /**
288
294
  * Get all regions
289
295
  * @returns Regions
@@ -1,6 +1,7 @@
1
+ import { AddressContinent } from '../address/AddressContinent';
1
2
  import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
2
3
  import { AddressState } from '../address/AddressState';
3
- import { IdLabelConditional } from '../dto/IdLabelDto';
4
+ import { IdLabelConditional } from './dto/IdLabelDto';
4
5
  import { BaseApi } from './BaseApi';
5
6
  /**
6
7
  * Address Api
@@ -8,23 +9,26 @@ import { BaseApi } from './BaseApi';
8
9
  export declare class AddressApi extends BaseApi {
9
10
  /**
10
11
  * Get all continents
11
- * @param language Language
12
12
  * @param isNumberKey Is number key or key as id
13
13
  * @returns Continents
14
14
  */
15
- continents<T extends boolean>(language?: string, isNumberKey?: T): Promise<IdLabelConditional<T>>;
15
+ continents<T extends boolean>(isNumberKey?: T): Promise<IdLabelConditional<T>>;
16
16
  /**
17
- * Get region list from database
18
- * @param language Language
17
+ * Get continent label
18
+ * @param id Region id
19
+ * @returns Label
20
+ */
21
+ getContinentLabel(id: AddressContinent | string): string;
22
+ /**
23
+ * Get region list
19
24
  * @param isLocal Is local version
20
25
  * @returns Result
21
26
  */
22
- regions<T extends boolean = true>(language?: string, isLocal?: T): Promise<T extends true | undefined ? AddressRegion[] : AddressRegionDb[] | undefined>;
27
+ regions<T extends boolean = true>(isLocal?: T): Promise<T extends true | undefined ? AddressRegion[] : AddressRegionDb[] | undefined>;
23
28
  /**
24
- * Get state list from database
29
+ * Get state list
25
30
  * @param regionId Region id
26
- * @param language Language
27
31
  * @returns Result
28
32
  */
29
- states(regionId: string, language?: string): Promise<AddressState[] | undefined>;
33
+ states(regionId: string): Promise<AddressState[] | undefined>;
30
34
  }
@@ -4,7 +4,6 @@ exports.AddressApi = void 0;
4
4
  const shared_1 = require("@etsoo/shared");
5
5
  const AddressContinent_1 = require("../address/AddressContinent");
6
6
  const AddressRegion_1 = require("../address/AddressRegion");
7
- const AddressUtils_1 = require("../address/AddressUtils");
8
7
  const BaseApi_1 = require("./BaseApi");
9
8
  /**
10
9
  * Address Api
@@ -12,50 +11,49 @@ const BaseApi_1 = require("./BaseApi");
12
11
  class AddressApi extends BaseApi_1.BaseApi {
13
12
  /**
14
13
  * Get all continents
15
- * @param language Language
16
14
  * @param isNumberKey Is number key or key as id
17
15
  * @returns Continents
18
16
  */
19
- async continents(language, isNumberKey = false) {
20
- const labels = await AddressUtils_1.AddressUtils.getLabels(this.app.checkLanguage(language));
21
- return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => {
22
- var _a;
23
- return ({
24
- id: isNumberKey
25
- ? shared_1.DataTypes.getEnumByKey(AddressContinent_1.AddressContinent, key)
26
- : key.toString(),
27
- label: (_a = labels['continent' + key]) !== null && _a !== void 0 ? _a : key
28
- });
29
- });
17
+ async continents(isNumberKey = false) {
18
+ return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => ({
19
+ id: isNumberKey
20
+ ? shared_1.DataTypes.getEnumByKey(AddressContinent_1.AddressContinent, key)
21
+ : key.toString(),
22
+ label: this.getContinentLabel(key)
23
+ }));
24
+ }
25
+ /**
26
+ * Get continent label
27
+ * @param id Region id
28
+ * @returns Label
29
+ */
30
+ getContinentLabel(id) {
31
+ var _a;
32
+ return (_a = this.app.get('continent' + id)) !== null && _a !== void 0 ? _a : id;
30
33
  }
31
34
  /**
32
- * Get region list from database
33
- * @param language Language
35
+ * Get region list
34
36
  * @param isLocal Is local version
35
37
  * @returns Result
36
38
  */
37
- async regions(language, isLocal) {
38
- language = this.app.checkLanguage(language);
39
+ async regions(isLocal) {
39
40
  if (isLocal == null || isLocal) {
40
- const labels = await AddressUtils_1.AddressUtils.getLabels(language);
41
41
  return AddressRegion_1.AddressRegion.all.map((region) => {
42
- region.label = AddressUtils_1.AddressUtils.getRegionLabel(region.id, labels);
42
+ region.label = this.app.getRegionLabel(region.id);
43
43
  return { ...region };
44
44
  });
45
45
  }
46
46
  else {
47
- return (await this.app.api.get(`Address/RegionList?language=${language}`, undefined, { defaultValue: [] }));
47
+ return (await this.api.get(`Address/RegionList?language=${this.app.culture}`, undefined, { defaultValue: [] }));
48
48
  }
49
49
  }
50
50
  /**
51
- * Get state list from database
51
+ * Get state list
52
52
  * @param regionId Region id
53
- * @param language Language
54
53
  * @returns Result
55
54
  */
56
- states(regionId, language) {
57
- language = this.app.checkLanguage(language);
58
- return this.app.api.get(`Address/StateList?regionId=${regionId}&language=${language}`, undefined, { defaultValue: [] });
55
+ states(regionId) {
56
+ return this.api.get(`Address/StateList?regionId=${regionId}&language=${this.app.culture}`, undefined, { defaultValue: [] });
59
57
  }
60
58
  }
61
59
  exports.AddressApi = AddressApi;
@@ -2,11 +2,13 @@ import { IApp } from '../app/IApp';
2
2
  /**
3
3
  * SmartERP base API
4
4
  */
5
- export declare class BaseApi {
6
- protected app: IApp;
5
+ export declare class BaseApi<T extends IApp = IApp> {
6
+ protected app: T;
7
+ protected api: import("@etsoo/restclient").IApi<any>;
7
8
  /**
8
9
  * Constructor
9
10
  * @param app Application
11
+ * @param api API
10
12
  */
11
- constructor(app: IApp);
13
+ constructor(app: T, api?: import("@etsoo/restclient").IApi<any>);
12
14
  }
@@ -8,9 +8,11 @@ class BaseApi {
8
8
  /**
9
9
  * Constructor
10
10
  * @param app Application
11
+ * @param api API
11
12
  */
12
- constructor(app) {
13
+ constructor(app, api = app.api) {
13
14
  this.app = app;
15
+ this.api = api;
14
16
  }
15
17
  }
16
18
  exports.BaseApi = BaseApi;
@@ -0,0 +1,78 @@
1
+ import { IApi, IApiPayload } from '@etsoo/restclient';
2
+ import { DataTypes } from '@etsoo/shared';
3
+ import { IApp } from '../app/IApp';
4
+ import { IActionResult } from '../result/IActionResult';
5
+ import { BaseApi } from './BaseApi';
6
+ import { QueryRQ } from './rq/QueryRQ';
7
+ import { TiplistRQ } from './rq/TiplistRQ';
8
+ /**
9
+ * Entity API
10
+ * Follow com.etsoo.CoreFramework.Services.EntityServiceBase
11
+ */
12
+ export declare class EntityApi<T extends IApp = IApp> extends BaseApi<T> {
13
+ protected flag: string;
14
+ /**
15
+ * Constructor
16
+ * @param flag Identity flag, like 'Product' for product APIs
17
+ * @param app Application
18
+ */
19
+ constructor(flag: string, app: T, api?: IApi);
20
+ /**
21
+ * Create
22
+ * @param data Modal data
23
+ * @param payload Payload
24
+ * @returns Result
25
+ */
26
+ protected createBase<R extends IActionResult>(data: object, payload?: IApiPayload<R, any>): Promise<R | undefined>;
27
+ /**
28
+ * Delete
29
+ * @param id Id or ids
30
+ * @param payload Payload
31
+ */
32
+ protected deleteBase<R extends IActionResult>(id: DataTypes.IdType, payload?: IApiPayload<R, any>): R;
33
+ protected deleteBase<R extends IActionResult>(ids: DataTypes.IdType[], payload?: IApiPayload<R, any>): R;
34
+ /**
35
+ * List
36
+ * @param rq Request data
37
+ * @param payload Payload
38
+ * @returns Result
39
+ */
40
+ protected listBase<RQ extends TiplistRQ, R extends object>(rq: RQ, payload?: IApiPayload<R[], any>): Promise<R[] | undefined>;
41
+ /**
42
+ * Query
43
+ * @param rq Request data
44
+ * @param payload Payload
45
+ * @returns Result
46
+ */
47
+ protected queryBase<RQ extends QueryRQ, R extends object>(rq: RQ, payload?: IApiPayload<R[], any>): Promise<R[] | undefined>;
48
+ /**
49
+ * Read
50
+ * @param id Id
51
+ * @param payload Payload
52
+ * @returns Result
53
+ */
54
+ protected readBase<R extends object>(id: DataTypes.IdType, payload?: IApiPayload<R, any>): Promise<R | undefined>;
55
+ /**
56
+ * Sort
57
+ * @param items Items to sort
58
+ * @param payload Payload
59
+ * @returns Result
60
+ */
61
+ protected sortBase<RQ extends {
62
+ id: DataTypes.IdType;
63
+ }>(items: RQ[], payload?: IApiPayload<number, any>): Promise<number | undefined>;
64
+ /**
65
+ * Update
66
+ * @param data Modal data
67
+ * @param payload Payload
68
+ * @returns Result
69
+ */
70
+ protected updateBase<R extends IActionResult>(data: object, payload?: IApiPayload<R, any>): Promise<R | undefined>;
71
+ /**
72
+ * Read for update
73
+ * @param id Id
74
+ * @param payload Payload
75
+ * @returns Result
76
+ */
77
+ protected updateReadBase<R extends object>(id: DataTypes.IdType, payload?: IApiPayload<R, any>): Promise<R | undefined>;
78
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityApi = void 0;
4
+ const BaseApi_1 = require("./BaseApi");
5
+ /**
6
+ * Entity API
7
+ * Follow com.etsoo.CoreFramework.Services.EntityServiceBase
8
+ */
9
+ class EntityApi extends BaseApi_1.BaseApi {
10
+ /**
11
+ * Constructor
12
+ * @param flag Identity flag, like 'Product' for product APIs
13
+ * @param app Application
14
+ */
15
+ constructor(flag, app, api) {
16
+ super(app, api);
17
+ this.flag = flag;
18
+ }
19
+ /**
20
+ * Create
21
+ * @param data Modal data
22
+ * @param payload Payload
23
+ * @returns Result
24
+ */
25
+ createBase(data, payload) {
26
+ return this.api.put(`${this.flag}/Create`, data, payload);
27
+ }
28
+ deleteBase(id, payload) {
29
+ const query = Array.isArray(id)
30
+ ? '?' + id.map((item) => `ids=${item}`).join('&')
31
+ : id;
32
+ return this.api.delete(`${this.flag}/Delete/${query}`, undefined, payload);
33
+ }
34
+ /**
35
+ * List
36
+ * @param rq Request data
37
+ * @param payload Payload
38
+ * @returns Result
39
+ */
40
+ listBase(rq, payload) {
41
+ return this.api.post(`${this.flag}/List`, rq, payload);
42
+ }
43
+ /**
44
+ * Query
45
+ * @param rq Request data
46
+ * @param payload Payload
47
+ * @returns Result
48
+ */
49
+ queryBase(rq, payload) {
50
+ return this.api.post(`${this.flag}/Query`, rq, payload);
51
+ }
52
+ /**
53
+ * Read
54
+ * @param id Id
55
+ * @param payload Payload
56
+ * @returns Result
57
+ */
58
+ readBase(id, payload) {
59
+ return this.api.get(`${this.flag}/Read/${id}`, payload);
60
+ }
61
+ /**
62
+ * Sort
63
+ * @param items Items to sort
64
+ * @param payload Payload
65
+ * @returns Result
66
+ */
67
+ sortBase(items, payload) {
68
+ const rq = {};
69
+ items.forEach((item, index) => (rq[item.id] = index));
70
+ return this.api.put(`${this.flag}/Sort`, rq, payload);
71
+ }
72
+ /**
73
+ * Update
74
+ * @param data Modal data
75
+ * @param payload Payload
76
+ * @returns Result
77
+ */
78
+ updateBase(data, payload) {
79
+ return this.api.put(`${this.flag}/Update`, data, payload);
80
+ }
81
+ /**
82
+ * Read for update
83
+ * @param id Id
84
+ * @param payload Payload
85
+ * @returns Result
86
+ */
87
+ updateReadBase(id, payload) {
88
+ return this.api.get(`${this.flag}/UpdateRead/${id}`, payload);
89
+ }
90
+ }
91
+ exports.EntityApi = EntityApi;