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.
- package/.env +1 -0
- package/.vscode/launch.json +24 -0
- package/dist/config/config.d.ts +6 -0
- package/dist/config/config.js +13 -0
- package/dist/config/env.d.ts +7 -0
- package/dist/config/env.js +16 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -0
- package/dist/lib/ApiService.d.ts +41 -0
- package/dist/lib/ApiService.js +143 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +9 -0
- package/dist/lib/queryParams.d.ts +43 -0
- package/dist/lib/queryParams.js +99 -0
- package/dist/services/account/AccountService.d.ts +52 -0
- package/dist/services/account/AccountService.js +119 -0
- package/dist/services/auth/AuthService.d.ts +44 -0
- package/dist/services/auth/AuthService.js +76 -0
- package/dist/services/branch/BranchService.d.ts +124 -0
- package/dist/services/branch/BranchService.js +162 -0
- package/dist/services/business/BusinessService.d.ts +91 -0
- package/dist/services/business/BusinessService.js +153 -0
- package/dist/services/document/DocumentService.d.ts +578 -0
- package/dist/services/document/DocumentService.js +615 -0
- package/dist/services/index.d.ts +36 -0
- package/dist/services/index.js +97 -0
- package/dist/services/injection_field/InjectionFieldService.d.ts +113 -0
- package/dist/services/injection_field/InjectionFieldService.js +220 -0
- package/dist/services/inventory/InventoryService.d.ts +27 -0
- package/dist/services/inventory/InventoryService.js +231 -0
- package/dist/services/item/ItemService.d.ts +227 -0
- package/dist/services/item/ItemService.js +411 -0
- package/dist/services/location/LocationService.d.ts +154 -0
- package/dist/services/location/LocationService.js +256 -0
- package/dist/services/logistic/LogisticService.d.ts +104 -0
- package/dist/services/logistic/LogisticService.js +150 -0
- package/dist/services/permission/PermissionService.d.ts +296 -0
- package/dist/services/permission/PermissionService.js +576 -0
- package/dist/services/permission/config/custom/adminPermission.d.ts +4 -0
- package/dist/services/permission/config/custom/adminPermission.js +18 -0
- package/dist/services/permission/config/custom/config.d.ts +40 -0
- package/dist/services/permission/config/custom/config.js +23 -0
- package/dist/services/permission/config/default/adminPermission.d.ts +2 -0
- package/dist/services/permission/config/default/adminPermission.js +129 -0
- package/dist/services/permission/config/default/agentPermission.d.ts +2 -0
- package/dist/services/permission/config/default/agentPermission.js +43 -0
- package/dist/services/permission/config/default/customerPermission.d.ts +2 -0
- package/dist/services/permission/config/default/customerPermission.js +10 -0
- package/dist/services/permission/config/default/driverPermission.d.ts +2 -0
- package/dist/services/permission/config/default/driverPermission.js +4 -0
- package/dist/services/permission/config/default/workerPermission.d.ts +2 -0
- package/dist/services/permission/config/default/workerPermission.js +25 -0
- package/dist/services/rate/RateService.d.ts +201 -0
- package/dist/services/rate/RateService.js +303 -0
- package/dist/services/region/RegionService.d.ts +111 -0
- package/dist/services/region/RegionService.js +193 -0
- package/dist/services/repository/RepositoryService.d.ts +153 -0
- package/dist/services/repository/RepositoryService.js +243 -0
- package/dist/services/transaction/TransactionService.d.ts +153 -0
- package/dist/services/transaction/TransactionService.js +173 -0
- package/dist/services/user/BranchUserService.d.ts +129 -0
- package/dist/services/user/BranchUserService.js +193 -0
- package/dist/services/user/UserRoleService.d.ts +105 -0
- package/dist/services/user/UserRoleService.js +193 -0
- package/dist/services/user/UserService.d.ts +269 -0
- package/dist/services/user/UserService.js +477 -0
- package/dist/services/wallet/WalletService.d.ts +104 -0
- package/dist/services/wallet/WalletService.js +163 -0
- package/dist/utils/dateUtils.d.ts +6 -0
- package/dist/utils/dateUtils.js +28 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +13 -0
- package/package.json +27 -0
- package/src/config/config.ts +15 -0
- package/src/config/env.ts +18 -0
- package/src/config/index.ts +2 -0
- package/src/index.ts +41 -0
- package/src/lib/ApiService.ts +170 -0
- package/src/lib/index.ts +5 -0
- package/src/lib/queryParams.ts +162 -0
- package/src/services/account/AccountService.ts +232 -0
- package/src/services/auth/AuthService.ts +125 -0
- package/src/services/branch/BranchService.ts +330 -0
- package/src/services/business/BusinessService.ts +277 -0
- package/src/services/document/DocumentService.ts +1471 -0
- package/src/services/index.ts +73 -0
- package/src/services/injection_field/InjectionFieldService.ts +483 -0
- package/src/services/inventory/InventoryService.ts +314 -0
- package/src/services/item/ItemService.ts +707 -0
- package/src/services/location/LocationService.ts +505 -0
- package/src/services/logistic/LogisticService.ts +285 -0
- package/src/services/permission/PermissionService.ts +1069 -0
- package/src/services/permission/config/custom/adminPermission.ts +19 -0
- package/src/services/permission/config/custom/config.ts +39 -0
- package/src/services/permission/config/default/adminPermission.ts +129 -0
- package/src/services/permission/config/default/agentPermission.ts +42 -0
- package/src/services/permission/config/default/customerPermission.ts +9 -0
- package/src/services/permission/config/default/driverPermission.ts +4 -0
- package/src/services/permission/config/default/workerPermission.ts +25 -0
- package/src/services/rate/RateService.ts +570 -0
- package/src/services/region/RegionService.ts +353 -0
- package/src/services/repository/RepositoryService.ts +437 -0
- package/src/services/transaction/TransactionService.ts +404 -0
- package/src/services/user/BranchUserService.ts +381 -0
- package/src/services/user/UserRoleService.ts +342 -0
- package/src/services/user/UserService.ts +807 -0
- package/src/services/wallet/WalletService.ts +300 -0
- package/src/utils/dateUtils.ts +26 -0
- package/src/utils/index.ts +2 -0
- package/tsconfig.json +119 -0
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import { ApiService, ApiServiceType } from '@/lib';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildApiListUrl,
|
|
5
|
+
BuildApiListParamsProps,
|
|
6
|
+
buildApiGetUrl,
|
|
7
|
+
BuildApiGetParamsProps,
|
|
8
|
+
filterOperatorTypes
|
|
9
|
+
} from '@/lib';
|
|
10
|
+
|
|
11
|
+
// only for item uom
|
|
12
|
+
const decimalPlaces = [0, 1, 2, 3, 4]
|
|
13
|
+
|
|
14
|
+
const metricTypes = {
|
|
15
|
+
weight: [
|
|
16
|
+
{ id: 'kg', abbreviation: 'kg', name: 'kilogram' },
|
|
17
|
+
{ id: 'g', abbreviation: 'g', name: 'gram' }
|
|
18
|
+
],
|
|
19
|
+
volume: [
|
|
20
|
+
{ id: 'ml', abbreviation: 'ml', name: 'mililitre' },
|
|
21
|
+
{ id: 'l', abbreviation: 'l', name: 'litre' }
|
|
22
|
+
],
|
|
23
|
+
unit: [
|
|
24
|
+
{ id: 'unit', abbreviation: 'unit', name: 'unit' }
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const uomConfig = {
|
|
29
|
+
decimalPlaces,
|
|
30
|
+
metricTypes
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const itemTypes = {
|
|
34
|
+
item: "item",
|
|
35
|
+
brand: "item_brand",
|
|
36
|
+
category: "item_category",
|
|
37
|
+
uom: "item_uom",
|
|
38
|
+
product: "product"
|
|
39
|
+
} as const
|
|
40
|
+
|
|
41
|
+
export const itemTargetTypes = {
|
|
42
|
+
item: "item",
|
|
43
|
+
brand: "item_brand",
|
|
44
|
+
category: "item_category",
|
|
45
|
+
uom: "item_uom",
|
|
46
|
+
product: "product"
|
|
47
|
+
} as const
|
|
48
|
+
|
|
49
|
+
// export const actionTypes = {
|
|
50
|
+
// item: {
|
|
51
|
+
// image: "item_image"
|
|
52
|
+
// }
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
export type ItemType = typeof itemTypes[keyof typeof itemTypes]
|
|
56
|
+
export type ItemTargetType = typeof itemTargetTypes[keyof typeof itemTargetTypes]
|
|
57
|
+
export type ItemTargetKey = keyof typeof itemTargetTypes
|
|
58
|
+
|
|
59
|
+
export type ItemServiceProps = ApiServiceType & {
|
|
60
|
+
itemTargetType?: ItemTargetType
|
|
61
|
+
itemType?: ItemType
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type ListItemProps = BuildApiListParamsProps & {
|
|
65
|
+
itemType?: ItemType
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type GetItemProps = BuildApiGetParamsProps & {
|
|
69
|
+
id: number | string
|
|
70
|
+
itemType: ItemType
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type Product = {
|
|
74
|
+
name: string
|
|
75
|
+
model: string
|
|
76
|
+
productCode: string
|
|
77
|
+
description: string
|
|
78
|
+
categoryId: number
|
|
79
|
+
brandId: number
|
|
80
|
+
summary: string
|
|
81
|
+
defaultUomItemId: number,
|
|
82
|
+
status: boolean
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type ItemProp = {
|
|
86
|
+
supplierId: number[]
|
|
87
|
+
transformRatio?: number,
|
|
88
|
+
repackRemark: string
|
|
89
|
+
scanningCodePrefix: string
|
|
90
|
+
scanningCodeSuffix: string
|
|
91
|
+
relocateTopupQty: number
|
|
92
|
+
reorderTopupQty: number
|
|
93
|
+
relocateThresholdQty: number
|
|
94
|
+
reorderThresholdQty: number
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type Item = {
|
|
98
|
+
productId: number
|
|
99
|
+
isPackage: boolean
|
|
100
|
+
status: boolean
|
|
101
|
+
code: string
|
|
102
|
+
description: string
|
|
103
|
+
remark: string
|
|
104
|
+
cost: number
|
|
105
|
+
uomId: number
|
|
106
|
+
uomPrice: number
|
|
107
|
+
floorPrice: number
|
|
108
|
+
volumeWeight: number
|
|
109
|
+
grossWeight: number
|
|
110
|
+
netWeight: number
|
|
111
|
+
dimensionWidth: number
|
|
112
|
+
dimensionHeight: number
|
|
113
|
+
dimensionLength: number
|
|
114
|
+
cbm: number
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type Category = {
|
|
118
|
+
parentCategoryId: number
|
|
119
|
+
name: string
|
|
120
|
+
description: string
|
|
121
|
+
status: boolean
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type Brand = {
|
|
125
|
+
name: string
|
|
126
|
+
description: string
|
|
127
|
+
status: boolean
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type Uom = {
|
|
131
|
+
name: string
|
|
132
|
+
description: string
|
|
133
|
+
metricType: "weight" | "unit" | "volume" /* weight, unit , volume */
|
|
134
|
+
metricTypeDisplayName: string
|
|
135
|
+
decimalDigit: number,
|
|
136
|
+
status: boolean
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type CreateItemProps = {
|
|
140
|
+
itemTargetType?: ItemTargetType
|
|
141
|
+
itemType?: ItemType
|
|
142
|
+
data:
|
|
143
|
+
// product
|
|
144
|
+
{
|
|
145
|
+
product: {
|
|
146
|
+
product: Product,
|
|
147
|
+
item: Omit<Item, "productId">,
|
|
148
|
+
props?: ItemProp,
|
|
149
|
+
status: {
|
|
150
|
+
scanningShowCbm: boolean
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} |
|
|
154
|
+
// item
|
|
155
|
+
{
|
|
156
|
+
item: {
|
|
157
|
+
item: Item,
|
|
158
|
+
props: ItemProp,
|
|
159
|
+
status: {
|
|
160
|
+
scanningShowCbm: boolean
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
} |
|
|
164
|
+
// category
|
|
165
|
+
{
|
|
166
|
+
itemCategory: Category
|
|
167
|
+
} |
|
|
168
|
+
// brand
|
|
169
|
+
{
|
|
170
|
+
itemBrand: Brand
|
|
171
|
+
} |
|
|
172
|
+
// uom
|
|
173
|
+
{
|
|
174
|
+
itemUom: Uom
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// only for type = item
|
|
179
|
+
export type CreateMultipleItemProps = {
|
|
180
|
+
itemTargetType?: Extract<ItemTargetType, "item">
|
|
181
|
+
itemType?: Extract<ItemType, "item">
|
|
182
|
+
data: Item[]
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type CreateMultipleItemPropsProps = {
|
|
186
|
+
itemTargetType?: Extract<ItemTargetType, "item">
|
|
187
|
+
itemType?: Extract<ItemType, "item">
|
|
188
|
+
data: (ItemProp & { itemId: number })[]
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type UpdateItemProps = {
|
|
192
|
+
id: number
|
|
193
|
+
itemTargetType?: ItemTargetType
|
|
194
|
+
itemType?: ItemType
|
|
195
|
+
data: // product
|
|
196
|
+
{
|
|
197
|
+
product: Product,
|
|
198
|
+
item: Omit<Item, "productId">,
|
|
199
|
+
props?: ItemProp
|
|
200
|
+
status: {
|
|
201
|
+
scanningShowCbm: boolean
|
|
202
|
+
}
|
|
203
|
+
} |
|
|
204
|
+
// item
|
|
205
|
+
{
|
|
206
|
+
item: Omit<Item, "productId">,
|
|
207
|
+
props: ItemProp,
|
|
208
|
+
status: {
|
|
209
|
+
scanningShowCbm: boolean
|
|
210
|
+
}
|
|
211
|
+
} |
|
|
212
|
+
// category
|
|
213
|
+
{
|
|
214
|
+
itemCategory: Category
|
|
215
|
+
} |
|
|
216
|
+
// brand
|
|
217
|
+
{
|
|
218
|
+
itemBrand: Brand
|
|
219
|
+
} |
|
|
220
|
+
// uom
|
|
221
|
+
{
|
|
222
|
+
itemUom: Uom
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export type RemoveItemProps = {
|
|
227
|
+
itemTargetType?: ItemTargetType
|
|
228
|
+
ids: number[]
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type GetDataTypeItemProps = {
|
|
232
|
+
itemType?: ItemType
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const getCreatePayload = (itemType: ItemType, data: CreateItemProps["data"]) => {
|
|
236
|
+
|
|
237
|
+
if (itemType === "product" && "product" in data) {
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
product: {
|
|
241
|
+
item_name: data.product.product.name,
|
|
242
|
+
model: data.product.product.model,
|
|
243
|
+
product_code: data.product.product.productCode,
|
|
244
|
+
description: data.product.product.description,
|
|
245
|
+
category_id: data.product.product.categoryId,
|
|
246
|
+
brand_id: data.product.product.brandId,
|
|
247
|
+
summary: data.product.product.summary,
|
|
248
|
+
status: data.product.product.status === true ? 1 : 0
|
|
249
|
+
},
|
|
250
|
+
item: {
|
|
251
|
+
is_package: data.product.item.isPackage === true ? 1 : 0,
|
|
252
|
+
status: data.product.item.status === true ? 1 : 0,
|
|
253
|
+
uom_id: data.product.item.uomId,
|
|
254
|
+
code: data.product.item.code,
|
|
255
|
+
item_description: data.product.item.description,
|
|
256
|
+
remark: data.product.item.remark,
|
|
257
|
+
cost: data.product.item.cost,
|
|
258
|
+
uom_price: data.product.item.uomPrice,
|
|
259
|
+
floor_price: data.product.item.floorPrice,
|
|
260
|
+
volume_weight: data.product.item.volumeWeight,
|
|
261
|
+
gross_weight: data.product.item.grossWeight,
|
|
262
|
+
net_weight: data.product.item.netWeight,
|
|
263
|
+
dimension_width: data.product.item.dimensionWidth,
|
|
264
|
+
dimension_height: data.product.item.dimensionHeight,
|
|
265
|
+
dimension_length: data.product.item.dimensionLength,
|
|
266
|
+
cbm: data.product.item.cbm,
|
|
267
|
+
props: {
|
|
268
|
+
...(data?.product.props?.transformRatio && { transformRatio: data.product.props.transformRatio }),
|
|
269
|
+
supplier_id: data.product.props?.supplierId || "",
|
|
270
|
+
repack_remark: data.product.props?.repackRemark || "",
|
|
271
|
+
scanning_code_prefix: data.product.props?.scanningCodePrefix || "",
|
|
272
|
+
scanning_code_suffix: data.product.props?.scanningCodeSuffix || "",
|
|
273
|
+
relocate_topup_qty: data.product.props?.relocateTopupQty || "",
|
|
274
|
+
reorder_topup_qty: data.product.props?.reorderTopupQty || "",
|
|
275
|
+
relocate_threshold_qty: data.product.props?.relocateThresholdQty || "",
|
|
276
|
+
reorder_threshold_qty: data.product.props?.reorderThresholdQty || "",
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
status: {
|
|
280
|
+
scanning_show_cbm: data.product.status.scanningShowCbm === true ? 1 : 0
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (itemType === "item" && "item" in data) {
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
item: {
|
|
289
|
+
product_id: data.item.item.productId,
|
|
290
|
+
code: data.item.item.code,
|
|
291
|
+
uom_id: data.item.item.uomId,
|
|
292
|
+
status: data.item.item.status === true ? 1 : 0,
|
|
293
|
+
is_package: data.item.item.isPackage === true ? 1 : 0,
|
|
294
|
+
item_description: data.item.item.description,
|
|
295
|
+
remark: data.item.item.remark,
|
|
296
|
+
cost: data.item.item.cost,
|
|
297
|
+
uom_price: data.item.item.uomPrice,
|
|
298
|
+
floor_price: data.item.item.floorPrice,
|
|
299
|
+
gross_weight: data.item.item.grossWeight,
|
|
300
|
+
volume_weight: data.item.item.volumeWeight,
|
|
301
|
+
net_weight: data.item.item.netWeight,
|
|
302
|
+
dimension_width: data.item.item.dimensionWidth,
|
|
303
|
+
dimension_height: data.item.item.dimensionHeight,
|
|
304
|
+
dimension_length: data.item.item.dimensionLength,
|
|
305
|
+
cbm: data.item.item.cbm
|
|
306
|
+
},
|
|
307
|
+
props: {
|
|
308
|
+
supplier_id: data?.item.props?.supplierId || "",
|
|
309
|
+
repack_remark: data?.item.props?.repackRemark || "",
|
|
310
|
+
scanning_code_prefix: data?.item.props?.scanningCodePrefix || "",
|
|
311
|
+
scanning_code_suffix: data?.item.props?.scanningCodeSuffix || "",
|
|
312
|
+
relocate_topup_qty: data?.item.props?.relocateTopupQty || "",
|
|
313
|
+
reorder_topup_qty: data?.item.props?.reorderTopupQty || "",
|
|
314
|
+
relocate_threshold_qty: data?.item.props?.relocateThresholdQty || "",
|
|
315
|
+
reorder_threshold_qty: data?.item.props?.reorderThresholdQty || "",
|
|
316
|
+
...(data?.item.props?.transformRatio && { transformRatio: data.item.props.transformRatio }),
|
|
317
|
+
},
|
|
318
|
+
status: {
|
|
319
|
+
scanning_show_cbm: data.item.status.scanningShowCbm === true ? 1 : 0
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (itemType === "item_category" && "itemCategory" in data) {
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
item_category: {
|
|
329
|
+
parent_category_id: data.itemCategory.parentCategoryId,
|
|
330
|
+
name: data.itemCategory.name,
|
|
331
|
+
description: data.itemCategory.description,
|
|
332
|
+
status: data.itemCategory.status === true ? 1 : 0
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (itemType === "item_brand" && "itemBrand" in data) {
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
item_brand: {
|
|
341
|
+
name: data.itemBrand.name,
|
|
342
|
+
description: data.itemBrand.description,
|
|
343
|
+
status: data.itemBrand.status === true ? 1 : 0
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (itemType === "item_uom" && "itemUom" in data) {
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
item_uom: {
|
|
352
|
+
name: data.itemUom.name,
|
|
353
|
+
description: data.itemUom.description,
|
|
354
|
+
metric_type: data.itemUom.metricType,
|
|
355
|
+
metric_type_display_name: data.itemUom.metricTypeDisplayName,
|
|
356
|
+
decimal_digit: data.itemUom.decimalDigit,
|
|
357
|
+
status: data.itemUom.status === true ? 1 : 0
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const getMultipleCreatePayload = (multipleType: "item" | "item_props", data: CreateMultipleItemProps["data"] | CreateMultipleItemPropsProps["data"]) => {
|
|
365
|
+
|
|
366
|
+
if (multipleType === "item" && "item" in data) {
|
|
367
|
+
|
|
368
|
+
const items = data as CreateMultipleItemProps["data"]
|
|
369
|
+
|
|
370
|
+
return {
|
|
371
|
+
item: items.map((i) => ({
|
|
372
|
+
is_package: i.isPackage === true ? 1 : 0,
|
|
373
|
+
status: i.status === true ? 1 : 0,
|
|
374
|
+
uom_id: i.uomId,
|
|
375
|
+
code: i.code,
|
|
376
|
+
item_description: i.description,
|
|
377
|
+
remark: i.remark,
|
|
378
|
+
cost: i.cost,
|
|
379
|
+
uom_price: i.uomPrice,
|
|
380
|
+
floor_price: i.floorPrice,
|
|
381
|
+
volume_weight: i.volumeWeight,
|
|
382
|
+
gross_weight: i.grossWeight,
|
|
383
|
+
net_weight: i.netWeight,
|
|
384
|
+
dimension_width: i.dimensionWidth,
|
|
385
|
+
dimension_height: i.dimensionHeight,
|
|
386
|
+
dimension_length: i.dimensionLength,
|
|
387
|
+
product_id: i.productId,
|
|
388
|
+
}))
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (multipleType === "item_props" && "itemProps" in data) {
|
|
394
|
+
|
|
395
|
+
const items = data as CreateMultipleItemPropsProps["data"]
|
|
396
|
+
|
|
397
|
+
return {
|
|
398
|
+
item: items.map((i) => ({
|
|
399
|
+
item_id: i.itemId,
|
|
400
|
+
scanning_code_prefix: i.scanningCodePrefix,
|
|
401
|
+
scanningCodeSuffix: i.scanningCodeSuffix
|
|
402
|
+
}))
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const getUpdatePayload = (itemType: ItemType, data: UpdateItemProps["data"]) => {
|
|
410
|
+
|
|
411
|
+
if (itemType === "product" && "product" in data) {
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
product: {
|
|
415
|
+
item_name: data.product.name,
|
|
416
|
+
model: data.product.model,
|
|
417
|
+
product_code: data.product.productCode,
|
|
418
|
+
description: data.product.description,
|
|
419
|
+
category_id: data.product.categoryId,
|
|
420
|
+
brand_id: data.product.brandId,
|
|
421
|
+
summary: data.product.summary,
|
|
422
|
+
status: data.product.status === true ? 1 : 0
|
|
423
|
+
},
|
|
424
|
+
props: {
|
|
425
|
+
default_uom_item_id: data.product.defaultUomItemId || 0
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (itemType === "item" && "item" in data) {
|
|
431
|
+
|
|
432
|
+
return {
|
|
433
|
+
item: {
|
|
434
|
+
code: data.item.code,
|
|
435
|
+
uom_id: data.item.uomId,
|
|
436
|
+
is_package: data.item.isPackage === true ? 1 : 0,
|
|
437
|
+
status: data.item.status === true ? 1 : 0,
|
|
438
|
+
item_description: data.item.description,
|
|
439
|
+
remark: data.item.remark,
|
|
440
|
+
cost: data.item.cost,
|
|
441
|
+
uom_price: data.item.uomPrice,
|
|
442
|
+
floor_price: data.item.floorPrice,
|
|
443
|
+
gross_weight: data.item.grossWeight,
|
|
444
|
+
volume_weight: data.item.volumeWeight,
|
|
445
|
+
net_weight: data.item.netWeight,
|
|
446
|
+
dimension_width: data.item.dimensionWidth,
|
|
447
|
+
dimension_height: data.item.dimensionHeight,
|
|
448
|
+
dimension_length: data.item.dimensionLength,
|
|
449
|
+
cbm: data.item.cbm
|
|
450
|
+
},
|
|
451
|
+
props: {
|
|
452
|
+
supplier_id: data?.props?.supplierId || "",
|
|
453
|
+
repack_remark: data?.props?.repackRemark || "",
|
|
454
|
+
scanning_code_prefix: data?.props?.scanningCodePrefix || "",
|
|
455
|
+
scanning_code_suffix: data?.props?.scanningCodeSuffix || "",
|
|
456
|
+
relocate_topup_qty: data?.props?.relocateTopupQty || "",
|
|
457
|
+
reorder_topup_qty: data?.props?.reorderTopupQty || "",
|
|
458
|
+
relocate_threshold_qty: data?.props?.relocateThresholdQty || "",
|
|
459
|
+
reorder_threshold_qty: data?.props?.reorderThresholdQty || "",
|
|
460
|
+
...(data?.props?.transformRatio && { transformRatio: data.props.transformRatio }),
|
|
461
|
+
},
|
|
462
|
+
status: {
|
|
463
|
+
scanning_show_cbm: data.status.scanningShowCbm === true ? 1 : 0
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (itemType === "item_category" && "itemCategory" in data) {
|
|
470
|
+
|
|
471
|
+
return {
|
|
472
|
+
item_category: {
|
|
473
|
+
name: data.itemCategory.name,
|
|
474
|
+
description: data.itemCategory.description,
|
|
475
|
+
status: data.itemCategory.status === true ? 1 : 0
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (itemType === "item_brand" && "itemBrand" in data) {
|
|
481
|
+
|
|
482
|
+
return {
|
|
483
|
+
item_brand: {
|
|
484
|
+
name: data.itemBrand.name,
|
|
485
|
+
description: data.itemBrand.description,
|
|
486
|
+
status: data.itemBrand.status === true ? 1 : 0
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (itemType === "item_uom" && "itemUom" in data) {
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
item_uom: {
|
|
495
|
+
name: data.itemUom.name,
|
|
496
|
+
description: data.itemUom.description,
|
|
497
|
+
metric_type: data.itemUom.metricType,
|
|
498
|
+
metric_type_display_name: data.itemUom.metricTypeDisplayName,
|
|
499
|
+
decimal_digit: data.itemUom.decimalDigit,
|
|
500
|
+
status: data.itemUom.status === true ? 1 : 0
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export const ItemService = (props?: ItemServiceProps) => {
|
|
508
|
+
|
|
509
|
+
const { itemType = "product", itemTargetType, ...rest } = props ?? {};
|
|
510
|
+
|
|
511
|
+
const { makeCall } = ApiService(rest?.customToken ? { customToken: rest.customToken } : {})
|
|
512
|
+
|
|
513
|
+
const endpoint1 = "item";
|
|
514
|
+
const endpoint2 = "items"
|
|
515
|
+
|
|
516
|
+
const list = async (props: ListItemProps) => {
|
|
517
|
+
|
|
518
|
+
const { itemType: overrideItemType } = props;
|
|
519
|
+
|
|
520
|
+
const url = buildApiListUrl(
|
|
521
|
+
`${endpoint2}/${overrideItemType || itemType}`,
|
|
522
|
+
props
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
const response = await makeCall({
|
|
526
|
+
url,
|
|
527
|
+
method: "get",
|
|
528
|
+
payload: {},
|
|
529
|
+
// configuration
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
return response;
|
|
533
|
+
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const get = async (props: GetItemProps) => {
|
|
537
|
+
|
|
538
|
+
const { id, itemType: overrideItemType } = props;
|
|
539
|
+
|
|
540
|
+
const url = buildApiGetUrl(
|
|
541
|
+
`${endpoint1}/${overrideItemType || itemType}/${id}`,
|
|
542
|
+
props
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
const response = await makeCall({
|
|
546
|
+
url,
|
|
547
|
+
method: "get",
|
|
548
|
+
payload: {},
|
|
549
|
+
// configuration
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
return response;
|
|
553
|
+
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const create = async ({ data, itemType: overrideItemType, itemTargetType: overrideItemTargetType }: CreateItemProps) => {
|
|
557
|
+
|
|
558
|
+
let url = `${endpoint1}`;
|
|
559
|
+
|
|
560
|
+
let _itemType = overrideItemType || itemType
|
|
561
|
+
|
|
562
|
+
let payload: any = getCreatePayload(_itemType, data)
|
|
563
|
+
|
|
564
|
+
let postData = {
|
|
565
|
+
scope: {
|
|
566
|
+
target: overrideItemTargetType || itemTargetType,
|
|
567
|
+
action: "",
|
|
568
|
+
},
|
|
569
|
+
payload
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const response = await makeCall({
|
|
573
|
+
url,
|
|
574
|
+
method: "post",
|
|
575
|
+
payload: postData
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
return response;
|
|
579
|
+
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const update = async ({ id, data, itemType: overrideItemType, itemTargetType: overrideItemTargetType }: UpdateItemProps) => {
|
|
583
|
+
|
|
584
|
+
let url = `${endpoint1}/${id}`
|
|
585
|
+
|
|
586
|
+
let _itemType = overrideItemType || itemType
|
|
587
|
+
|
|
588
|
+
let payload: any = getUpdatePayload(_itemType, data)
|
|
589
|
+
|
|
590
|
+
const postData = {
|
|
591
|
+
scope: {
|
|
592
|
+
target: overrideItemTargetType || itemTargetType,
|
|
593
|
+
action: "",
|
|
594
|
+
},
|
|
595
|
+
payload
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
const response = await makeCall({
|
|
599
|
+
url,
|
|
600
|
+
method: "put",
|
|
601
|
+
payload: postData
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
return response;
|
|
605
|
+
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const remove = async ({ ids, itemTargetType: overrideItemTargetType }: RemoveItemProps) => {
|
|
609
|
+
|
|
610
|
+
let url = `${endpoint2}/${itemTargetType}/delete`
|
|
611
|
+
|
|
612
|
+
const postData = {
|
|
613
|
+
scope: {
|
|
614
|
+
target: overrideItemTargetType || itemTargetType,
|
|
615
|
+
},
|
|
616
|
+
payload: {
|
|
617
|
+
ids
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const response = await makeCall({
|
|
622
|
+
url,
|
|
623
|
+
method: "post",
|
|
624
|
+
payload: postData
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
return response;
|
|
628
|
+
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const getDataTypes = async ({ itemType: overrideItemType }: GetDataTypeItemProps) => {
|
|
632
|
+
|
|
633
|
+
let url = `${endpoint2}/data_types/${overrideItemType || itemType}`
|
|
634
|
+
|
|
635
|
+
const response = await makeCall({
|
|
636
|
+
url,
|
|
637
|
+
method: "get",
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
return response;
|
|
641
|
+
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
const multipleItemCreate = async ({ data, itemType: overrideItemType, itemTargetType: overrideItemTargetType }: CreateMultipleItemProps) => {
|
|
645
|
+
|
|
646
|
+
let _itemType = overrideItemType || itemType
|
|
647
|
+
|
|
648
|
+
let url = `${endpoint2}/${_itemType}/bulk_item`;
|
|
649
|
+
|
|
650
|
+
let payload: any = getMultipleCreatePayload("item", data)
|
|
651
|
+
|
|
652
|
+
let postData = {
|
|
653
|
+
scope: {
|
|
654
|
+
target: overrideItemTargetType || itemTargetType,
|
|
655
|
+
action: "",
|
|
656
|
+
},
|
|
657
|
+
payload
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const response = await makeCall({
|
|
661
|
+
url,
|
|
662
|
+
method: "post",
|
|
663
|
+
payload: postData
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
return response;
|
|
667
|
+
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const multipleItemPropsCreate = async ({ data, itemType: overrideItemType, itemTargetType: overrideItemTargetType }: CreateMultipleItemPropsProps) => {
|
|
671
|
+
|
|
672
|
+
let _itemType = overrideItemType || itemType
|
|
673
|
+
|
|
674
|
+
let url = `${endpoint2}/${_itemType}/bulk_item_props`;
|
|
675
|
+
|
|
676
|
+
let payload: any = getMultipleCreatePayload("item_props", data)
|
|
677
|
+
|
|
678
|
+
let postData = {
|
|
679
|
+
scope: {
|
|
680
|
+
target: overrideItemTargetType || itemTargetType,
|
|
681
|
+
action: "",
|
|
682
|
+
},
|
|
683
|
+
payload
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const response = await makeCall({
|
|
687
|
+
url,
|
|
688
|
+
method: "post",
|
|
689
|
+
payload: postData
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
return response;
|
|
693
|
+
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
return {
|
|
697
|
+
filterOperatorTypes,
|
|
698
|
+
list,
|
|
699
|
+
get,
|
|
700
|
+
create,
|
|
701
|
+
multipleItemCreate,
|
|
702
|
+
multipleItemPropsCreate,
|
|
703
|
+
update,
|
|
704
|
+
remove,
|
|
705
|
+
getDataTypes
|
|
706
|
+
};
|
|
707
|
+
}
|