@things-factory/sales-base 8.0.2 → 8.0.5
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/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/server/constants/attachment-type.ts +0 -9
- package/server/constants/index.ts +0 -7
- package/server/constants/load-type.ts +0 -4
- package/server/constants/order.ts +0 -203
- package/server/constants/product-group-type.ts +0 -4
- package/server/constants/release-good.ts +0 -9
- package/server/constants/transfer-order-type.ts +0 -6
- package/server/constants/validation-error-code.ts +0 -3
- package/server/constants/vas-target-type.ts +0 -25
- package/server/controllers/ecommerce/ecommerce-controller.ts +0 -122
- package/server/controllers/ecommerce/index.ts +0 -2
- package/server/controllers/ecommerce/sellercraft-controller.ts +0 -182
- package/server/controllers/index.ts +0 -2
- package/server/controllers/order-controller.ts +0 -296
- package/server/errors/index.ts +0 -1
- package/server/errors/validation-error.ts +0 -25
- package/server/index.ts +0 -5
- package/server/migrations/index.ts +0 -9
- package/server/service/arrival-notice/arrival-notice-mutation.ts +0 -1152
- package/server/service/arrival-notice/arrival-notice-query.ts +0 -549
- package/server/service/arrival-notice/arrival-notice-types.ts +0 -310
- package/server/service/arrival-notice/arrival-notice.ts +0 -202
- package/server/service/arrival-notice/index.ts +0 -9
- package/server/service/claim/claim-mutation.ts +0 -308
- package/server/service/claim/claim-query.ts +0 -122
- package/server/service/claim/claim-types.ts +0 -130
- package/server/service/claim/claim.ts +0 -140
- package/server/service/claim/index.ts +0 -9
- package/server/service/claim-detail/claim-detail-mutation.ts +0 -102
- package/server/service/claim-detail/claim-detail-query.ts +0 -55
- package/server/service/claim-detail/claim-detail-types.ts +0 -47
- package/server/service/claim-detail/claim-detail.ts +0 -69
- package/server/service/claim-detail/index.ts +0 -9
- package/server/service/claim-order/claim-order-mutation.ts +0 -101
- package/server/service/claim-order/claim-order-query.ts +0 -47
- package/server/service/claim-order/claim-order-types.ts +0 -35
- package/server/service/claim-order/claim-order.ts +0 -81
- package/server/service/claim-order/index.ts +0 -9
- package/server/service/collection-order/collection-order-mutation.ts +0 -245
- package/server/service/collection-order/collection-order-query.ts +0 -97
- package/server/service/collection-order/collection-order-types.ts +0 -165
- package/server/service/collection-order/collection-order.ts +0 -135
- package/server/service/collection-order/index.ts +0 -9
- package/server/service/delivery-order/delivery-order-mutation.ts +0 -967
- package/server/service/delivery-order/delivery-order-query.ts +0 -631
- package/server/service/delivery-order/delivery-order-types.ts +0 -268
- package/server/service/delivery-order/delivery-order.ts +0 -258
- package/server/service/delivery-order/index.ts +0 -9
- package/server/service/draft-release-good/draft-release-good-mutation.ts +0 -765
- package/server/service/draft-release-good/draft-release-good-query.ts +0 -354
- package/server/service/draft-release-good/draft-release-good-type.ts +0 -261
- package/server/service/draft-release-good/draft-release-good.ts +0 -284
- package/server/service/draft-release-good/index.ts +0 -9
- package/server/service/goods-receival-note/goods-receival-note-mutation.ts +0 -129
- package/server/service/goods-receival-note/goods-receival-note-query.ts +0 -280
- package/server/service/goods-receival-note/goods-receival-note-types.ts +0 -105
- package/server/service/goods-receival-note/goods-receival-note.ts +0 -127
- package/server/service/goods-receival-note/index.ts +0 -9
- package/server/service/index.ts +0 -238
- package/server/service/inventory-check/index.ts +0 -9
- package/server/service/inventory-check/inventory-check-mutation.ts +0 -149
- package/server/service/inventory-check/inventory-check-query.ts +0 -48
- package/server/service/inventory-check/inventory-check-types.ts +0 -48
- package/server/service/inventory-check/inventory-check.ts +0 -90
- package/server/service/invoice/index.ts +0 -9
- package/server/service/invoice/invoice-mutation.ts +0 -95
- package/server/service/invoice/invoice-query.ts +0 -53
- package/server/service/invoice/invoice-types.ts +0 -279
- package/server/service/invoice/invoice.ts +0 -230
- package/server/service/invoice-product/index.ts +0 -9
- package/server/service/invoice-product/invoice-product-mutation.ts +0 -54
- package/server/service/invoice-product/invoice-product-query.ts +0 -54
- package/server/service/invoice-product/invoice-product-types.ts +0 -84
- package/server/service/invoice-product/invoice-product.ts +0 -92
- package/server/service/job-sheet/index.ts +0 -9
- package/server/service/job-sheet/job-sheet-mutation.ts +0 -92
- package/server/service/job-sheet/job-sheet-query.ts +0 -112
- package/server/service/job-sheet/job-sheet-types.ts +0 -78
- package/server/service/job-sheet/job-sheet.ts +0 -102
- package/server/service/manifest/index.ts +0 -6
- package/server/service/manifest/manifest-mutation.ts +0 -190
- package/server/service/manifest/manifest-query.ts +0 -149
- package/server/service/manifest/manifest-type.ts +0 -84
- package/server/service/manifest/manifest.ts +0 -114
- package/server/service/order-inventory/index.ts +0 -9
- package/server/service/order-inventory/order-inventory-mutation.ts +0 -54
- package/server/service/order-inventory/order-inventory-query.ts +0 -722
- package/server/service/order-inventory/order-inventory-types.ts +0 -238
- package/server/service/order-inventory/order-inventory.ts +0 -401
- package/server/service/order-product/index.ts +0 -9
- package/server/service/order-product/order-product-mutation.ts +0 -48
- package/server/service/order-product/order-product-query.ts +0 -89
- package/server/service/order-product/order-product-types.ts +0 -335
- package/server/service/order-product/order-product.ts +0 -362
- package/server/service/order-tote/index.ts +0 -9
- package/server/service/order-tote/order-tote-mutation.ts +0 -31
- package/server/service/order-tote/order-tote-query.ts +0 -112
- package/server/service/order-tote/order-tote-types.ts +0 -47
- package/server/service/order-tote/order-tote.ts +0 -73
- package/server/service/order-tote-item/index.ts +0 -9
- package/server/service/order-tote-item/order-tote-item-mutation.ts +0 -31
- package/server/service/order-tote-item/order-tote-item-query.ts +0 -82
- package/server/service/order-tote-item/order-tote-item-types.ts +0 -56
- package/server/service/order-tote-item/order-tote-item.ts +0 -72
- package/server/service/order-tote-seal/index.ts +0 -9
- package/server/service/order-tote-seal/order-tote-seal-mutation.ts +0 -31
- package/server/service/order-tote-seal/order-tote-seal-query.ts +0 -59
- package/server/service/order-tote-seal/order-tote-seal-types.ts +0 -41
- package/server/service/order-tote-seal/order-tote-seal.ts +0 -46
- package/server/service/order-vas/index.ts +0 -9
- package/server/service/order-vas/order-vas-mutation.ts +0 -20
- package/server/service/order-vas/order-vas-query.ts +0 -72
- package/server/service/order-vas/order-vas-types.ts +0 -159
- package/server/service/order-vas/order-vas.ts +0 -207
- package/server/service/others/index.ts +0 -5
- package/server/service/others/other-query.ts +0 -563
- package/server/service/others/other-types.ts +0 -115
- package/server/service/purchase-order/index.ts +0 -9
- package/server/service/purchase-order/purchase-order-mutation.ts +0 -458
- package/server/service/purchase-order/purchase-order-query.ts +0 -90
- package/server/service/purchase-order/purchase-order-types.ts +0 -154
- package/server/service/purchase-order/purchase-order.ts +0 -172
- package/server/service/purchase-order-other-charge/index.ts +0 -9
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-mutation.ts +0 -31
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-query.ts +0 -52
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-types.ts +0 -44
- package/server/service/purchase-order-other-charge/purchase-order-other-charge.ts +0 -68
- package/server/service/release-good/index.ts +0 -9
- package/server/service/release-good/release-good-mutation.ts +0 -1686
- package/server/service/release-good/release-good-query.ts +0 -980
- package/server/service/release-good/release-good-types.ts +0 -662
- package/server/service/release-good/release-good.ts +0 -490
- package/server/service/retail-replenishment-order/index.ts +0 -9
- package/server/service/retail-replenishment-order/retail-replenishment-order-mutation.ts +0 -382
- package/server/service/retail-replenishment-order/retail-replenishment-order-query.ts +0 -54
- package/server/service/retail-replenishment-order/retail-replenishment-order-types.ts +0 -101
- package/server/service/retail-replenishment-order/retail-replenishment-order.ts +0 -115
- package/server/service/return-order/index.ts +0 -9
- package/server/service/return-order/return-order-mutation.ts +0 -516
- package/server/service/return-order/return-order-query.ts +0 -226
- package/server/service/return-order/return-order-types.ts +0 -196
- package/server/service/return-order/return-order.ts +0 -127
- package/server/service/reverse-kitting-order/index.ts +0 -9
- package/server/service/reverse-kitting-order/reverse-kitting-order-mutation.ts +0 -500
- package/server/service/reverse-kitting-order/reverse-kitting-order-query.ts +0 -197
- package/server/service/reverse-kitting-order/reverse-kitting-order-type.ts +0 -173
- package/server/service/reverse-kitting-order/reverse-kitting-order.ts +0 -121
- package/server/service/reverse-kitting-order-inventory/index.ts +0 -9
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.ts +0 -129
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-query.ts +0 -52
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.ts +0 -95
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +0 -143
- package/server/service/shipping-order/index.ts +0 -9
- package/server/service/shipping-order/shipping-order-mutation.ts +0 -61
- package/server/service/shipping-order/shipping-order-query.ts +0 -61
- package/server/service/shipping-order/shipping-order-types.ts +0 -89
- package/server/service/shipping-order/shipping-order.ts +0 -129
- package/server/service/transfer-order/index.ts +0 -9
- package/server/service/transfer-order/transfer-order-mutation.ts +0 -309
- package/server/service/transfer-order/transfer-order-query.ts +0 -66
- package/server/service/transfer-order/transfer-order-types.ts +0 -97
- package/server/service/transfer-order/transfer-order.ts +0 -117
- package/server/service/vas/index.ts +0 -9
- package/server/service/vas/vas-mutation.ts +0 -106
- package/server/service/vas/vas-query.ts +0 -60
- package/server/service/vas/vas-types.ts +0 -71
- package/server/service/vas/vas.ts +0 -77
- package/server/service/vas-order/index.ts +0 -9
- package/server/service/vas-order/vas-order-mutation.ts +0 -259
- package/server/service/vas-order/vas-order-query.ts +0 -119
- package/server/service/vas-order/vas-order-types.ts +0 -49
- package/server/service/vas-order/vas-order.ts +0 -81
- package/server/utils/datetime-util.ts +0 -54
- package/server/utils/index.ts +0 -3
- package/server/utils/inventory-util.ts +0 -1155
- package/server/utils/order-no-generator.ts +0 -146
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { EntityManager, EntitySchema, FindOneOptions } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Role, User } from '@things-factory/auth-base'
|
|
4
|
-
import { Bizplace, getDomainUsers } from '@things-factory/biz-base'
|
|
5
|
-
import { ProductDetail } from '@things-factory/product-base'
|
|
6
|
-
import { Domain } from '@things-factory/shell'
|
|
7
|
-
import { Inventory } from '@things-factory/warehouse-base'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
ArrivalNotice,
|
|
11
|
-
DeliveryOrder,
|
|
12
|
-
InventoryCheck,
|
|
13
|
-
OrderInventory,
|
|
14
|
-
OrderProduct,
|
|
15
|
-
OrderVas,
|
|
16
|
-
ReleaseGood,
|
|
17
|
-
ReturnOrder,
|
|
18
|
-
VasOrder
|
|
19
|
-
} from '../service'
|
|
20
|
-
|
|
21
|
-
export type ReferenceOrderType = ArrivalNotice | ReleaseGood | VasOrder | InventoryCheck | DeliveryOrder | ReturnOrder
|
|
22
|
-
export type OrderTargetTypes = OrderProduct | OrderInventory | OrderVas
|
|
23
|
-
|
|
24
|
-
export enum ReferenceOrderFields {
|
|
25
|
-
ArrivalNotice = 'arrivalNotice',
|
|
26
|
-
ReleaseGood = 'releaseGood',
|
|
27
|
-
VasOrder = 'vasOrder',
|
|
28
|
-
InventoryCheck = 'inventoryCheck',
|
|
29
|
-
ReturnOrder = 'returnOrder'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export enum OrderTargetFields {
|
|
33
|
-
OrderProduct = 'targetProduct',
|
|
34
|
-
OrderInventory = 'targetInventory',
|
|
35
|
-
OrderVas = 'targetVas'
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface BasicInterface {
|
|
39
|
-
domain: Domain
|
|
40
|
-
user: User
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type NotificationMsgInterface = {
|
|
44
|
-
title: string
|
|
45
|
-
body: string
|
|
46
|
-
url: string
|
|
47
|
-
data: any
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class OrderController {
|
|
51
|
-
public readonly ERROR_MSG = {
|
|
52
|
-
FIND: {
|
|
53
|
-
NO_RESULT: (condition: any) => `There's no results matched with condition ${condition}`,
|
|
54
|
-
NO_CHILD_RESULT: (condition: any) => `There's no child result matched with condition ${condition}`,
|
|
55
|
-
NOT_MATCH: (source: any, target: any) => `Unable to find matching ${target} using ${source}`
|
|
56
|
-
},
|
|
57
|
-
CREATE: {
|
|
58
|
-
ID_EXISTS: 'Target has ID already',
|
|
59
|
-
EMPTY_CREATOR: 'Cannot create without creator',
|
|
60
|
-
EMPTY_UPDATER: 'Cannot create without updater'
|
|
61
|
-
},
|
|
62
|
-
UPDATE: {
|
|
63
|
-
ID_NOT_EXISTS: `Target doesn't have ID`,
|
|
64
|
-
EMPTY_UPDATER: 'Cannot update without updater'
|
|
65
|
-
},
|
|
66
|
-
VALIDITY: {
|
|
67
|
-
UNEXPECTED_FIELD_VALUE: (field: string, expectedValue: any, actualValue: any) =>
|
|
68
|
-
`Expected ${field} value is ${expectedValue} but got ${actualValue}`,
|
|
69
|
-
DUPLICATED: (field: string, value: any) => `There is duplicated ${field} value (${value})`,
|
|
70
|
-
CANT_PROCEED_STEP_BY: (step: string, reason: string) => `Can't proceed to ${step} it because ${reason}`
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private readonly ROLE_NAMES: Record<string, string> = {
|
|
75
|
-
OFFICE_ADMIN: 'Office Admin'
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
protected trxMgr: EntityManager
|
|
79
|
-
protected domain: Domain
|
|
80
|
-
protected user: User
|
|
81
|
-
|
|
82
|
-
constructor(trxMgr: EntityManager, domain: Domain, user: User) {
|
|
83
|
-
this.trxMgr = trxMgr
|
|
84
|
-
this.domain = domain
|
|
85
|
-
this.user = user
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private getRefOrderField(refOrder: ReferenceOrderType): string {
|
|
89
|
-
if (refOrder instanceof ArrivalNotice) {
|
|
90
|
-
return ReferenceOrderFields.ArrivalNotice
|
|
91
|
-
} else if (refOrder instanceof ReleaseGood) {
|
|
92
|
-
return ReferenceOrderFields.ReleaseGood
|
|
93
|
-
} else if (refOrder instanceof VasOrder) {
|
|
94
|
-
return ReferenceOrderFields.VasOrder
|
|
95
|
-
} else if (refOrder instanceof InventoryCheck) {
|
|
96
|
-
return ReferenceOrderFields.InventoryCheck
|
|
97
|
-
} else if (refOrder instanceof ReturnOrder) {
|
|
98
|
-
return ReferenceOrderFields.ReturnOrder
|
|
99
|
-
} else {
|
|
100
|
-
throw new Error(
|
|
101
|
-
this.ERROR_MSG.VALIDITY.UNEXPECTED_FIELD_VALUE('refOrder', 'One of reference order type', refOrder)
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private getOrderTargetField(orderTarget: OrderTargetTypes): string {
|
|
107
|
-
if (orderTarget instanceof OrderProduct) {
|
|
108
|
-
return OrderTargetFields.OrderProduct
|
|
109
|
-
} else if (orderTarget instanceof OrderInventory) {
|
|
110
|
-
return OrderTargetFields.OrderInventory
|
|
111
|
-
} else if (orderTarget instanceof OrderVas) {
|
|
112
|
-
return OrderTargetFields.OrderVas
|
|
113
|
-
} else {
|
|
114
|
-
this.ERROR_MSG.VALIDITY.UNEXPECTED_FIELD_VALUE('orderTarget', 'One of order target type', orderTarget)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @summary Find reference order (ArrivalNotice, ReleaseGood, VasOrder, etc...)
|
|
120
|
-
* @description
|
|
121
|
-
* Find and return reference order with its relations based on passed condition & reltaions
|
|
122
|
-
*/
|
|
123
|
-
async findRefOrder(
|
|
124
|
-
entitySchema: EntitySchema,
|
|
125
|
-
condition: Partial<ReferenceOrderType>,
|
|
126
|
-
relations?: string[]
|
|
127
|
-
): Promise<ReferenceOrderType> {
|
|
128
|
-
condition = this.tidyConditions(condition)
|
|
129
|
-
let findOption: FindOneOptions = { where: condition }
|
|
130
|
-
if (relations?.length > 0) findOption.relations = relations
|
|
131
|
-
|
|
132
|
-
const refOrder: ReferenceOrderType = await this.trxMgr.getRepository(entitySchema).findOne(findOption)
|
|
133
|
-
if (!refOrder) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(findOption))
|
|
134
|
-
|
|
135
|
-
return refOrder
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* @summary Valitiy checker
|
|
140
|
-
* @description It will try to check whether passed record has same properties with passed conditions
|
|
141
|
-
* Basically it will check equality of value
|
|
142
|
-
* If you want to check advanced validation you can pass function to customize the logic of validation
|
|
143
|
-
* Passed function will be call with actual value of record as parameter
|
|
144
|
-
*/
|
|
145
|
-
checkRecordValidity(record: Record<string, any>, conditions: Record<string, any>): void {
|
|
146
|
-
for (let field in conditions) {
|
|
147
|
-
let isValid: boolean = false
|
|
148
|
-
if (typeof conditions[field] === 'function') {
|
|
149
|
-
isValid = conditions[field](record[field])
|
|
150
|
-
} else {
|
|
151
|
-
isValid = conditions[field] === record[field]
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!isValid)
|
|
155
|
-
throw new Error(this.ERROR_MSG.VALIDITY.UNEXPECTED_FIELD_VALUE(field, conditions[field], record[field]))
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @summary Notify to passed users
|
|
161
|
-
* @description Passed notification message will be sent to passed users
|
|
162
|
-
*/
|
|
163
|
-
async notifyToUsers(users: User[], message: NotificationMsgInterface): Promise<void> {
|
|
164
|
-
const receivers: any[] = users.map(user => user.id)
|
|
165
|
-
/**
|
|
166
|
-
* @notes Temporary off sendNotification due to suspect of causing wms down
|
|
167
|
-
*/
|
|
168
|
-
// await sendNotification({
|
|
169
|
-
// receivers,
|
|
170
|
-
// message
|
|
171
|
-
// })
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @summary Notify to office admin
|
|
176
|
-
* @description Passed notification message will be sent to office admin of current domain
|
|
177
|
-
* default role name is defiend as ROLE_NAME.OFFICE_ADMIn by default
|
|
178
|
-
* You can change role name by passing roleName as parameter
|
|
179
|
-
*/
|
|
180
|
-
async notifyToOfficeAdmin(message: NotificationMsgInterface, roleName?: string): Promise<void> {
|
|
181
|
-
const users: User[] = await this.trxMgr
|
|
182
|
-
.getRepository('users_roles')
|
|
183
|
-
.createQueryBuilder('ur')
|
|
184
|
-
.select('ur.users_id', 'id')
|
|
185
|
-
.where(qb => {
|
|
186
|
-
const subQuery = qb
|
|
187
|
-
.subQuery()
|
|
188
|
-
.select('role.id')
|
|
189
|
-
.from(Role, 'role')
|
|
190
|
-
.where('role.name = :roleName', { roleName: roleName || this.ROLE_NAMES.OFFICE_ADMIN })
|
|
191
|
-
.andWhere('role.domain_id = :domainId', { domainId: this.domain.id })
|
|
192
|
-
.getQuery()
|
|
193
|
-
return 'ur.roles_id IN ' + subQuery
|
|
194
|
-
})
|
|
195
|
-
.getRawMany()
|
|
196
|
-
|
|
197
|
-
this.notifyToUsers(users, message)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* @summary Notify to customer of passed bizplace
|
|
202
|
-
* @description Passed notification message will be sent to customer of passed bizplace
|
|
203
|
-
*/
|
|
204
|
-
async notifyToCustomer(bizplace: Bizplace, message: NotificationMsgInterface): Promise<void> {
|
|
205
|
-
const users: any[] = await getDomainUsers(bizplace, this.trxMgr)
|
|
206
|
-
|
|
207
|
-
this.notifyToUsers(users, message)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async createInventory(inventory: Partial<Inventory> | Partial<Inventory>[]): Promise<Inventory | Inventory[]> {
|
|
211
|
-
inventory = this.setStamp(inventory)
|
|
212
|
-
return await this.trxMgr.getRepository(Inventory).save(inventory)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* @summary Update inventory record
|
|
217
|
-
* @description It will update inventory after set a stamp (domain, updater)
|
|
218
|
-
* The special point of this function is that this changes won't generate inventory history
|
|
219
|
-
* If you want to generate inventory history automatically you would better to use transactionInventory function
|
|
220
|
-
*/
|
|
221
|
-
async updateInventory(inventory: Partial<Inventory> | Partial<Inventory>[]): Promise<Inventory | Inventory[]> {
|
|
222
|
-
if (!(inventory as any).id) throw new Error(this.ERROR_MSG.UPDATE.ID_NOT_EXISTS)
|
|
223
|
-
inventory = this.setStamp(inventory)
|
|
224
|
-
return await this.trxMgr.getRepository(Inventory).save(inventory)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async getChildPackingSize(
|
|
228
|
-
productDetails: ProductDetail[],
|
|
229
|
-
defaultProductDetail: ProductDetail,
|
|
230
|
-
unmatchingProductDetail: ProductDetail
|
|
231
|
-
): Promise<number> {
|
|
232
|
-
let hasChildRelation: boolean = Boolean(unmatchingProductDetail?.childProductDetail)
|
|
233
|
-
let hasMatchingChild: boolean
|
|
234
|
-
let packingSize: number = 1
|
|
235
|
-
let currentChildProductDetail: ProductDetail
|
|
236
|
-
|
|
237
|
-
if (hasChildRelation) {
|
|
238
|
-
currentChildProductDetail = productDetails.find(
|
|
239
|
-
(productDetail: ProductDetail) => productDetail.id === unmatchingProductDetail.childProductDetail.id
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
if (!currentChildProductDetail) {
|
|
243
|
-
throw new Error(this.ERROR_MSG.FIND.NOT_MATCH('packing type', `GTIN (${unmatchingProductDetail.gtin})`))
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
hasMatchingChild = Boolean(defaultProductDetail.id === currentChildProductDetail.id)
|
|
247
|
-
if (hasMatchingChild) {
|
|
248
|
-
packingSize = unmatchingProductDetail.packingSize
|
|
249
|
-
} else {
|
|
250
|
-
packingSize = unmatchingProductDetail.packingSize * packingSize
|
|
251
|
-
}
|
|
252
|
-
} else {
|
|
253
|
-
throw new Error(this.ERROR_MSG.FIND.NO_CHILD_RESULT(`${unmatchingProductDetail.gtin}`))
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
while (hasChildRelation && !hasMatchingChild) {
|
|
257
|
-
if (hasMatchingChild) {
|
|
258
|
-
packingSize = currentChildProductDetail.packingSize * packingSize // 12 x 10
|
|
259
|
-
} else if (!hasMatchingChild && hasChildRelation) {
|
|
260
|
-
packingSize = currentChildProductDetail.packingSize * packingSize // 12 x 10
|
|
261
|
-
currentChildProductDetail = productDetails.find(
|
|
262
|
-
(productDetail: ProductDetail) => productDetail.id === currentChildProductDetail.childProductDetail.id
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
hasChildRelation = Boolean(currentChildProductDetail?.childProductDetail)
|
|
266
|
-
hasMatchingChild = Boolean(defaultProductDetail.id === currentChildProductDetail.id)
|
|
267
|
-
} else if (!hasChildRelation && !hasMatchingChild) {
|
|
268
|
-
throw new Error(this.ERROR_MSG.FIND.NO_RESULT(unmatchingProductDetail.gtin))
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return packingSize
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* @summary set common stamp like domain, creator, updater
|
|
277
|
-
* @description Set common stamp to passed record
|
|
278
|
-
* If it doesn't have id it will handle it as creating one
|
|
279
|
-
* If it has id it will handle it as updating one
|
|
280
|
-
*/
|
|
281
|
-
setStamp(record: Record<string, any>): Record<string, any> {
|
|
282
|
-
if (!record.domain) record.domain = this.domain
|
|
283
|
-
if (!record.id && !record.creator) record.creator = this.user
|
|
284
|
-
if (!record.updater) record.updater = this.user
|
|
285
|
-
|
|
286
|
-
return record
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
tidyConditions(record: Record<string, any>): Record<string, any> {
|
|
290
|
-
Object.keys(record).forEach((key: string) => {
|
|
291
|
-
if (record[key] === null || record[key] instanceof Date || Array.isArray(record[key])) delete record[key]
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
return record
|
|
295
|
-
}
|
|
296
|
-
}
|
package/server/errors/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './validation-error'
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as ERROR_CODES from '../constants/validation-error-code'
|
|
2
|
-
|
|
3
|
-
type ValidationErrorArgument = {
|
|
4
|
-
errorCode: string
|
|
5
|
-
message: string
|
|
6
|
-
detail?: Object
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class ValidationError extends Error {
|
|
10
|
-
static get ERROR_CODES(): any {
|
|
11
|
-
return {
|
|
12
|
-
...ERROR_CODES
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
errorCode: any
|
|
17
|
-
detail: Object
|
|
18
|
-
constructor({ errorCode, message, detail }: ValidationErrorArgument) {
|
|
19
|
-
super(errorCode)
|
|
20
|
-
this.name = 'validation-error'
|
|
21
|
-
this.errorCode = errorCode,
|
|
22
|
-
this.message = message
|
|
23
|
-
this.detail = detail
|
|
24
|
-
}
|
|
25
|
-
}
|
package/server/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const glob = require('glob')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
export var migrations = []
|
|
5
|
-
|
|
6
|
-
glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
|
|
7
|
-
if (file.indexOf('index.js') !== -1) return
|
|
8
|
-
migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
|
|
9
|
-
})
|