@things-factory/operato-hub 4.3.76 → 4.3.79-alpha.0
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/middlewares/business-middleware.js +4 -1
- package/dist-server/middlewares/business-middleware.js.map +1 -1
- package/dist-server/middlewares/store-middleware.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js +3 -2
- package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-inbound-order.js +5 -2
- package/dist-server/routers/api/restful-apis/unstable/add-inbound-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +4 -2
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/company/add-contact-points.js +94 -0
- package/dist-server/routers/api/restful-apis/v1/company/add-contact-points.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/add-marketplace-order.js +208 -0
- package/dist-server/routers/api/restful-apis/v1/company/add-marketplace-order.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/add-product.js +65 -0
- package/dist-server/routers/api/restful-apis/v1/company/add-product.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/cancel-marketplace-order.js +97 -0
- package/dist-server/routers/api/restful-apis/v1/company/cancel-marketplace-order.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-bizplace-list.js +50 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-bizplace-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-contact-point-list.js +63 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-contact-point-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-marketplace-order-shipping-list.js +110 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-marketplace-order-shipping-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-marketplace-store-list.js +52 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-marketplace-store-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-partner-list.js +90 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-partner-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-product-list.js +99 -0
- package/dist-server/routers/api/restful-apis/v1/company/get-product-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/index.js +14 -0
- package/dist-server/routers/api/restful-apis/v1/company/index.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/company/update-marketplace-order-delivered.js +65 -0
- package/dist-server/routers/api/restful-apis/v1/company/update-marketplace-order-delivered.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/index.js +2 -31
- package/dist-server/routers/api/restful-apis/v1/index.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/middlewares/business-middleware.js +29 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/business-middleware.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/index.js +40 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/index.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/logging-middleware.js +23 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/logging-middleware.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/store-middleware.js +32 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/store-middleware.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/validation-middleware.js +53 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/validation-middleware.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/warehouse-middleware.js +31 -0
- package/dist-server/routers/api/restful-apis/v1/middlewares/warehouse-middleware.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/utils/error-util.js +71 -0
- package/dist-server/routers/api/restful-apis/v1/utils/error-util.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/utils/expected-parameters.js +201 -0
- package/dist-server/routers/api/restful-apis/v1/utils/expected-parameters.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/utils/params.js +293 -0
- package/dist-server/routers/api/restful-apis/v1/utils/params.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/utils/validate-util.js +90 -0
- package/dist-server/routers/api/restful-apis/v1/utils/validate-util.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-inbound-order.js +277 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-inbound-order.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js +810 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/cancel-inbound-order.js +116 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/cancel-inbound-order.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-delivery-order-list.js +140 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-delivery-order-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-goods-received-note-list.js +100 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-goods-received-note-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-inbound-order-details.js +78 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-inbound-order-details.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-inbound-order-list.js +96 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-inbound-order-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-inventory-product-group-list.js +244 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-inventory-product-group-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-onhand-inventory-list.js +96 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-onhand-inventory-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-details.js +94 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-details.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-list.js +112 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-list.js.map +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/index.js +13 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/index.js.map +1 -0
- package/package.json +54 -54
- package/server/middlewares/business-middleware.ts +5 -1
- package/server/middlewares/store-middleware.ts +1 -0
- package/server/routers/api/restful-apis/unstable/add-draft-release-order.ts +3 -2
- package/server/routers/api/restful-apis/unstable/add-inbound-order.ts +5 -2
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +4 -2
- package/server/routers/api/restful-apis/v1/company/add-contact-points.ts +94 -0
- package/server/routers/api/restful-apis/v1/company/add-marketplace-order.ts +242 -0
- package/server/routers/api/restful-apis/v1/company/add-product.ts +78 -0
- package/server/routers/api/restful-apis/v1/company/cancel-marketplace-order.ts +102 -0
- package/server/routers/api/restful-apis/v1/company/get-bizplace-list.ts +56 -0
- package/server/routers/api/restful-apis/v1/company/get-contact-point-list.ts +69 -0
- package/server/routers/api/restful-apis/v1/company/get-marketplace-order-shipping-list.ts +118 -0
- package/server/routers/api/restful-apis/v1/company/get-marketplace-store-list.ts +58 -0
- package/server/routers/api/restful-apis/v1/company/get-partner-list.ts +97 -0
- package/server/routers/api/restful-apis/v1/company/get-product-list.ts +105 -0
- package/server/routers/api/restful-apis/v1/company/index.ts +11 -0
- package/server/routers/api/restful-apis/v1/company/update-marketplace-order-delivered.ts +70 -0
- package/server/routers/api/restful-apis/v1/index.ts +2 -31
- package/server/routers/api/restful-apis/v1/middlewares/business-middleware.ts +31 -0
- package/server/routers/api/restful-apis/v1/middlewares/index.ts +26 -0
- package/server/routers/api/restful-apis/v1/middlewares/logging-middleware.ts +24 -0
- package/server/routers/api/restful-apis/v1/middlewares/store-middleware.ts +34 -0
- package/server/routers/api/restful-apis/v1/middlewares/validation-middleware.ts +50 -0
- package/server/routers/api/restful-apis/v1/middlewares/warehouse-middleware.ts +31 -0
- package/server/routers/api/restful-apis/v1/utils/error-util.ts +70 -0
- package/server/routers/api/restful-apis/v1/utils/expected-parameters.ts +199 -0
- package/server/routers/api/restful-apis/v1/utils/params.ts +291 -0
- package/server/routers/api/restful-apis/v1/utils/validate-util.ts +74 -0
- package/server/routers/api/restful-apis/v1/warehouse/add-inbound-order.ts +361 -0
- package/server/routers/api/restful-apis/v1/warehouse/add-release-order.ts +1000 -0
- package/server/routers/api/restful-apis/v1/warehouse/cancel-inbound-order.ts +139 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-delivery-order-list.ts +144 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-goods-received-note-list.ts +109 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-inbound-order-details.ts +74 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-inbound-order-list.ts +99 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-inventory-product-group-list.ts +295 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-onhand-inventory-list.ts +99 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-release-order-details.ts +97 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-release-order-list.ts +116 -0
- package/server/routers/api/restful-apis/v1/warehouse/index.ts +10 -0
- package/dist-server/routers/api/restful-apis/v1/bizplace.js +0 -45
- package/dist-server/routers/api/restful-apis/v1/bizplace.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-contact-point-list.js +0 -103
- package/dist-server/routers/api/restful-apis/v1/get-contact-point-list.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-delivery-order-detail.js +0 -47
- package/dist-server/routers/api/restful-apis/v1/get-delivery-order-detail.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-delivery-order-list.js +0 -124
- package/dist-server/routers/api/restful-apis/v1/get-delivery-order-list.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-delivery-orders.js +0 -164
- package/dist-server/routers/api/restful-apis/v1/get-delivery-orders.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-goods-received-notes.js +0 -120
- package/dist-server/routers/api/restful-apis/v1/get-goods-received-notes.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-inbound-order-detail.js +0 -115
- package/dist-server/routers/api/restful-apis/v1/get-inbound-order-detail.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-inbound-order-list.js +0 -125
- package/dist-server/routers/api/restful-apis/v1/get-inbound-order-list.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-inventory-overall-product-group.js +0 -88
- package/dist-server/routers/api/restful-apis/v1/get-inventory-overall-product-group.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-marketplace-store-list.js +0 -79
- package/dist-server/routers/api/restful-apis/v1/get-marketplace-store-list.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-onhand-inventories.js +0 -110
- package/dist-server/routers/api/restful-apis/v1/get-onhand-inventories.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-partners.js +0 -23
- package/dist-server/routers/api/restful-apis/v1/get-partners.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-products.js +0 -210
- package/dist-server/routers/api/restful-apis/v1/get-products.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-release-order-detail.js +0 -122
- package/dist-server/routers/api/restful-apis/v1/get-release-order-detail.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-release-order-list.js +0 -191
- package/dist-server/routers/api/restful-apis/v1/get-release-order-list.js.map +0 -1
- package/dist-server/routers/api/restful-apis/v1/get-warehouses.js +0 -20
- package/dist-server/routers/api/restful-apis/v1/get-warehouses.js.map +0 -1
- package/server/routers/api/restful-apis/v1/bizplace.ts +0 -45
- package/server/routers/api/restful-apis/v1/get-contact-point-list.ts +0 -110
- package/server/routers/api/restful-apis/v1/get-delivery-order-detail.ts +0 -46
- package/server/routers/api/restful-apis/v1/get-delivery-order-list.ts +0 -121
- package/server/routers/api/restful-apis/v1/get-delivery-orders.ts +0 -178
- package/server/routers/api/restful-apis/v1/get-goods-received-notes.ts +0 -134
- package/server/routers/api/restful-apis/v1/get-inbound-order-detail.ts +0 -128
- package/server/routers/api/restful-apis/v1/get-inbound-order-list.ts +0 -126
- package/server/routers/api/restful-apis/v1/get-inventory-overall-product-group.ts +0 -99
- package/server/routers/api/restful-apis/v1/get-marketplace-store-list.ts +0 -81
- package/server/routers/api/restful-apis/v1/get-onhand-inventories.ts +0 -125
- package/server/routers/api/restful-apis/v1/get-partners.ts +0 -24
- package/server/routers/api/restful-apis/v1/get-products.ts +0 -216
- package/server/routers/api/restful-apis/v1/get-release-order-detail.ts +0 -134
- package/server/routers/api/restful-apis/v1/get-release-order-list.ts +0 -198
- package/server/routers/api/restful-apis/v1/get-warehouses.ts +0 -18
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { restfulApiRouter as router } from '@things-factory/api'
|
|
4
|
+
import { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
5
|
+
|
|
6
|
+
import { ApiError, ApiErrorHandler, throwInternalServerError } from '../utils/error-util'
|
|
7
|
+
import { validateLimitOffset } from '../utils/validate-util'
|
|
8
|
+
import { businessMiddleware, validationMiddleware, loggingMiddleware } from '../middlewares'
|
|
9
|
+
|
|
10
|
+
router.get(
|
|
11
|
+
'/v1/company/get-marketplace-store-list',
|
|
12
|
+
businessMiddleware,
|
|
13
|
+
validationMiddleware,
|
|
14
|
+
loggingMiddleware,
|
|
15
|
+
async (context, next) => {
|
|
16
|
+
try {
|
|
17
|
+
const { limit, offset } = validateLimitOffset(context.query.limit, context.query.offset)
|
|
18
|
+
|
|
19
|
+
// get marketplace stores for that domain
|
|
20
|
+
const domainId = context.state.domain.id
|
|
21
|
+
const [marketplaceStores, totalCount]: MarketplaceStore[] = await getRepository(MarketplaceStore).findAndCount({
|
|
22
|
+
where: { domain: domainId },
|
|
23
|
+
skip: offset,
|
|
24
|
+
take: limit,
|
|
25
|
+
order: { createdAt: 'DESC' }
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// create and format data response
|
|
29
|
+
let data = []
|
|
30
|
+
for (const marketplaceStore of marketplaceStores) {
|
|
31
|
+
const datapoint = {
|
|
32
|
+
id: marketplaceStore.id,
|
|
33
|
+
name: marketplaceStore.name,
|
|
34
|
+
platform: marketplaceStore.platform,
|
|
35
|
+
eTrax: marketplaceStore.eTrax,
|
|
36
|
+
storeName: marketplaceStore.storeName,
|
|
37
|
+
storeUrl: marketplaceStore.storeUrl,
|
|
38
|
+
isAutoUpdateStockQty: marketplaceStore.isAutoUpdateStockQty,
|
|
39
|
+
isAutoUpdateShipment: marketplaceStore.isAutoUpdateShipment,
|
|
40
|
+
storeId: marketplaceStore.storeId,
|
|
41
|
+
countryCode: marketplaceStore.countryCode,
|
|
42
|
+
status: marketplaceStore.status
|
|
43
|
+
}
|
|
44
|
+
data.push(datapoint)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
context.body = {
|
|
48
|
+
data,
|
|
49
|
+
totalCount,
|
|
50
|
+
limit,
|
|
51
|
+
offset
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
55
|
+
else throwInternalServerError(context, e)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { restfulApiRouter as router } from '@things-factory/api'
|
|
4
|
+
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
+
import { Partner } from '@things-factory/auth-base'
|
|
6
|
+
|
|
7
|
+
import { ApiError, ApiErrorHandler, throwInternalServerError } from '../utils/error-util'
|
|
8
|
+
import { validateLimitOffset } from '../utils/validate-util'
|
|
9
|
+
import { businessMiddleware, validationMiddleware, loggingMiddleware } from '../middlewares'
|
|
10
|
+
|
|
11
|
+
router.get(
|
|
12
|
+
'/v1/company/get-partner-list',
|
|
13
|
+
businessMiddleware,
|
|
14
|
+
validationMiddleware,
|
|
15
|
+
loggingMiddleware,
|
|
16
|
+
async (context, next) => {
|
|
17
|
+
try {
|
|
18
|
+
const { limit, offset } = validateLimitOffset(context.query.limit, context.query.offset)
|
|
19
|
+
|
|
20
|
+
//validate bizplace belongs to company
|
|
21
|
+
const companyId = context.state.business.id
|
|
22
|
+
const { bizplaceId } = context.query
|
|
23
|
+
const bizplace: Bizplace = await getRepository(Bizplace).findOne({
|
|
24
|
+
where: { company: companyId, id: bizplaceId },
|
|
25
|
+
relations: ['domain']
|
|
26
|
+
})
|
|
27
|
+
if (!bizplace) throw new ApiError('E01', 'bizplaceId')
|
|
28
|
+
|
|
29
|
+
const partners: Partner[] = await getRepository(Partner)
|
|
30
|
+
.createQueryBuilder('p')
|
|
31
|
+
.innerJoinAndSelect('bizplaces', 'bpp', 'bpp.domain_id = p.partner_domain_id')
|
|
32
|
+
.innerJoinAndSelect('bizplaces', 'bpo', 'bpo.domain_id = p.domain_id')
|
|
33
|
+
.innerJoinAndSelect('domains', 'dp', 'bpp.domain_id = dp.id')
|
|
34
|
+
.innerJoinAndSelect('domains', 'do', 'bpo.domain_id = do.id')
|
|
35
|
+
.where('p.partner_domain_id = :domainId', { domainId: bizplace.domain.id })
|
|
36
|
+
.orWhere('p.domain_id = :domainId', { domainId: bizplace.domain.id })
|
|
37
|
+
.limit(limit)
|
|
38
|
+
.offset(offset)
|
|
39
|
+
.orderBy('p.created_at', 'DESC')
|
|
40
|
+
.getRawMany()
|
|
41
|
+
|
|
42
|
+
const count = await getRepository(Partner)
|
|
43
|
+
.createQueryBuilder('p')
|
|
44
|
+
.select('COUNT(p.id)')
|
|
45
|
+
.innerJoin('bizplaces', 'bpp', 'bpp.domain_id = p.partner_domain_id')
|
|
46
|
+
.innerJoin('bizplaces', 'bpo', 'bpo.domain_id = p.domain_id')
|
|
47
|
+
.innerJoin('domains', 'dp', 'bpp.domain_id = dp.id')
|
|
48
|
+
.innerJoin('domains', 'do', 'bpo.domain_id = do.id')
|
|
49
|
+
.where('p.partner_domain_id = :domainId', { domainId: bizplace.domain.id })
|
|
50
|
+
.orWhere('p.domain_id = :domainId', { domainId: bizplace.domain.id })
|
|
51
|
+
.getRawOne()
|
|
52
|
+
|
|
53
|
+
const totalCount = parseInt(count.count)
|
|
54
|
+
|
|
55
|
+
let data = []
|
|
56
|
+
for (const partner of partners) {
|
|
57
|
+
let datapoint = {}
|
|
58
|
+
if (partner.bpo_id === bizplaceId) {
|
|
59
|
+
datapoint = {
|
|
60
|
+
bizplace: {
|
|
61
|
+
id: partner.bpp_id,
|
|
62
|
+
name: partner.bpp_name,
|
|
63
|
+
description: partner.bpp_description,
|
|
64
|
+
address: partner.bpp_address,
|
|
65
|
+
postalCode: partner.bpp_postal_code
|
|
66
|
+
},
|
|
67
|
+
partnershipOwner: false,
|
|
68
|
+
extType: partner.dp_ext_type
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
datapoint = {
|
|
72
|
+
bizplace: {
|
|
73
|
+
id: partner.bpo_id,
|
|
74
|
+
name: partner.bpo_name,
|
|
75
|
+
description: partner.bpo_description,
|
|
76
|
+
address: partner.bpo_address,
|
|
77
|
+
postalCode: partner.bpo_postal_code
|
|
78
|
+
},
|
|
79
|
+
partnershipOwner: true,
|
|
80
|
+
extType: partner.do_ext_type
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
data.push(datapoint)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
context.body = {
|
|
87
|
+
data,
|
|
88
|
+
totalCount,
|
|
89
|
+
limit,
|
|
90
|
+
offset
|
|
91
|
+
}
|
|
92
|
+
} catch (e) {
|
|
93
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
94
|
+
else throwInternalServerError(context, e)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { restfulApiRouter as router } from '@things-factory/api'
|
|
4
|
+
import { Product } from '@things-factory/product-base'
|
|
5
|
+
|
|
6
|
+
import { ApiError, ApiErrorHandler, throwInternalServerError } from '../utils/error-util'
|
|
7
|
+
import { validateLimitOffset } from '../utils/validate-util'
|
|
8
|
+
import { businessMiddleware, validationMiddleware, loggingMiddleware } from '../middlewares'
|
|
9
|
+
|
|
10
|
+
router.get(
|
|
11
|
+
'/v1/company/get-product-list',
|
|
12
|
+
businessMiddleware,
|
|
13
|
+
validationMiddleware,
|
|
14
|
+
loggingMiddleware,
|
|
15
|
+
async (context, next) => {
|
|
16
|
+
try {
|
|
17
|
+
const { limit, offset } = validateLimitOffset(context.query.limit, context.query.offset)
|
|
18
|
+
|
|
19
|
+
// get productDetails for that bizplace/domain
|
|
20
|
+
// optional query parameter filter
|
|
21
|
+
let filter = { ...context.query }
|
|
22
|
+
// map query field to database column
|
|
23
|
+
filter['bizplace'] = filter['bizplaceId']
|
|
24
|
+
delete filter['bizplaceId']
|
|
25
|
+
delete filter['limit']
|
|
26
|
+
delete filter['offset']
|
|
27
|
+
const [products, totalCount]: Product[] = await getRepository(Product).findAndCount({
|
|
28
|
+
where: filter,
|
|
29
|
+
relations: ['productDetails'],
|
|
30
|
+
skip: offset,
|
|
31
|
+
take: limit,
|
|
32
|
+
order: { createdAt: 'DESC' }
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// create and format data response
|
|
36
|
+
let data = []
|
|
37
|
+
for (const product of products) {
|
|
38
|
+
let productDetails = []
|
|
39
|
+
for (const productDetail of product.productDetails) {
|
|
40
|
+
const productDetailDataPoint = {
|
|
41
|
+
isDefault: productDetail.isDefault,
|
|
42
|
+
gtin: productDetail.gtin,
|
|
43
|
+
refCode: productDetail.refCode,
|
|
44
|
+
packingType: productDetail.packingType,
|
|
45
|
+
packingSize: productDetail.packingSize,
|
|
46
|
+
uom: productDetail.uom,
|
|
47
|
+
uomValue: productDetail.uomValue,
|
|
48
|
+
costPrice: productDetail.costPrice,
|
|
49
|
+
minQty: productDetail.minQty,
|
|
50
|
+
maxQty: productDetail.maxQty,
|
|
51
|
+
bufferQty: productDetail.bufferQty,
|
|
52
|
+
movement: productDetail.movement,
|
|
53
|
+
weightUnit: productDetail.weightUnit,
|
|
54
|
+
nettWeight: productDetail.nettWeight,
|
|
55
|
+
grossWeight: productDetail.grossWeight,
|
|
56
|
+
lengthUnit: productDetail.lengthUnit,
|
|
57
|
+
width: productDetail.width,
|
|
58
|
+
depth: productDetail.depth,
|
|
59
|
+
height: productDetail.height,
|
|
60
|
+
volume: productDetail.volume,
|
|
61
|
+
auxUnit1: productDetail.auxUnit1,
|
|
62
|
+
auxValue1: productDetail.auxValue1,
|
|
63
|
+
auxUnit2: productDetail.auxUnit2,
|
|
64
|
+
auxValue2: productDetail.auxValue2,
|
|
65
|
+
auxUnit3: productDetail.auxUnit3,
|
|
66
|
+
auxValue3: productDetail.auxValue3,
|
|
67
|
+
auxUnit4: productDetail.auxUnit4,
|
|
68
|
+
auxValue4: productDetail.auxValue4,
|
|
69
|
+
auxUnit5: productDetail.auxUnit5,
|
|
70
|
+
auxValue5: productDetail.auxValue5,
|
|
71
|
+
childProductDetail: productDetail.childProductDetail
|
|
72
|
+
}
|
|
73
|
+
productDetails.push(productDetailDataPoint)
|
|
74
|
+
}
|
|
75
|
+
const datapoint = {
|
|
76
|
+
sku: product.sku,
|
|
77
|
+
brandSku: product.brandSku,
|
|
78
|
+
name: product.name,
|
|
79
|
+
description: product.description,
|
|
80
|
+
type: product.type,
|
|
81
|
+
brand: product.brand,
|
|
82
|
+
subBrand: product.subBrand,
|
|
83
|
+
isRequiredCheckExpiry: product.isRequiredCheckExpiry,
|
|
84
|
+
isRequireSerialNumberScanning: product.isRequireSerialNumberScanning,
|
|
85
|
+
isRequireSerialNumberScanningInbound: product.isRequireSerialNumberScanningInbound,
|
|
86
|
+
isRequireSerialNumberScanningOutbound: product.isRequireSerialNumberScanningOutbound,
|
|
87
|
+
pickingStrategy: product.pickingStrategy,
|
|
88
|
+
expirationPeriod: product.expirationPeriod,
|
|
89
|
+
productDetails
|
|
90
|
+
}
|
|
91
|
+
data.push(datapoint)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
context.body = {
|
|
95
|
+
data,
|
|
96
|
+
totalCount,
|
|
97
|
+
limit,
|
|
98
|
+
offset
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
102
|
+
else throwInternalServerError(context, e)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './add-contact-points'
|
|
2
|
+
import './add-marketplace-order'
|
|
3
|
+
import './add-product'
|
|
4
|
+
import './cancel-marketplace-order'
|
|
5
|
+
import './get-bizplace-list'
|
|
6
|
+
import './get-contact-point-list'
|
|
7
|
+
import './get-marketplace-order-shipping-list'
|
|
8
|
+
import './get-marketplace-store-list'
|
|
9
|
+
import './get-partner-list'
|
|
10
|
+
import './get-product-list'
|
|
11
|
+
import './update-marketplace-order-delivered'
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { restfulApiRouter as router } from '@things-factory/api'
|
|
4
|
+
import { MarketplaceOrder } from '@things-factory/marketplace-base'
|
|
5
|
+
import { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
6
|
+
|
|
7
|
+
import { businessMiddleware } from '../middlewares/business-middleware'
|
|
8
|
+
import { ApiError, ApiErrorHandler, throwInternalServerError } from '../utils/error-util'
|
|
9
|
+
import { expectedParams, reqParams } from '../utils/expected-parameters'
|
|
10
|
+
import { validateFilter, validateReqParams } from '../utils/validate-util'
|
|
11
|
+
import { loggingMiddleware } from '../middlewares/logging-middleware'
|
|
12
|
+
|
|
13
|
+
router.post(
|
|
14
|
+
'/v1/company/update-marketplace-order-delivered',
|
|
15
|
+
businessMiddleware,
|
|
16
|
+
loggingMiddleware,
|
|
17
|
+
async (context, next) => {
|
|
18
|
+
try {
|
|
19
|
+
validateReqParams(context.request.body, reqParams.requireDataKey)
|
|
20
|
+
validateFilter(context.request.body, expectedParams.requireDataKey)
|
|
21
|
+
validateReqParams(context.request.body.data, reqParams.cancelMarketplaceOrder)
|
|
22
|
+
validateFilter(context.request.body.data, expectedParams.cancelMarketplaceOrder)
|
|
23
|
+
|
|
24
|
+
// check if name exists under the domain of the requester
|
|
25
|
+
const marketplaceStore: MarketplaceStore = await getRepository(MarketplaceStore).findOne({
|
|
26
|
+
where: { name: context.request.body.data.storeId, domain: context.state.business.domain }
|
|
27
|
+
})
|
|
28
|
+
if (!marketplaceStore) throw new ApiError('E01', 'storeId does not exist')
|
|
29
|
+
|
|
30
|
+
// update values to DB
|
|
31
|
+
// restricted to marketplaceStores in the domain of the requester
|
|
32
|
+
const datapoint = context.request.body.data
|
|
33
|
+
const result = await getRepository(MarketplaceOrder)
|
|
34
|
+
.createQueryBuilder()
|
|
35
|
+
.update(MarketplaceOrder)
|
|
36
|
+
.set({ status: 'delivered' })
|
|
37
|
+
.where({ orderNo: datapoint.orderNo, marketplaceStore })
|
|
38
|
+
.execute()
|
|
39
|
+
if (result.affected !== 1) throw new ApiError('E01', 'orderNo is invalid')
|
|
40
|
+
|
|
41
|
+
const marketplaceOrder: MarketplaceOrder = await getRepository(MarketplaceOrder).findOne({
|
|
42
|
+
where: { orderNo: datapoint.orderNo, marketplaceStore },
|
|
43
|
+
relations: ['domain', 'marketplaceStore', 'updater']
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// create and format response
|
|
47
|
+
const data = {
|
|
48
|
+
orderNo: marketplaceOrder.orderNo,
|
|
49
|
+
status: marketplaceOrder.status,
|
|
50
|
+
updatedAt: marketplaceOrder.updatedAt,
|
|
51
|
+
domain: {
|
|
52
|
+
name: marketplaceOrder.domain.name
|
|
53
|
+
},
|
|
54
|
+
marketplaceStore: {
|
|
55
|
+
name: marketplaceOrder.marketplaceStore.storeName
|
|
56
|
+
},
|
|
57
|
+
updater: {
|
|
58
|
+
name: marketplaceOrder.updater.name
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
context.body = {
|
|
63
|
+
data
|
|
64
|
+
}
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
67
|
+
else throwInternalServerError(context, e)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
)
|
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './
|
|
3
|
-
import './add-marketplace-order'
|
|
4
|
-
import './add-products'
|
|
5
|
-
import './add-draft-release-order'
|
|
6
|
-
import './add-release-order'
|
|
7
|
-
import './bizplace'
|
|
8
|
-
import './reject-inbound-order'
|
|
9
|
-
import './get-contact-point-list'
|
|
10
|
-
import './get-delivery-order-detail'
|
|
11
|
-
import './get-delivery-order-list'
|
|
12
|
-
import './get-inbound-order-detail'
|
|
13
|
-
import './get-inbound-order-list'
|
|
14
|
-
import './get-inventory-product-group'
|
|
15
|
-
import './get-inventory-overall-product-group'
|
|
16
|
-
import './get-onhand-inventories'
|
|
17
|
-
import './get-products'
|
|
18
|
-
import './get-release-order-detail'
|
|
19
|
-
import './get-marketplace-store-list'
|
|
20
|
-
import './get-marketplace-order-shipping-list'
|
|
21
|
-
import './get-release-order-list'
|
|
22
|
-
import './get-warehouses'
|
|
23
|
-
import './cancel-marketplace-order'
|
|
24
|
-
import './cancel-release-order'
|
|
25
|
-
import './set-marketplace-order-delivered'
|
|
26
|
-
import './set-marketplace-order-failed-delivery'
|
|
27
|
-
import './update-marketplace-shipping-order'
|
|
28
|
-
import './update-marketplace-order'
|
|
29
|
-
import './update-release-order-details'
|
|
30
|
-
import './get-goods-received-notes'
|
|
31
|
-
import './get-delivery-orders'
|
|
1
|
+
import './company'
|
|
2
|
+
import './warehouse'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { Bizplace, Company } from '@things-factory/biz-base'
|
|
4
|
+
import { Domain, getDomainFromURL } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
const debug = require('debug')('things-factory:operato-hub:business-middleware')
|
|
7
|
+
|
|
8
|
+
export async function businessMiddleware(context, next) {
|
|
9
|
+
const { user } = context.state
|
|
10
|
+
|
|
11
|
+
debug('user', user?.email)
|
|
12
|
+
|
|
13
|
+
if (user) {
|
|
14
|
+
const domain: Domain = await getDomainFromURL(context)
|
|
15
|
+
|
|
16
|
+
let company: Company
|
|
17
|
+
if (domain.extType === 'company') {
|
|
18
|
+
company = await getRepository(Company).findOne({ where: { domain }, relations: ['domain'] })
|
|
19
|
+
} else {
|
|
20
|
+
const bizplace: Bizplace = await getRepository(Bizplace).findOne({
|
|
21
|
+
where: { domain },
|
|
22
|
+
relations: ['company', 'domain']
|
|
23
|
+
})
|
|
24
|
+
company = bizplace.company
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
context.state.business = company
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
await next()
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { businessMiddleware } from './business-middleware'
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('things-factory:operato-hub:index')
|
|
4
|
+
|
|
5
|
+
export function initMiddlewares(app) {
|
|
6
|
+
/*
|
|
7
|
+
* post:graphql 에 대해서는 businessMiddleware를 적용한다.
|
|
8
|
+
* graphql app을 router에 적용하지 못하기 때문임.
|
|
9
|
+
*/
|
|
10
|
+
app.use(async (context, next) => {
|
|
11
|
+
const { method, path } = context
|
|
12
|
+
|
|
13
|
+
if (method == 'POST' && path.startsWith('/graphql')) {
|
|
14
|
+
debug(method, path)
|
|
15
|
+
return await businessMiddleware(context, next)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
await next()
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export * from './business-middleware'
|
|
23
|
+
export * from './logging-middleware'
|
|
24
|
+
export * from './store-middleware'
|
|
25
|
+
export * from './warehouse-middleware'
|
|
26
|
+
export * from './validation-middleware'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createPayloadLog, PayloadType } from '@things-factory/integration-base'
|
|
2
|
+
|
|
3
|
+
// inserts payload log after successful endpoint request
|
|
4
|
+
export async function loggingMiddleware(context, next) {
|
|
5
|
+
// wait for endpoint logic to complete
|
|
6
|
+
await next()
|
|
7
|
+
|
|
8
|
+
// name of requester's domain
|
|
9
|
+
const name = context.state.domain.name
|
|
10
|
+
|
|
11
|
+
// endpoint that was queried
|
|
12
|
+
const endpoint = context.req._parsedUrl.pathname
|
|
13
|
+
|
|
14
|
+
// request body and query
|
|
15
|
+
const request = {
|
|
16
|
+
query: context.query,
|
|
17
|
+
requestBody: context.request.body
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// response
|
|
21
|
+
const response = context.body
|
|
22
|
+
|
|
23
|
+
await createPayloadLog(name, endpoint, request, response, context, PayloadType.INGESTION)
|
|
24
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { ApiError } from '../utils/error-util'
|
|
4
|
+
|
|
5
|
+
import { MarketplaceStore as MarketplaceStoreEntity } from '@things-factory/integration-marketplace'
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')('things-factory:operato-hub:store-middleware')
|
|
8
|
+
|
|
9
|
+
export async function storeMiddleware(context, next) {
|
|
10
|
+
const { storeId } = context.query
|
|
11
|
+
const { business } = context.state
|
|
12
|
+
|
|
13
|
+
let marketplaceStore: MarketplaceStoreEntity
|
|
14
|
+
|
|
15
|
+
debug('company and store', business, storeId)
|
|
16
|
+
|
|
17
|
+
if (!business) throw new ApiError('E04', 'Company')
|
|
18
|
+
|
|
19
|
+
if (storeId) {
|
|
20
|
+
marketplaceStore = await getRepository(MarketplaceStoreEntity).findOne({
|
|
21
|
+
where: { domain: business.domain, name: storeId, status: 'ACTIVE' },
|
|
22
|
+
relations: ['domain']
|
|
23
|
+
})
|
|
24
|
+
debug('marketplace-store', storeId, marketplaceStore?.domain?.subdomain)
|
|
25
|
+
|
|
26
|
+
if (!marketplaceStore) throw new ApiError('E04', 'Operato Marketplace Store')
|
|
27
|
+
} else {
|
|
28
|
+
throw new ApiError('E04', 'storeId')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
context.state.marketplaceStore = marketplaceStore
|
|
32
|
+
|
|
33
|
+
await next()
|
|
34
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ApiError, ApiErrorHandler, throwInternalServerError } from '../utils/error-util'
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('things-factory:operato-hub:validation-middleware')
|
|
4
|
+
|
|
5
|
+
import { params, reqParams } from '../utils/params'
|
|
6
|
+
|
|
7
|
+
export async function validationMiddleware(context, next) {
|
|
8
|
+
let path = context.req._parsedUrl.pathname
|
|
9
|
+
let endpoint = path.substring(path.lastIndexOf('/') + 1)
|
|
10
|
+
|
|
11
|
+
// validate data key
|
|
12
|
+
try {
|
|
13
|
+
validateExpected(endpoint, context)
|
|
14
|
+
validateRequired(endpoint, context)
|
|
15
|
+
await next()
|
|
16
|
+
} catch (e) {
|
|
17
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
18
|
+
else throwInternalServerError(context, e)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function validateExpected(endpoint, context) {
|
|
23
|
+
let data = context.method == 'POST' ? context.request.body.data : context.request.query
|
|
24
|
+
let expected = params[endpoint]
|
|
25
|
+
let result = context.method == 'POST' ? Object.keys(flatten(data)) : Object.keys(data)
|
|
26
|
+
for (let r of result) {
|
|
27
|
+
if (!expected.includes(r)) throw new ApiError('E02', r.toString())
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function validateRequired(endpoint, context) {
|
|
32
|
+
let data = context.method == 'POST' ? context.request.body.data : context.request.query
|
|
33
|
+
let required = reqParams[endpoint]
|
|
34
|
+
let result = context.method == 'POST' ? Object.keys(flatten(data)) : Object.keys(data)
|
|
35
|
+
for (let r of required) {
|
|
36
|
+
let v = r.split('.').slice(0, -1).join('.')
|
|
37
|
+
if (!required.includes(v) && !result.includes(v)) continue
|
|
38
|
+
if (!result.includes(r)) throw new ApiError('E03', r.toString())
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const flatten = (obj, path = '') => {
|
|
43
|
+
if (!(obj instanceof Object)) return { [path.replace(/\.$/g, '')]: obj }
|
|
44
|
+
|
|
45
|
+
return Object.keys(obj).reduce((output, key) => {
|
|
46
|
+
return obj instanceof Array
|
|
47
|
+
? { ...output, ...flatten(obj[key], path) }
|
|
48
|
+
: { ...output, ...flatten(obj[key], path + key + '.') }
|
|
49
|
+
}, {})
|
|
50
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
import { Bizplace } from '@things-factory/biz-base'
|
|
3
|
+
import { ApiError } from '../utils/error-util'
|
|
4
|
+
|
|
5
|
+
const debug = require('debug')('things-factory:operato-hub:warehouse-middleware')
|
|
6
|
+
|
|
7
|
+
export async function warehouseMiddleware(context, next) {
|
|
8
|
+
const { warehouseId } = context.query
|
|
9
|
+
const { business } = context.state
|
|
10
|
+
|
|
11
|
+
let warehouse: Bizplace
|
|
12
|
+
|
|
13
|
+
debug('company and warehouse', business, warehouseId)
|
|
14
|
+
|
|
15
|
+
if (!business) throw new ApiError('E04', 'Company')
|
|
16
|
+
|
|
17
|
+
if (warehouseId) {
|
|
18
|
+
warehouse = await getRepository(Bizplace).findOne(warehouseId, {
|
|
19
|
+
relations: ['company', 'domain']
|
|
20
|
+
})
|
|
21
|
+
debug('warehouse', warehouseId, warehouse?.domain?.subdomain)
|
|
22
|
+
|
|
23
|
+
if (!warehouse) throw new ApiError('E04', 'Warehouse')
|
|
24
|
+
} else {
|
|
25
|
+
throw new ApiError('E04', 'Warehouse')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
context.state.warehouse = warehouse
|
|
29
|
+
|
|
30
|
+
await next()
|
|
31
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// custom error class used when throwing errors for API V1
|
|
2
|
+
export class ApiError extends Error {
|
|
3
|
+
responseCode: string
|
|
4
|
+
status: number
|
|
5
|
+
message: string
|
|
6
|
+
details: string
|
|
7
|
+
constructor(responseCode: string, message: string, ...params) {
|
|
8
|
+
super(...params)
|
|
9
|
+
this.responseCode = responseCode
|
|
10
|
+
this.name = 'ApiError'
|
|
11
|
+
switch (responseCode) {
|
|
12
|
+
case 'E01':
|
|
13
|
+
this.status = 400
|
|
14
|
+
this.message = 'Invalid parameter values'
|
|
15
|
+
this.details = message
|
|
16
|
+
break
|
|
17
|
+
case 'E02':
|
|
18
|
+
this.status = 400
|
|
19
|
+
this.message = 'Unexpected parameters'
|
|
20
|
+
this.details = message
|
|
21
|
+
break
|
|
22
|
+
case 'E03':
|
|
23
|
+
this.status = 400
|
|
24
|
+
this.message = 'Missing parameters'
|
|
25
|
+
this.details = message
|
|
26
|
+
break
|
|
27
|
+
case 'E04':
|
|
28
|
+
this.status = 404
|
|
29
|
+
this.message = 'Resource not found'
|
|
30
|
+
this.details = message
|
|
31
|
+
break
|
|
32
|
+
case 'E05':
|
|
33
|
+
this.status = 409
|
|
34
|
+
this.message = 'Duplicate entry'
|
|
35
|
+
this.details = message
|
|
36
|
+
break
|
|
37
|
+
case 'E06':
|
|
38
|
+
this.status = 500
|
|
39
|
+
this.message = 'Internal server error'
|
|
40
|
+
this.details = message
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// used in catch block to give an error response
|
|
47
|
+
export function ApiErrorHandler(context, e) {
|
|
48
|
+
context.type = 'application/json'
|
|
49
|
+
context.status = e.status
|
|
50
|
+
context.body = {
|
|
51
|
+
error: {
|
|
52
|
+
responseCode: e.responseCode,
|
|
53
|
+
message: e.message,
|
|
54
|
+
details: e.details
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// used in catch block for all errors that are not ApiError
|
|
60
|
+
export function throwInternalServerError(context, e) {
|
|
61
|
+
context.type = 'application/json'
|
|
62
|
+
context.status = 500
|
|
63
|
+
context.body = {
|
|
64
|
+
error: {
|
|
65
|
+
responseCode: 'E06',
|
|
66
|
+
message: 'Internal Server Error',
|
|
67
|
+
details: e.message
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|