storemw-core-client 1.0.1

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/.env +1 -0
  2. package/.vscode/launch.json +24 -0
  3. package/dist/config/config.d.ts +6 -0
  4. package/dist/config/config.js +13 -0
  5. package/dist/config/env.d.ts +7 -0
  6. package/dist/config/env.js +16 -0
  7. package/dist/config/index.d.ts +2 -0
  8. package/dist/config/index.js +8 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +32 -0
  11. package/dist/lib/ApiService.d.ts +41 -0
  12. package/dist/lib/ApiService.js +143 -0
  13. package/dist/lib/index.d.ts +4 -0
  14. package/dist/lib/index.js +9 -0
  15. package/dist/lib/queryParams.d.ts +43 -0
  16. package/dist/lib/queryParams.js +99 -0
  17. package/dist/services/account/AccountService.d.ts +52 -0
  18. package/dist/services/account/AccountService.js +119 -0
  19. package/dist/services/auth/AuthService.d.ts +44 -0
  20. package/dist/services/auth/AuthService.js +76 -0
  21. package/dist/services/branch/BranchService.d.ts +124 -0
  22. package/dist/services/branch/BranchService.js +162 -0
  23. package/dist/services/business/BusinessService.d.ts +91 -0
  24. package/dist/services/business/BusinessService.js +153 -0
  25. package/dist/services/document/DocumentService.d.ts +578 -0
  26. package/dist/services/document/DocumentService.js +615 -0
  27. package/dist/services/index.d.ts +36 -0
  28. package/dist/services/index.js +97 -0
  29. package/dist/services/injection_field/InjectionFieldService.d.ts +113 -0
  30. package/dist/services/injection_field/InjectionFieldService.js +220 -0
  31. package/dist/services/inventory/InventoryService.d.ts +27 -0
  32. package/dist/services/inventory/InventoryService.js +231 -0
  33. package/dist/services/item/ItemService.d.ts +227 -0
  34. package/dist/services/item/ItemService.js +411 -0
  35. package/dist/services/location/LocationService.d.ts +154 -0
  36. package/dist/services/location/LocationService.js +256 -0
  37. package/dist/services/logistic/LogisticService.d.ts +104 -0
  38. package/dist/services/logistic/LogisticService.js +150 -0
  39. package/dist/services/permission/PermissionService.d.ts +296 -0
  40. package/dist/services/permission/PermissionService.js +576 -0
  41. package/dist/services/permission/config/custom/adminPermission.d.ts +4 -0
  42. package/dist/services/permission/config/custom/adminPermission.js +18 -0
  43. package/dist/services/permission/config/custom/config.d.ts +40 -0
  44. package/dist/services/permission/config/custom/config.js +23 -0
  45. package/dist/services/permission/config/default/adminPermission.d.ts +2 -0
  46. package/dist/services/permission/config/default/adminPermission.js +129 -0
  47. package/dist/services/permission/config/default/agentPermission.d.ts +2 -0
  48. package/dist/services/permission/config/default/agentPermission.js +43 -0
  49. package/dist/services/permission/config/default/customerPermission.d.ts +2 -0
  50. package/dist/services/permission/config/default/customerPermission.js +10 -0
  51. package/dist/services/permission/config/default/driverPermission.d.ts +2 -0
  52. package/dist/services/permission/config/default/driverPermission.js +4 -0
  53. package/dist/services/permission/config/default/workerPermission.d.ts +2 -0
  54. package/dist/services/permission/config/default/workerPermission.js +25 -0
  55. package/dist/services/rate/RateService.d.ts +201 -0
  56. package/dist/services/rate/RateService.js +303 -0
  57. package/dist/services/region/RegionService.d.ts +111 -0
  58. package/dist/services/region/RegionService.js +193 -0
  59. package/dist/services/repository/RepositoryService.d.ts +153 -0
  60. package/dist/services/repository/RepositoryService.js +243 -0
  61. package/dist/services/transaction/TransactionService.d.ts +153 -0
  62. package/dist/services/transaction/TransactionService.js +173 -0
  63. package/dist/services/user/BranchUserService.d.ts +129 -0
  64. package/dist/services/user/BranchUserService.js +193 -0
  65. package/dist/services/user/UserRoleService.d.ts +105 -0
  66. package/dist/services/user/UserRoleService.js +193 -0
  67. package/dist/services/user/UserService.d.ts +269 -0
  68. package/dist/services/user/UserService.js +477 -0
  69. package/dist/services/wallet/WalletService.d.ts +104 -0
  70. package/dist/services/wallet/WalletService.js +163 -0
  71. package/dist/utils/dateUtils.d.ts +6 -0
  72. package/dist/utils/dateUtils.js +28 -0
  73. package/dist/utils/index.d.ts +2 -0
  74. package/dist/utils/index.js +13 -0
  75. package/package.json +27 -0
  76. package/src/config/config.ts +15 -0
  77. package/src/config/env.ts +18 -0
  78. package/src/config/index.ts +2 -0
  79. package/src/index.ts +41 -0
  80. package/src/lib/ApiService.ts +170 -0
  81. package/src/lib/index.ts +5 -0
  82. package/src/lib/queryParams.ts +162 -0
  83. package/src/services/account/AccountService.ts +232 -0
  84. package/src/services/auth/AuthService.ts +125 -0
  85. package/src/services/branch/BranchService.ts +330 -0
  86. package/src/services/business/BusinessService.ts +277 -0
  87. package/src/services/document/DocumentService.ts +1471 -0
  88. package/src/services/index.ts +73 -0
  89. package/src/services/injection_field/InjectionFieldService.ts +483 -0
  90. package/src/services/inventory/InventoryService.ts +314 -0
  91. package/src/services/item/ItemService.ts +707 -0
  92. package/src/services/location/LocationService.ts +505 -0
  93. package/src/services/logistic/LogisticService.ts +285 -0
  94. package/src/services/permission/PermissionService.ts +1069 -0
  95. package/src/services/permission/config/custom/adminPermission.ts +19 -0
  96. package/src/services/permission/config/custom/config.ts +39 -0
  97. package/src/services/permission/config/default/adminPermission.ts +129 -0
  98. package/src/services/permission/config/default/agentPermission.ts +42 -0
  99. package/src/services/permission/config/default/customerPermission.ts +9 -0
  100. package/src/services/permission/config/default/driverPermission.ts +4 -0
  101. package/src/services/permission/config/default/workerPermission.ts +25 -0
  102. package/src/services/rate/RateService.ts +570 -0
  103. package/src/services/region/RegionService.ts +353 -0
  104. package/src/services/repository/RepositoryService.ts +437 -0
  105. package/src/services/transaction/TransactionService.ts +404 -0
  106. package/src/services/user/BranchUserService.ts +381 -0
  107. package/src/services/user/UserRoleService.ts +342 -0
  108. package/src/services/user/UserService.ts +807 -0
  109. package/src/services/wallet/WalletService.ts +300 -0
  110. package/src/utils/dateUtils.ts +26 -0
  111. package/src/utils/index.ts +2 -0
  112. package/tsconfig.json +119 -0
@@ -0,0 +1,44 @@
1
+ import { ApiServiceType } from '@/lib';
2
+ export declare const routeTypes: {
3
+ readonly admin: "admin";
4
+ readonly retail: "retail";
5
+ readonly workstation: "workstation";
6
+ readonly customer: "customer";
7
+ readonly member: "member";
8
+ readonly public: "public";
9
+ readonly driver: "driver";
10
+ readonly console: "console";
11
+ };
12
+ export declare const authTargetTypes: {
13
+ readonly admin: "administrator";
14
+ readonly retailer: "retail";
15
+ readonly workstation: "workstation";
16
+ readonly customer: "customer";
17
+ readonly member: "member";
18
+ readonly public: "public";
19
+ readonly driver: "driver";
20
+ readonly console: "console";
21
+ };
22
+ export type AuthTargetType = typeof authTargetTypes[keyof typeof authTargetTypes];
23
+ export type AuthServiceProps = ApiServiceType & {
24
+ authTargetType: AuthTargetType;
25
+ };
26
+ export type AuthLoginProps = {
27
+ authTargetType?: AuthTargetType;
28
+ username: string;
29
+ password: string;
30
+ };
31
+ type confirmPasswordProps = {
32
+ current: string;
33
+ password: string;
34
+ confirm: string;
35
+ };
36
+ export declare const AuthService: (props?: AuthServiceProps) => {
37
+ authLogin: (props: AuthLoginProps) => Promise<{
38
+ status: boolean;
39
+ message: string;
40
+ data?: any;
41
+ }>;
42
+ changePassword: ({ current, password, confirm }: confirmPasswordProps) => Promise<void>;
43
+ };
44
+ export {};
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthService = exports.authTargetTypes = exports.routeTypes = void 0;
4
+ const lib_1 = require("@/lib");
5
+ exports.routeTypes = {
6
+ admin: "admin",
7
+ retail: "retail", // retail
8
+ workstation: "workstation",
9
+ customer: "customer",
10
+ member: "member",
11
+ public: "public",
12
+ driver: "driver",
13
+ console: "console"
14
+ };
15
+ exports.authTargetTypes = {
16
+ admin: "administrator",
17
+ // retail: "retailer",
18
+ retailer: "retail",
19
+ workstation: "workstation", // worker
20
+ customer: "customer",
21
+ member: "member",
22
+ public: "public",
23
+ driver: "driver",
24
+ console: "console"
25
+ };
26
+ const AuthService = (props) => {
27
+ const { authTargetType, customToken } = props ?? {};
28
+ const { makeCall } = (0, lib_1.ApiService)(customToken ? { customToken } : {});
29
+ const endpoint1 = "auth/";
30
+ const authLogin = async (props) => {
31
+ const { authTargetType: overrideAuthTargetType, username, password } = props;
32
+ const url = `${endpoint1}token`;
33
+ const postData = {
34
+ scope: {
35
+ target: overrideAuthTargetType || authTargetType,
36
+ action: "",
37
+ },
38
+ payload: {
39
+ account_id: "1",
40
+ username,
41
+ password
42
+ }
43
+ };
44
+ const response = await makeCall({
45
+ url,
46
+ method: "post",
47
+ payload: postData
48
+ });
49
+ return response;
50
+ };
51
+ const changePassword = async ({ current, password, confirm }) => {
52
+ const url = `${endpoint1}`;
53
+ const postData = {
54
+ scope: {
55
+ target: "change_password"
56
+ },
57
+ payload: {
58
+ auth: {
59
+ current_password: current,
60
+ new_password: password,
61
+ confirm_password: confirm
62
+ }
63
+ }
64
+ };
65
+ const response = await makeCall({
66
+ url,
67
+ method: 'put',
68
+ payload: postData
69
+ });
70
+ };
71
+ return {
72
+ authLogin,
73
+ changePassword
74
+ };
75
+ };
76
+ exports.AuthService = AuthService;
@@ -0,0 +1,124 @@
1
+ import { ApiServiceType } from '@/lib';
2
+ import { BuildApiListParamsProps, BuildApiGetParamsProps } from '@/lib';
3
+ export declare const branchTypes: {
4
+ readonly customer: "customer";
5
+ readonly retailer: "retailer";
6
+ };
7
+ export declare const branchTargetTypes: {
8
+ readonly customer: "customer";
9
+ readonly retailer: "retailer";
10
+ };
11
+ export type BranchType = typeof branchTypes[keyof typeof branchTypes];
12
+ export type BranchTargetType = typeof branchTargetTypes[keyof typeof branchTargetTypes];
13
+ export type BranchTargetKey = keyof typeof branchTargetTypes;
14
+ export type BranchServiceProps = ApiServiceType & {
15
+ branchTargetType?: BranchTargetType;
16
+ branchType?: BranchType;
17
+ };
18
+ export type ListBranchProps = BuildApiListParamsProps & {
19
+ branchType?: BranchType;
20
+ };
21
+ export type GetBranchProps = BuildApiGetParamsProps & {
22
+ id: number | string;
23
+ branchType: BranchType;
24
+ };
25
+ type Branch = {
26
+ branchName: string;
27
+ branchCode: string;
28
+ branchContact: string;
29
+ branchEmail: string;
30
+ type: "branch_shipping" | "branch_billing";
31
+ address1: string;
32
+ address2: string;
33
+ countryId: number;
34
+ stateId: number;
35
+ areaId: number;
36
+ postcode: string;
37
+ remark: string;
38
+ picName: string;
39
+ picContact: string;
40
+ picEmail: string;
41
+ isHq: boolean;
42
+ status: boolean;
43
+ };
44
+ export type CreateBranchProps = {
45
+ userId: number;
46
+ branchTargetType?: BranchTargetType;
47
+ branchType?: BranchType;
48
+ data: {
49
+ customerBranch: {
50
+ branch: Branch;
51
+ props: {
52
+ marking: string;
53
+ };
54
+ };
55
+ } | {
56
+ retailBranch: {
57
+ branch: Branch;
58
+ props: {
59
+ marking: string;
60
+ };
61
+ };
62
+ };
63
+ };
64
+ export type UpdateBranchProps = {
65
+ userId: number;
66
+ branchId: number;
67
+ branchTargetType?: BranchTargetType;
68
+ branchType?: BranchType;
69
+ data: {
70
+ customerBranch: {
71
+ branch: Branch;
72
+ props: {
73
+ marking: string;
74
+ };
75
+ };
76
+ } | {
77
+ retailBranch: {
78
+ branch: Branch;
79
+ props: {
80
+ marking: string;
81
+ };
82
+ };
83
+ };
84
+ };
85
+ export type RemoveBranchProps = {
86
+ branchTargetType?: BranchTargetType;
87
+ ids: number[];
88
+ };
89
+ export type GetDataTypeBranchProps = {
90
+ branchType?: BranchType;
91
+ };
92
+ export declare const BranchService: (props?: BranchServiceProps) => {
93
+ list: (props: ListBranchProps) => Promise<{
94
+ status: boolean;
95
+ message: string;
96
+ data?: any;
97
+ }>;
98
+ get: (props: GetBranchProps) => Promise<{
99
+ status: boolean;
100
+ message: string;
101
+ data?: any;
102
+ }>;
103
+ create: ({ data, userId, branchType: overrideBranchType, branchTargetType: overrideBranchTargetType }: CreateBranchProps) => Promise<{
104
+ status: boolean;
105
+ message: string;
106
+ data?: any;
107
+ }>;
108
+ update: ({ userId, branchId, data, branchType: overrideBranchType, branchTargetType: overrideBranchTargetType }: UpdateBranchProps) => Promise<{
109
+ status: boolean;
110
+ message: string;
111
+ data?: any;
112
+ }>;
113
+ remove: ({ ids, branchTargetType: overrideBranchTargetType }: RemoveBranchProps) => Promise<{
114
+ status: boolean;
115
+ message: string;
116
+ data?: any;
117
+ }>;
118
+ getDataTypes: ({ branchType: overrideBranchType }: GetDataTypeBranchProps) => Promise<{
119
+ status: boolean;
120
+ message: string;
121
+ data?: any;
122
+ }>;
123
+ };
124
+ export {};
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BranchService = exports.branchTargetTypes = exports.branchTypes = void 0;
4
+ const lib_1 = require("@/lib");
5
+ const lib_2 = require("@/lib");
6
+ exports.branchTypes = {
7
+ customer: "customer",
8
+ retailer: "retailer",
9
+ };
10
+ exports.branchTargetTypes = {
11
+ customer: "customer",
12
+ retailer: "retailer",
13
+ };
14
+ const getCreatePayload = (branchType, data) => {
15
+ if (branchType === "customer" && "customerBranch" in data) {
16
+ return {
17
+ branch: {
18
+ branch_name: data.customerBranch.branch.branchName,
19
+ branch_code: data.customerBranch.branch.branchCode,
20
+ branch_contact: data.customerBranch.branch.branchContact,
21
+ branch_email: data.customerBranch.branch.branchEmail,
22
+ address_1: data.customerBranch.branch.address1,
23
+ address_2: data.customerBranch.branch.address2,
24
+ country_id: data.customerBranch.branch.countryId,
25
+ state_id: data.customerBranch.branch.stateId,
26
+ area_id: data.customerBranch.branch.areaId,
27
+ pic_name: data.customerBranch.branch.picName,
28
+ pic_contact: data.customerBranch.branch.picContact,
29
+ pic_email: data.customerBranch.branch.picEmail,
30
+ is_hq: data.customerBranch.branch.isHq === true ? 1 : 0,
31
+ status: data.customerBranch.branch.status === true ? 1 : 0,
32
+ },
33
+ props: {
34
+ marking: data.customerBranch.props?.marking ?? "",
35
+ }
36
+ };
37
+ }
38
+ if (branchType === "retailer" && "retailBranch" in data) {
39
+ return {
40
+ branch: {
41
+ branch_name: data.retailBranch.branch.branchName,
42
+ branch_code: data.retailBranch.branch.branchCode,
43
+ branch_contact: data.retailBranch.branch.branchContact,
44
+ branch_email: data.retailBranch.branch.branchEmail,
45
+ address_1: data.retailBranch.branch.address1,
46
+ address_2: data.retailBranch.branch.address2,
47
+ country_id: data.retailBranch.branch.countryId,
48
+ state_id: data.retailBranch.branch.stateId,
49
+ area_id: data.retailBranch.branch.areaId,
50
+ pic_name: data.retailBranch.branch.picName,
51
+ pic_contact: data.retailBranch.branch.picContact,
52
+ pic_email: data.retailBranch.branch.picEmail,
53
+ is_hq: data.retailBranch.branch.isHq === true ? 1 : 0,
54
+ status: data.retailBranch.branch.status === true ? 1 : 0,
55
+ },
56
+ props: {
57
+ marking: data.retailBranch.props?.marking ?? "",
58
+ }
59
+ };
60
+ }
61
+ };
62
+ const getUpdatePayload = (branchType, data) => {
63
+ return getCreatePayload(branchType, data);
64
+ };
65
+ const BranchService = (props) => {
66
+ const { branchType = "customer", branchTargetType, ...rest } = props ?? {};
67
+ const { makeCall } = (0, lib_1.ApiService)(rest?.customToken ? { customToken: rest.customToken } : {});
68
+ const endpoint1 = "user/branch";
69
+ const endpoint2 = "user/branches";
70
+ const list = async (props) => {
71
+ const { branchType: overrideBranchType } = props;
72
+ const url = (0, lib_2.buildApiListUrl)(`${endpoint2}/${overrideBranchType || branchType}`, props);
73
+ const response = await makeCall({
74
+ url,
75
+ method: "get",
76
+ payload: {},
77
+ // configuration
78
+ });
79
+ return response;
80
+ };
81
+ const get = async (props) => {
82
+ const { id, branchType: overrideBranchType } = props;
83
+ const url = (0, lib_2.buildApiGetUrl)(`${endpoint1}/${overrideBranchType || branchType}/${id}`, props);
84
+ const response = await makeCall({
85
+ url,
86
+ method: "get",
87
+ payload: {},
88
+ // configuration
89
+ });
90
+ return response;
91
+ };
92
+ const create = async ({ data, userId, branchType: overrideBranchType, branchTargetType: overrideBranchTargetType }) => {
93
+ let _branchType = overrideBranchType || branchType;
94
+ let payload = getCreatePayload(_branchType, data);
95
+ let url = `${endpoint1}/${userId}`;
96
+ let postData = {
97
+ scope: {
98
+ target: overrideBranchTargetType || branchTargetType,
99
+ action: "",
100
+ },
101
+ payload
102
+ };
103
+ const response = await makeCall({
104
+ url,
105
+ method: "post",
106
+ payload: postData
107
+ });
108
+ return response;
109
+ };
110
+ const update = async ({ userId, branchId, data, branchType: overrideBranchType, branchTargetType: overrideBranchTargetType }) => {
111
+ let url = `${endpoint1}/${userId}/${branchId}`;
112
+ let _branchType = overrideBranchType || branchType;
113
+ let payload = getUpdatePayload(_branchType, data);
114
+ const postData = {
115
+ scope: {
116
+ target: overrideBranchTargetType || branchTargetType,
117
+ action: "",
118
+ },
119
+ payload
120
+ };
121
+ const response = await makeCall({
122
+ url,
123
+ method: "put",
124
+ payload: postData
125
+ });
126
+ return response;
127
+ };
128
+ const remove = async ({ ids, branchTargetType: overrideBranchTargetType }) => {
129
+ let url = `${endpoint2}/delete`;
130
+ const postData = {
131
+ scope: {
132
+ target: overrideBranchTargetType || branchTargetType,
133
+ },
134
+ payload: {
135
+ ids
136
+ }
137
+ };
138
+ const response = await makeCall({
139
+ url,
140
+ method: "post",
141
+ payload: postData
142
+ });
143
+ return response;
144
+ };
145
+ const getDataTypes = async ({ branchType: overrideBranchType }) => {
146
+ let url = `${endpoint2}/data_types/${overrideBranchType || branchType}`;
147
+ const response = await makeCall({
148
+ url,
149
+ method: "get",
150
+ });
151
+ return response;
152
+ };
153
+ return {
154
+ list,
155
+ get,
156
+ create,
157
+ update,
158
+ remove,
159
+ getDataTypes
160
+ };
161
+ };
162
+ exports.BranchService = BranchService;
@@ -0,0 +1,91 @@
1
+ import { ApiServiceType } from '@/lib';
2
+ import { BuildApiListParamsProps, BuildApiGetParamsProps } from '@/lib';
3
+ export declare const businessTypes: {
4
+ readonly business: "business";
5
+ };
6
+ export declare const businessTargetTypes: {
7
+ readonly business: "business";
8
+ };
9
+ export type BusinessType = typeof businessTypes[keyof typeof businessTypes];
10
+ export type BusinessTargetType = typeof businessTargetTypes[keyof typeof businessTargetTypes];
11
+ export type BusinessTargetKey = keyof typeof businessTargetTypes;
12
+ export type BusinessServiceProps = ApiServiceType & {
13
+ businessTargetType?: BusinessTargetType;
14
+ businessType?: BusinessType;
15
+ };
16
+ export type ListBusinessProps = BuildApiListParamsProps & {
17
+ businessType?: BusinessType;
18
+ };
19
+ export type GetBusinessProps = BuildApiGetParamsProps & {
20
+ id: number | string;
21
+ businessType?: BusinessType;
22
+ };
23
+ type Business = {
24
+ companyName: string;
25
+ idNumber: string;
26
+ website: string;
27
+ email: string;
28
+ companyContact: string;
29
+ address1: string;
30
+ address2: string;
31
+ countryId: number;
32
+ stateId: number;
33
+ areaId: number;
34
+ postcode: string;
35
+ status: boolean;
36
+ };
37
+ export type CreateBusinessProps = {
38
+ businessTargetType?: BusinessTargetType;
39
+ businessType?: BusinessType;
40
+ data: {
41
+ business: Business;
42
+ };
43
+ };
44
+ export type UpdateBusinessProps = {
45
+ id: number;
46
+ businessTargetType?: BusinessTargetType;
47
+ businessType?: BusinessType;
48
+ data: {
49
+ business: Business;
50
+ };
51
+ };
52
+ export type RemoveBusinessProps = {
53
+ businessTargetType?: BusinessTargetType;
54
+ ids: number[];
55
+ };
56
+ export type GetDataTypeBusinessProps = {
57
+ businessType?: BusinessType;
58
+ };
59
+ export declare const BusinessService: (props?: BusinessServiceProps) => {
60
+ list: (props: ListBusinessProps) => Promise<{
61
+ status: boolean;
62
+ message: string;
63
+ data?: any;
64
+ }>;
65
+ get: (props: GetBusinessProps) => Promise<{
66
+ status: boolean;
67
+ message: string;
68
+ data?: any;
69
+ }>;
70
+ create: ({ data, businessType: overrideBusinessType, businessTargetType: overrideBusinessTargetType }: CreateBusinessProps) => Promise<{
71
+ status: boolean;
72
+ message: string;
73
+ data?: any;
74
+ }>;
75
+ update: ({ id, data, businessType: overrideBusinessType, businessTargetType: overrideBusinessTargetType }: UpdateBusinessProps) => Promise<{
76
+ status: boolean;
77
+ message: string;
78
+ data?: any;
79
+ }>;
80
+ remove: ({ ids, businessTargetType: overrideBusinessTargetType }: RemoveBusinessProps) => Promise<{
81
+ status: boolean;
82
+ message: string;
83
+ data?: any;
84
+ }>;
85
+ getDataTypes: ({ businessType: overrideBusinessType }: GetDataTypeBusinessProps) => Promise<{
86
+ status: boolean;
87
+ message: string;
88
+ data?: any;
89
+ }>;
90
+ };
91
+ export {};
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BusinessService = exports.businessTargetTypes = exports.businessTypes = void 0;
4
+ const lib_1 = require("@/lib");
5
+ const lib_2 = require("@/lib");
6
+ exports.businessTypes = {
7
+ business: "business",
8
+ };
9
+ exports.businessTargetTypes = {
10
+ business: "business",
11
+ };
12
+ const getCreatePayload = (businessType, data) => {
13
+ if (businessType === "business") {
14
+ return {
15
+ business: {
16
+ company_name: data.business.companyName,
17
+ id_number: data.business.idNumber,
18
+ website: data.business.website,
19
+ email: data.business.email,
20
+ company_contact: data.business.companyContact,
21
+ address_1: data.business.address1,
22
+ address_2: data.business.address2,
23
+ country_id: data.business.countryId,
24
+ state_id: data.business.stateId,
25
+ area_id: data.business.areaId,
26
+ postcode: data.business.postcode,
27
+ status: (data.business.status === true) ? 1 : 0
28
+ }
29
+ };
30
+ }
31
+ };
32
+ const getUpdatePayload = (businessType, data) => {
33
+ if (businessType === "business") {
34
+ return {
35
+ business: {
36
+ company_name: data.business.companyName,
37
+ id_number: data.business.idNumber,
38
+ website: data.business.website,
39
+ email: data.business.email,
40
+ company_contact: data.business.companyContact,
41
+ address_1: data.business.address1,
42
+ address_2: data.business.address2,
43
+ country_id: data.business.countryId,
44
+ state_id: data.business.stateId,
45
+ area_id: data.business.areaId,
46
+ postcode: data.business.postcode,
47
+ status: (data.business.status === true) ? 1 : 0
48
+ }
49
+ };
50
+ }
51
+ };
52
+ const BusinessService = (props) => {
53
+ const { businessType, businessTargetType, ...rest } = props ?? {};
54
+ const { makeCall } = (0, lib_1.ApiService)(rest?.customToken ? { customToken: rest.customToken } : {});
55
+ const endpoint1 = "business";
56
+ const endpoint2 = "businesses";
57
+ const list = async (props) => {
58
+ const { businessType: overrideBusinessType } = props;
59
+ const url = (0, lib_2.buildApiListUrl)(`${endpoint2}/${overrideBusinessType || businessType}`, props);
60
+ const response = await makeCall({
61
+ url,
62
+ method: "get",
63
+ payload: {},
64
+ // configuration
65
+ });
66
+ return response;
67
+ };
68
+ const get = async (props) => {
69
+ const { id, businessType: overrideBusinessType } = props;
70
+ const url = (0, lib_2.buildApiGetUrl)(`${endpoint1}/${overrideBusinessType || businessType}/${id}`, props);
71
+ const response = await makeCall({
72
+ url,
73
+ method: "get",
74
+ payload: {},
75
+ // configuration
76
+ });
77
+ return response;
78
+ };
79
+ const create = async ({ data, businessType: overrideBusinessType, businessTargetType: overrideBusinessTargetType }) => {
80
+ let payload = {};
81
+ if (overrideBusinessType) {
82
+ payload = getCreatePayload(overrideBusinessType, data);
83
+ }
84
+ let url = `${endpoint1}`;
85
+ let postData = {
86
+ scope: {
87
+ target: overrideBusinessTargetType || businessTargetType,
88
+ action: "",
89
+ },
90
+ payload
91
+ };
92
+ const response = await makeCall({
93
+ url,
94
+ method: "post",
95
+ payload: postData
96
+ });
97
+ return response;
98
+ };
99
+ const update = async ({ id, data, businessType: overrideBusinessType, businessTargetType: overrideBusinessTargetType }) => {
100
+ let url = `${endpoint1}/${id}`;
101
+ let payload = {};
102
+ if (overrideBusinessType) {
103
+ payload = getUpdatePayload(overrideBusinessType, data);
104
+ }
105
+ const postData = {
106
+ scope: {
107
+ target: overrideBusinessTargetType || businessTargetType,
108
+ action: "",
109
+ },
110
+ payload
111
+ };
112
+ const response = await makeCall({
113
+ url,
114
+ method: "put",
115
+ payload: postData
116
+ });
117
+ return response;
118
+ };
119
+ const remove = async ({ ids, businessTargetType: overrideBusinessTargetType }) => {
120
+ let url = `${endpoint2}/delete`;
121
+ const postData = {
122
+ scope: {
123
+ target: overrideBusinessTargetType || businessTargetType,
124
+ },
125
+ payload: {
126
+ ids
127
+ }
128
+ };
129
+ const response = await makeCall({
130
+ url,
131
+ method: "post",
132
+ payload: postData
133
+ });
134
+ return response;
135
+ };
136
+ const getDataTypes = async ({ businessType: overrideBusinessType }) => {
137
+ let url = `${endpoint1}/data_types/${overrideBusinessType || businessType}`;
138
+ const response = await makeCall({
139
+ url,
140
+ method: "get",
141
+ });
142
+ return response;
143
+ };
144
+ return {
145
+ list,
146
+ get,
147
+ create,
148
+ update,
149
+ remove,
150
+ getDataTypes
151
+ };
152
+ };
153
+ exports.BusinessService = BusinessService;