@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
@@ -15,6 +15,13 @@
15
15
  "confirm": "Confirm",
16
16
  "confirmAction": "Are you sure you want to {0}?",
17
17
  "completeTip": "{0} completed",
18
+ "continentAF": "Africa",
19
+ "continentAN": "Antarctica",
20
+ "continentAS": "Asia",
21
+ "continentEU": "Europe",
22
+ "continentNA": "North America",
23
+ "continentOC": "Oceania",
24
+ "continentSA": "South America",
18
25
  "copy": "Copy",
19
26
  "creation": "Creation",
20
27
  "currentPassword": "Current password",
@@ -106,6 +113,19 @@
106
113
  "refresh": "Refresh",
107
114
  "refreshing": "Refreshing",
108
115
  "releaseToRefresh": "Release to refresh",
116
+ "region": "Country or region",
117
+ "regionAU": "Australia",
118
+ "regionCA": "Canada",
119
+ "regionCN": "Mainland China",
120
+ "regionDE": "Germany",
121
+ "regionFR": "France",
122
+ "regionGB": "United Kingdom",
123
+ "regionHK": "Hong Kong, China",
124
+ "regionIE": "Ireland",
125
+ "regionJP": "Japan",
126
+ "regionNZ": "New Zealand",
127
+ "regionSG": "Singapore",
128
+ "regionUS": "United States",
109
129
  "reloginTip": "Please enter your password, resubmit the data after successful login",
110
130
  "remove": "Remove",
111
131
  "renew": "Renew",
@@ -15,6 +15,13 @@
15
15
  "confirm": "确认",
16
16
  "confirmAction": "确定要{0}吗?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南极洲",
20
+ "continentAS": "亚洲",
21
+ "continentEU": "欧洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "复制",
19
26
  "creation": "登记时间",
20
27
  "currentPassword": "当前密码",
@@ -105,6 +112,19 @@
105
112
  "record": "记录",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "region": "国家或地区",
116
+ "regionAU": "澳大利亚",
117
+ "regionCA": "加拿大",
118
+ "regionCN": "中国大陆",
119
+ "regionDE": "德国",
120
+ "regionFR": "法国",
121
+ "regionGB": "英国",
122
+ "regionHK": "中国香港",
123
+ "regionIE": "爱尔兰",
124
+ "regionJP": "日本",
125
+ "regionNZ": "新西兰",
126
+ "regionSG": "新加坡",
127
+ "regionUS": "美国",
108
128
  "releaseToRefresh": "释放刷新",
109
129
  "reloginTip": "请输入您的登录密码,登录成功后请重新提交数据",
110
130
  "remove": "移除",
@@ -15,6 +15,13 @@
15
15
  "confirm": "確認",
16
16
  "confirmAction": "確定要{0}嗎?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南極洲",
20
+ "continentAS": "亞洲",
21
+ "continentEU": "歐洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "複製",
19
26
  "creation": "登記時間",
20
27
  "currentPassword": "當前密碼",
@@ -105,6 +112,19 @@
105
112
  "record": "記錄",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "region": "國家或地區",
116
+ "regionAU": "澳大利亞",
117
+ "regionCA": "加拿大",
118
+ "regionCN": "中國大陸",
119
+ "regionDE": "德國",
120
+ "regionFR": "法國",
121
+ "regionGB": "英國",
122
+ "regionHK": "中國香港",
123
+ "regionIE": "愛爾蘭",
124
+ "regionJP": "日本",
125
+ "regionNZ": "新西蘭",
126
+ "regionSG": "新加坡",
127
+ "regionUS": "美國",
108
128
  "releaseToRefresh": "釋放刷新",
109
129
  "reloginTip": "請輸入您的登錄密碼,登錄成功後請重新提交數據",
110
130
  "remove": "移除",
@@ -16,15 +16,19 @@ export * from './business/EntityStatus';
16
16
  export * from './business/ProductUnit';
17
17
  export * from './business/RepeatOption';
18
18
  export * from './def/ListItem';
19
- export * from './dto/IdLabelDto';
20
- export * from './dto/IdLabelPrimaryDto';
21
- export * from './dto/InitCallDto';
22
19
  export * from './erp/dto/CurrencyDto';
23
20
  export * from './erp/dto/ExchangeRateDto';
24
21
  export * from './erp/dto/ExchangeRateHistoryDto';
22
+ export * from './erp/dto/IdLabelDto';
23
+ export * from './erp/dto/IdLabelPrimaryDto';
24
+ export * from './erp/dto/InitCallDto';
25
25
  export * from './erp/dto/PublicProductDto';
26
+ export * from './erp/rq/QueryRQ';
27
+ export * from './erp/rq/RefreshTokenRQ';
28
+ export * from './erp/rq/TiplistRQ';
26
29
  export * from './erp/AddressApi';
27
30
  export * from './erp/BaseApi';
31
+ export * from './erp/EntityApi';
28
32
  export * from './erp/OrgApi';
29
33
  export * from './erp/PublicApi';
30
34
  export * from './i18n/enUS';
@@ -36,10 +40,6 @@ export * from './result/ActionResult';
36
40
  export * from './result/ActionResultError';
37
41
  export * from './result/IActionResult';
38
42
  export * from './result/InitCallResult';
39
- export * from './rq/LoginIdRQ';
40
- export * from './rq/LoginRQ';
41
- export * from './rq/QueryRQ';
42
- export * from './rq/TiplistRQ';
43
43
  export * from './state/Culture';
44
44
  export * from './state/State';
45
45
  export * from './state/User';
package/lib/mjs/index.js CHANGED
@@ -21,17 +21,22 @@ export * from './business/ProductUnit';
21
21
  export * from './business/RepeatOption';
22
22
  // def
23
23
  export * from './def/ListItem';
24
- // dto
25
- export * from './dto/IdLabelDto';
26
- export * from './dto/IdLabelPrimaryDto';
27
- export * from './dto/InitCallDto';
28
- // erp
24
+ // erp dto
29
25
  export * from './erp/dto/CurrencyDto';
30
26
  export * from './erp/dto/ExchangeRateDto';
31
27
  export * from './erp/dto/ExchangeRateHistoryDto';
28
+ export * from './erp/dto/IdLabelDto';
29
+ export * from './erp/dto/IdLabelPrimaryDto';
30
+ export * from './erp/dto/InitCallDto';
32
31
  export * from './erp/dto/PublicProductDto';
32
+ // erp rq
33
+ export * from './erp/rq/QueryRQ';
34
+ export * from './erp/rq/RefreshTokenRQ';
35
+ export * from './erp/rq/TiplistRQ';
36
+ // erp api
33
37
  export * from './erp/AddressApi';
34
38
  export * from './erp/BaseApi';
39
+ export * from './erp/EntityApi';
35
40
  export * from './erp/OrgApi';
36
41
  export * from './erp/PublicApi';
37
42
  // i18n
@@ -45,11 +50,6 @@ export * from './result/ActionResult';
45
50
  export * from './result/ActionResultError';
46
51
  export * from './result/IActionResult';
47
52
  export * from './result/InitCallResult';
48
- // rq
49
- export * from './rq/LoginIdRQ';
50
- export * from './rq/LoginRQ';
51
- export * from './rq/QueryRQ';
52
- export * from './rq/TiplistRQ';
53
53
  // state
54
54
  export * from './state/Culture';
55
55
  export * from './state/State';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.12",
56
56
  "@etsoo/restclient": "^1.0.74",
57
- "@etsoo/shared": "^1.1.60",
57
+ "@etsoo/shared": "^1.1.62",
58
58
  "@types/crypto-js": "^4.1.1",
59
59
  "crypto-js": "^4.1.1"
60
60
  },
@@ -70,8 +70,8 @@
70
70
  "eslint": "^8.25.0",
71
71
  "eslint-config-airbnb-base": "^15.0.0",
72
72
  "eslint-plugin-import": "^2.26.0",
73
- "jest": "^29.1.2",
74
- "jest-environment-jsdom": "^29.1.2",
73
+ "jest": "^29.2.0",
74
+ "jest-environment-jsdom": "^29.2.0",
75
75
  "ts-jest": "^29.0.3",
76
76
  "typescript": "^4.8.4"
77
77
  }
@@ -1,28 +1,9 @@
1
- import { DataTypes } from '@etsoo/shared';
2
1
  import { AddressRegion } from './AddressRegion';
3
2
 
4
- const languageLabels: Record<string, DataTypes.StringRecord | undefined> = {};
5
-
6
3
  /**
7
4
  * Address utils
8
5
  */
9
6
  export namespace AddressUtils {
10
- /**
11
- * Get address labels
12
- * @param language Language
13
- * @returns Result
14
- */
15
- export async function getLabels(language: string) {
16
- let labels = languageLabels[language];
17
- if (labels == null) {
18
- labels = await import(`./../i18n/address.${language}.json`);
19
-
20
- // Cache
21
- languageLabels[language] = labels;
22
- }
23
- return labels!;
24
- }
25
-
26
7
  /**
27
8
  * Get region from regions and detected region and language
28
9
  * @param regions Supported regions
@@ -51,30 +32,4 @@ export namespace AddressUtils {
51
32
  // Default
52
33
  return AddressRegion.getById(regions[0])!;
53
34
  }
54
-
55
- /**
56
- * Get region label
57
- * @param id Region id
58
- * @param labels Labels
59
- * @returns Label
60
- */
61
- export function getRegionLabel(
62
- id: string,
63
- labels: DataTypes.StringRecord
64
- ): string {
65
- return (labels['region' + id] as string) ?? id;
66
- }
67
-
68
- /**
69
- * Update region label
70
- * @param region Region
71
- * @param culture Culture
72
- */
73
- export async function updateRegionLabel(
74
- region: AddressRegion,
75
- culture: string
76
- ) {
77
- const labels = await AddressUtils.getLabels(culture);
78
- region.label = getRegionLabel(region.id, labels);
79
- }
80
35
  }
@@ -33,7 +33,7 @@ import { AddressRegion } from '../address/AddressRegion';
33
33
  import { AddressUtils } from '../address/AddressUtils';
34
34
  import { BridgeUtils } from '../bridges/BridgeUtils';
35
35
  import { EntityStatus } from '../business/EntityStatus';
36
- import { InitCallDto } from '../dto/InitCallDto';
36
+ import { InitCallDto } from '../erp/dto/InitCallDto';
37
37
  import { ActionResultError } from '../result/ActionResultError';
38
38
  import { IActionResult } from '../result/IActionResult';
39
39
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
@@ -718,8 +718,8 @@ export abstract class CoreApp<
718
718
  this._region = regionId;
719
719
 
720
720
  // Hold the current country or region
721
- AddressUtils.updateRegionLabel(regionItem, this._culture);
722
721
  this.settings.currentRegion = regionItem;
722
+ this.updateRegionLabel();
723
723
  }
724
724
 
725
725
  /**
@@ -745,6 +745,16 @@ export abstract class CoreApp<
745
745
 
746
746
  // Hold the current resources
747
747
  this.settings.currentCulture = culture;
748
+
749
+ this.updateRegionLabel();
750
+ }
751
+
752
+ /**
753
+ * Update current region label
754
+ */
755
+ protected updateRegionLabel() {
756
+ const region = this.settings.currentRegion;
757
+ region.label = this.getRegionLabel(region.id);
748
758
  }
749
759
 
750
760
  /**
@@ -1219,6 +1229,15 @@ export abstract class CoreApp<
1219
1229
  return list;
1220
1230
  }
1221
1231
 
1232
+ /**
1233
+ * Get region label
1234
+ * @param id Region id
1235
+ * @returns Label
1236
+ */
1237
+ getRegionLabel(id: string) {
1238
+ return this.get('region' + id) ?? id;
1239
+ }
1240
+
1222
1241
  /**
1223
1242
  * Get all regions
1224
1243
  * @returns Regions
package/src/app/IApp.ts CHANGED
@@ -375,6 +375,13 @@ export interface IApp {
375
375
  */
376
376
  getCacheToken(): string | undefined;
377
377
 
378
+ /**
379
+ * Get region label
380
+ * @param id Region id
381
+ * @returns Label
382
+ */
383
+ getRegionLabel(id: string): string;
384
+
378
385
  /**
379
386
  * Get all regions
380
387
  * @returns Regions
@@ -2,8 +2,7 @@ import { DataTypes } from '@etsoo/shared';
2
2
  import { AddressContinent } from '../address/AddressContinent';
3
3
  import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
4
4
  import { AddressState } from '../address/AddressState';
5
- import { AddressUtils } from '../address/AddressUtils';
6
- import { IdLabelConditional } from '../dto/IdLabelDto';
5
+ import { IdLabelConditional } from './dto/IdLabelDto';
7
6
  import { BaseApi } from './BaseApi';
8
7
 
9
8
  /**
@@ -12,51 +11,51 @@ import { BaseApi } from './BaseApi';
12
11
  export class AddressApi extends 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
17
  async continents<T extends boolean>(
20
- language?: string,
21
18
  isNumberKey = <T>false
22
19
  ): Promise<IdLabelConditional<T>> {
23
- const labels = await AddressUtils.getLabels(
24
- this.app.checkLanguage(language)
25
- );
26
20
  return <IdLabelConditional<T>>DataTypes.getEnumKeys(
27
21
  AddressContinent
28
22
  ).map((key) => ({
29
23
  id: isNumberKey
30
24
  ? <number>DataTypes.getEnumByKey(AddressContinent, key)!
31
25
  : key.toString(),
32
- label: labels['continent' + key] ?? key
26
+ label: this.getContinentLabel(key)
33
27
  }));
34
28
  }
35
29
 
36
30
  /**
37
- * Get region list from database
38
- * @param language Language
31
+ * Get continent label
32
+ * @param id Region id
33
+ * @returns Label
34
+ */
35
+ getContinentLabel(id: AddressContinent | string) {
36
+ return this.app.get('continent' + id) ?? (id as string);
37
+ }
38
+
39
+ /**
40
+ * Get region list
39
41
  * @param isLocal Is local version
40
42
  * @returns Result
41
43
  */
42
44
  async regions<T extends boolean = true>(
43
- language?: string,
44
45
  isLocal?: T
45
46
  ): Promise<
46
47
  T extends true | undefined
47
48
  ? AddressRegion[]
48
49
  : AddressRegionDb[] | undefined
49
50
  > {
50
- language = this.app.checkLanguage(language);
51
51
  if (isLocal == null || isLocal) {
52
- const labels = await AddressUtils.getLabels(language);
53
52
  return AddressRegion.all.map((region) => {
54
- region.label = AddressUtils.getRegionLabel(region.id, labels);
53
+ region.label = this.app.getRegionLabel(region.id);
55
54
  return { ...region };
56
55
  });
57
56
  } else {
58
- return (await this.app.api.get<AddressRegionDb[]>(
59
- `Address/RegionList?language=${language}`,
57
+ return (await this.api.get<AddressRegionDb[]>(
58
+ `Address/RegionList?language=${this.app.culture}`,
60
59
  undefined,
61
60
  { defaultValue: [] }
62
61
  )) as any;
@@ -64,15 +63,13 @@ export class AddressApi extends BaseApi {
64
63
  }
65
64
 
66
65
  /**
67
- * Get state list from database
66
+ * Get state list
68
67
  * @param regionId Region id
69
- * @param language Language
70
68
  * @returns Result
71
69
  */
72
- states(regionId: string, language?: string) {
73
- language = this.app.checkLanguage(language);
74
- return this.app.api.get<AddressState[]>(
75
- `Address/StateList?regionId=${regionId}&language=${language}`,
70
+ states(regionId: string) {
71
+ return this.api.get<AddressState[]>(
72
+ `Address/StateList?regionId=${regionId}&language=${this.app.culture}`,
76
73
  undefined,
77
74
  { defaultValue: [] }
78
75
  );
@@ -3,10 +3,11 @@ import { IApp } from '../app/IApp';
3
3
  /**
4
4
  * SmartERP base API
5
5
  */
6
- export class BaseApi {
6
+ export class BaseApi<T extends IApp = IApp> {
7
7
  /**
8
8
  * Constructor
9
9
  * @param app Application
10
+ * @param api API
10
11
  */
11
- constructor(protected app: IApp) {}
12
+ constructor(protected app: T, protected api = app.api) {}
12
13
  }
@@ -0,0 +1,142 @@
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
+ /**
10
+ * Entity API
11
+ * Follow com.etsoo.CoreFramework.Services.EntityServiceBase
12
+ */
13
+ export class EntityApi<T extends IApp = IApp> extends BaseApi<T> {
14
+ /**
15
+ * Constructor
16
+ * @param flag Identity flag, like 'Product' for product APIs
17
+ * @param app Application
18
+ */
19
+ constructor(protected flag: string, app: T, api?: IApi) {
20
+ super(app, api);
21
+ }
22
+
23
+ /**
24
+ * Create
25
+ * @param data Modal data
26
+ * @param payload Payload
27
+ * @returns Result
28
+ */
29
+ protected createBase<R extends IActionResult>(
30
+ data: object,
31
+ payload?: IApiPayload<R, any>
32
+ ) {
33
+ return this.api.put<R>(`${this.flag}/Create`, data, payload);
34
+ }
35
+
36
+ /**
37
+ * Delete
38
+ * @param id Id or ids
39
+ * @param payload Payload
40
+ */
41
+ protected deleteBase<R extends IActionResult>(
42
+ id: DataTypes.IdType,
43
+ payload?: IApiPayload<R, any>
44
+ ): R;
45
+ protected deleteBase<R extends IActionResult>(
46
+ ids: DataTypes.IdType[],
47
+ payload?: IApiPayload<R, any>
48
+ ): R;
49
+ protected deleteBase<R extends IActionResult>(
50
+ id: DataTypes.IdType | DataTypes.IdType[],
51
+ payload?: IApiPayload<R, any>
52
+ ) {
53
+ const query = Array.isArray(id)
54
+ ? '?' + id.map((item) => `ids=${item}`).join('&')
55
+ : id;
56
+ return this.api.delete<R>(
57
+ `${this.flag}/Delete/${query}`,
58
+ undefined,
59
+ payload
60
+ );
61
+ }
62
+
63
+ /**
64
+ * List
65
+ * @param rq Request data
66
+ * @param payload Payload
67
+ * @returns Result
68
+ */
69
+ protected listBase<RQ extends TiplistRQ, R extends object>(
70
+ rq: RQ,
71
+ payload?: IApiPayload<R[], any>
72
+ ) {
73
+ return this.api.post<R[]>(`${this.flag}/List`, rq, payload);
74
+ }
75
+
76
+ /**
77
+ * Query
78
+ * @param rq Request data
79
+ * @param payload Payload
80
+ * @returns Result
81
+ */
82
+ protected queryBase<RQ extends QueryRQ, R extends object>(
83
+ rq: RQ,
84
+ payload?: IApiPayload<R[], any>
85
+ ) {
86
+ return this.api.post<R[]>(`${this.flag}/Query`, rq, payload);
87
+ }
88
+
89
+ /**
90
+ * Read
91
+ * @param id Id
92
+ * @param payload Payload
93
+ * @returns Result
94
+ */
95
+ protected readBase<R extends object>(
96
+ id: DataTypes.IdType,
97
+ payload?: IApiPayload<R, any>
98
+ ) {
99
+ return this.api.get<R>(`${this.flag}/Read/${id}`, payload);
100
+ }
101
+
102
+ /**
103
+ * Sort
104
+ * @param items Items to sort
105
+ * @param payload Payload
106
+ * @returns Result
107
+ */
108
+ protected sortBase<RQ extends { id: DataTypes.IdType }>(
109
+ items: RQ[],
110
+ payload?: IApiPayload<number, any>
111
+ ) {
112
+ const rq: Record<DataTypes.IdType, number> = {};
113
+ items.forEach((item, index) => (rq[item.id] = index));
114
+ return this.api.put<number>(`${this.flag}/Sort`, rq, payload);
115
+ }
116
+
117
+ /**
118
+ * Update
119
+ * @param data Modal data
120
+ * @param payload Payload
121
+ * @returns Result
122
+ */
123
+ protected updateBase<R extends IActionResult>(
124
+ data: object,
125
+ payload?: IApiPayload<R, any>
126
+ ) {
127
+ return this.api.put<R>(`${this.flag}/Update`, data, payload);
128
+ }
129
+
130
+ /**
131
+ * Read for update
132
+ * @param id Id
133
+ * @param payload Payload
134
+ * @returns Result
135
+ */
136
+ protected updateReadBase<R extends object>(
137
+ id: DataTypes.IdType,
138
+ payload?: IApiPayload<R, any>
139
+ ) {
140
+ return this.api.get<R>(`${this.flag}/UpdateRead/${id}`, payload);
141
+ }
142
+ }