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,505 @@
1
+ import { ApiService, ApiServiceType } from '@/lib';
2
+
3
+ import {
4
+ buildApiListUrl,
5
+ BuildApiListParamsProps,
6
+ buildApiGetUrl,
7
+ BuildApiGetParamsProps,
8
+ filterOperatorTypes
9
+ } from '@/lib';
10
+
11
+ export const locationTypes = {
12
+ location: "location",
13
+ rack: "rack",
14
+ slot: "slot",
15
+ zone: "zone",
16
+ } as const
17
+
18
+ export const locationTargetTypes = {
19
+ location: "location",
20
+ rack: "rack",
21
+ slot: "slot",
22
+ zone: "zone",
23
+ } as const
24
+
25
+ export type LocationType = keyof typeof locationTypes
26
+ export type LocationTargetType = typeof locationTargetTypes[keyof typeof locationTargetTypes]
27
+ export type LocationTargetKey = keyof typeof locationTargetTypes
28
+
29
+ export type LocationServiceProps = ApiServiceType & {
30
+ locationTargetType?: LocationTargetType
31
+ locationType?: LocationType
32
+ };
33
+
34
+ export type ListLocationProps = BuildApiListParamsProps & {
35
+ locationType?: LocationType
36
+ locationId?: number
37
+ }
38
+
39
+ export type GetLocationProps = BuildApiGetParamsProps & {
40
+ id: number | string
41
+ locationType: LocationType
42
+ }
43
+
44
+ type Location = {
45
+ locationName: string
46
+ locationType?: "administrator" | "retailer"
47
+ personName: string
48
+ personContact: string
49
+ personEmail: string
50
+ address1: string
51
+ address2: string
52
+ postcode: string
53
+ stateId: number
54
+ countryId: number
55
+ areaId: number
56
+ isDefault: boolean
57
+ status: boolean
58
+ }
59
+
60
+ type Rack = {
61
+ locationId: number
62
+ rackName: string
63
+ rackType: "normal" | "reserve"
64
+ sequence: number
65
+ isDefault: boolean
66
+ status: boolean
67
+ }
68
+
69
+ type Slot = {
70
+ rackId: number
71
+ slotId: number
72
+ slotName: string
73
+ status: boolean
74
+ isDefault: boolean
75
+ sequence: number
76
+ }
77
+
78
+ type Zone = {
79
+ locationId: number
80
+ zoneName: string
81
+ sequence: number
82
+ isDefault: boolean
83
+ status: boolean
84
+ }
85
+
86
+ // type LocationLocation = {
87
+ // location: Location
88
+ // }
89
+
90
+ // type LocationRack = {
91
+ // rack: Rack
92
+ // slots?: Slot[]
93
+ // }
94
+
95
+ // type LocationSlot = {
96
+ // slot: Slot
97
+ // }
98
+
99
+ // type LocationZone = {
100
+ // zone: Zone
101
+ // racks: {
102
+ // rackId: number
103
+ // }[]
104
+ // worker: {
105
+ // userId: number
106
+ // }[]
107
+ // }
108
+
109
+ export type CreateLocationProps = {
110
+ locationTargetType?: LocationTargetType
111
+ locationType?: LocationType
112
+ data:
113
+ // Location
114
+ {
115
+ location: Location
116
+ } |
117
+ // Rack
118
+ {
119
+ locationId: number
120
+ rack: Rack
121
+ slots?: Slot[]
122
+ } |
123
+ // Slot
124
+ {
125
+ rackId: number
126
+ slot: Slot
127
+ } |
128
+ // Zone
129
+ {
130
+ locationId: number
131
+ zone: Zone
132
+ racks: {
133
+ rackId: number
134
+ }[]
135
+ worker: {
136
+ userId: number
137
+ }[]
138
+ }
139
+ // LocationLocation |
140
+ // LocationRack & { rack: { locationId: number } } |
141
+ // LocationSlot & { slot: { rackId: number } } |
142
+ // LocationZone & { zone: { locationId: number } }
143
+ }
144
+
145
+ export type UpdateLocationProps = {
146
+ id: number
147
+ locationTargetType?: LocationTargetType
148
+ locationType?: LocationType
149
+ data:
150
+ // Location
151
+ {
152
+ location: Location
153
+ } |
154
+ // Rack
155
+ {
156
+ locationId: number
157
+ rack: Rack
158
+ slots?: Slot[]
159
+ } |
160
+ // Slot
161
+ {
162
+ rackId: number
163
+ slot: Slot
164
+ } |
165
+ // Zone
166
+ {
167
+ locationId: number
168
+ zone: Zone
169
+ racks: {
170
+ rackId: number
171
+ }[]
172
+ worker: {
173
+ userId: number
174
+ }[]
175
+ }
176
+ // LocationLocation |
177
+ // LocationRack & { rack: { locationId: number } } |
178
+ // LocationSlot & { slot: { rackId: number } } |
179
+ // LocationZone & { zone: { locationId: number } }
180
+ }
181
+
182
+ export type RemoveLocationProps = {
183
+ locationTargetType?: LocationTargetType
184
+ ids: number[]
185
+ }
186
+
187
+ export type GetDataTypeLocationProps = {
188
+ locationType?: LocationType
189
+ }
190
+
191
+ const getCreatePayload = (locationType: LocationType, data: CreateLocationProps["data"]) => {
192
+
193
+ if (locationType === "location" && "location" in data) {
194
+
195
+ return {
196
+ location: {
197
+ location_name: data.location.locationName,
198
+ location_type: data.location.locationType,
199
+ person_name: data.location.personName,
200
+ person_contact: data.location.personContact,
201
+ person_email: data.location.personEmail,
202
+ address_1: data.location.address1,
203
+ address_2: data.location.address2,
204
+ postcode: data.location.postcode,
205
+ state_id: data.location.stateId,
206
+ country_id: data.location.countryId,
207
+ area_id: data.location.areaId,
208
+ is_default: (data.location.isDefault === true) ? 1 : 0,
209
+ status: (data.location.status === true) ? 1 : 0,
210
+ }
211
+ }
212
+ }
213
+
214
+ if (locationType === "rack" && "rack" in data) {
215
+
216
+ return {
217
+ rack: {
218
+ location_id: data.rack.locationId,
219
+ rack_name: data.rack.rackName,
220
+ rack_type: data.rack.rackType,
221
+ sequence: data.rack.sequence,
222
+ is_default: (data.rack.isDefault === true) ? 1 : 0,
223
+ status: (data.rack.status === true) ? 1 : 0,
224
+ },
225
+ slots: data.slots?.map((i: Slot) => ({
226
+ slot_name: i.slotName,
227
+ status: (i.status === true) ? 1 : 0,
228
+ is_default: (i.isDefault === true) ? 1 : 0,
229
+ sequence: i.sequence
230
+ }))
231
+ }
232
+ }
233
+
234
+ if (locationType === "slot" && "slot" in data) {
235
+
236
+ return {
237
+ slot: {
238
+ rack_id: data.slot.rackId,
239
+ slot_name: data.slot.slotName,
240
+ status: (data.slot.status === true) ? 1 : 0,
241
+ is_default: (data.slot.isDefault === true) ? 1 : 0,
242
+ sequence: data.slot.sequence
243
+ }
244
+ }
245
+ }
246
+
247
+ if (locationType === "zone" && "zone" in data) {
248
+
249
+ return {
250
+ zone: {
251
+ location_id: data.zone.locationId,
252
+ zone_name: data.zone.zoneName,
253
+ sequence: data.zone.sequence,
254
+ is_default: (data.zone.isDefault === true) ? 1 : 0,
255
+ status: (data.zone.status === true) ? 1 : 0,
256
+ },
257
+ racks: data.racks.map((i) => ({
258
+ rack_id: i.rackId
259
+ })),
260
+ workers: data.worker.map((i) => ({
261
+ user_id: i.userId
262
+ }))
263
+ }
264
+ }
265
+
266
+ }
267
+
268
+ const getUpdatePayload = (locationType: LocationType, data: UpdateLocationProps["data"]) => {
269
+
270
+ if (locationType === "location" && "location" in data) {
271
+
272
+ return {
273
+ location: {
274
+ location_name: data.location.locationName,
275
+ location_type: data.location.locationType,
276
+ person_name: data.location.personName,
277
+ person_contact: data.location.personContact,
278
+ person_email: data.location.personEmail,
279
+ address_1: data.location.address1,
280
+ address_2: data.location.address2,
281
+ postcode: data.location.postcode,
282
+ state_id: data.location.stateId,
283
+ country_id: data.location.countryId,
284
+ area_id: data.location.areaId,
285
+ is_default: (data.location.isDefault === true) ? 1 : 0,
286
+ status: (data.location.status === true) ? 1 : 0,
287
+ }
288
+ }
289
+ }
290
+
291
+ if (locationType === "rack" && "rack" in data) {
292
+
293
+ return {
294
+ rack: {
295
+ location_id: data.rack.locationId,
296
+ rack_name: data.rack.rackName,
297
+ rack_type: data.rack.rackType,
298
+ sequence: data.rack.sequence,
299
+ is_default: (data.rack.isDefault === true) ? 1 : 0,
300
+ status: (data.rack.status === true) ? 1 : 0,
301
+ },
302
+ slots: data.slots?.map((i: Slot) => ({
303
+ slot_name: i.slotName,
304
+ status: (i.status === true) ? 1 : 0,
305
+ is_default: (i.isDefault === true) ? 1 : 0,
306
+ sequence: i.sequence
307
+ }))
308
+ }
309
+ }
310
+
311
+ if (locationType === "slot" && "slot" in data) {
312
+
313
+ return {
314
+ slot: {
315
+ slot_name: data.slot.slotName,
316
+ status: (data.slot.status === true) ? 1 : 0,
317
+ is_default: (data.slot.isDefault === true) ? 1 : 0,
318
+ sequence: data.slot.sequence
319
+ }
320
+ }
321
+ }
322
+
323
+ if (locationType === "zone" && "zone" in data) {
324
+
325
+ return {
326
+ zone: {
327
+ zone_name: data.zone.zoneName,
328
+ sequence: data.zone.sequence,
329
+ is_default: (data.zone.isDefault === true) ? 1 : 0,
330
+ status: (data.zone.status === true) ? 1 : 0,
331
+ },
332
+ racks: data.racks.map((i) => ({
333
+ zone_item_id: "", // ??
334
+ rack_id: i.rackId
335
+ })),
336
+ workers: data.worker.map((i) => ({
337
+ zone_item_id: "", // ??
338
+ user_id: i.userId
339
+ }))
340
+ }
341
+ }
342
+
343
+ }
344
+
345
+ export const LocationService = (props?: LocationServiceProps) => {
346
+
347
+ const { locationType = "location", locationTargetType, ...rest } = props ?? {};
348
+
349
+ const { makeCall } = ApiService(rest?.customToken ? { customToken: rest.customToken } : {})
350
+
351
+ const endpoint1 = "location";
352
+ const endpoint2 = "locations"
353
+
354
+ const list = async (props: ListLocationProps) => {
355
+
356
+ const { locationType: overrideLocationType } = props;
357
+
358
+ let _locationType = overrideLocationType || locationType
359
+
360
+ let url: string
361
+
362
+ if (_locationType === "location") { // only for location
363
+
364
+ url = buildApiListUrl(
365
+ `${endpoint2}/${_locationType}`,
366
+ props
367
+ );
368
+
369
+ } else { // for rack, slot, zone
370
+
371
+ url = buildApiListUrl(
372
+ `${endpoint2}/${_locationType}/${props?.locationId}`,
373
+ props
374
+ );
375
+
376
+ }
377
+
378
+ const response = await makeCall({
379
+ url,
380
+ method: "get",
381
+ payload: {},
382
+ // configuration
383
+ });
384
+
385
+ return response;
386
+
387
+ }
388
+
389
+ const get = async (props: GetLocationProps) => {
390
+
391
+ const { id, locationType: overrideLocationType } = props;
392
+
393
+ const url = buildApiGetUrl(
394
+ `${endpoint1}/${overrideLocationType || locationType}/${id}`,
395
+ props
396
+ );
397
+
398
+ const response = await makeCall({
399
+ url,
400
+ method: "get",
401
+ payload: {},
402
+ // configuration
403
+ });
404
+
405
+ return response;
406
+
407
+ }
408
+
409
+ const create = async ({ data, locationType: overrideLocationType, locationTargetType: overrideLocationTargetType }: CreateLocationProps) => {
410
+
411
+ let _locationType = overrideLocationType || locationType
412
+
413
+ let payload: any = getCreatePayload(_locationType, data)
414
+
415
+ let url = `${endpoint1}`;
416
+
417
+ let postData = {
418
+ scope: {
419
+ target: overrideLocationTargetType || locationTargetType,
420
+ action: "",
421
+ },
422
+ payload
423
+ }
424
+
425
+ const response = await makeCall({
426
+ url,
427
+ method: "post",
428
+ payload: postData
429
+ });
430
+
431
+ return response;
432
+
433
+ }
434
+
435
+ const update = async ({ id, data, locationType: overrideLocationType, locationTargetType: overrideLocationTargetType }: UpdateLocationProps) => {
436
+
437
+ let url = `${endpoint1}/${id}`
438
+
439
+ let _locationType = overrideLocationType || locationType
440
+
441
+ let payload: any = getUpdatePayload(_locationType, data)
442
+
443
+ const postData = {
444
+ scope: {
445
+ target: overrideLocationTargetType || locationTargetType,
446
+ action: "",
447
+ },
448
+ payload
449
+ }
450
+
451
+ const response = await makeCall({
452
+ url,
453
+ method: "put",
454
+ payload: postData
455
+ });
456
+
457
+ return response;
458
+
459
+ }
460
+
461
+ const remove = async ({ ids, locationTargetType: overrideLocationTargetType }: RemoveLocationProps) => {
462
+
463
+ let url = `${endpoint2}/delete`
464
+
465
+ const postData = {
466
+ scope: {
467
+ target: overrideLocationTargetType || locationTargetType,
468
+ },
469
+ payload: {
470
+ ids
471
+ }
472
+ }
473
+
474
+ const response = await makeCall({
475
+ url,
476
+ method: "post",
477
+ payload: postData
478
+ });
479
+
480
+ return response;
481
+
482
+ }
483
+
484
+ const getDataTypes = async ({ locationType: overrideLocationType }: GetDataTypeLocationProps) => {
485
+
486
+ let url = `${endpoint2}/data_types/${overrideLocationType || locationType}`
487
+
488
+ const response = await makeCall({
489
+ url,
490
+ method: "get",
491
+ });
492
+
493
+ return response;
494
+
495
+ }
496
+
497
+ return {
498
+ list,
499
+ get,
500
+ create,
501
+ update,
502
+ remove,
503
+ getDataTypes
504
+ };
505
+ }