把 task 的 helper独立出来了
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import { Router } from 'express'
|
||||
|
||||
import {
|
||||
@@ -9,6 +11,11 @@ import {
|
||||
} from '../../services/admin/admin-platform-config-service.js'
|
||||
import { createJsonHandler, requireAdminRoles } from './shared.js'
|
||||
|
||||
/** @typedef {import('../../types/admin-route-inputs.js').AdminAgisoShopConfigRouteBody} AdminAgisoShopConfigRouteBody */
|
||||
/** @typedef {import('../../types/admin-route-inputs.js').AdminFulfillmentBindingConfigRouteBody} AdminFulfillmentBindingConfigRouteBody */
|
||||
/** @typedef {import('../../types/admin-route-inputs.js').AdminFulfillmentBindingLookupRouteBody} AdminFulfillmentBindingLookupRouteBody */
|
||||
/** @typedef {import('../../types/admin-write-models.js').AdminAgisoShopConfigSaveResponse} AdminAgisoShopConfigSaveResponse */
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.use('/platform-config', requireAdminRoles(['admin']))
|
||||
@@ -23,20 +30,23 @@ router.get('/platform-config/agiso-shops', createJsonHandler(
|
||||
))
|
||||
|
||||
router.post('/platform-config/agiso-shops', createJsonHandler(
|
||||
(req) => updateAdminAgisoShopConfigs(req.body),
|
||||
(req) => updateAdminAgisoShopConfigs(/** @type {AdminAgisoShopConfigRouteBody} */ (req.body)),
|
||||
{
|
||||
successMessage: 'Agiso 店铺配置已保存',
|
||||
errorMessage: '保存 Agiso 店铺配置失败',
|
||||
scope: '[admin/platform-config/agiso-shops]',
|
||||
audit: (_req, data) => ({
|
||||
action: 'platform_shop_config_updated',
|
||||
targetType: 'platform_config',
|
||||
targetId: 'agiso_shops',
|
||||
data: {
|
||||
shopCount: data.shops.length,
|
||||
filePath: data.filePath,
|
||||
},
|
||||
}),
|
||||
audit: (_req, data) => {
|
||||
const result = /** @type {AdminAgisoShopConfigSaveResponse} */ (data)
|
||||
return {
|
||||
action: 'platform_shop_config_updated',
|
||||
targetType: 'platform_config',
|
||||
targetId: 'agiso_shops',
|
||||
data: {
|
||||
shopCount: result.shops.length,
|
||||
filePath: result.filePath,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
))
|
||||
|
||||
@@ -50,44 +60,50 @@ router.get('/platform-config/fulfillment-bindings', createJsonHandler(
|
||||
))
|
||||
|
||||
router.post('/platform-config/fulfillment-bindings/lookup-order', createJsonHandler(
|
||||
(req) => lookupAdminFulfillmentBindingOrder(req.body),
|
||||
(req) => lookupAdminFulfillmentBindingOrder(/** @type {AdminFulfillmentBindingLookupRouteBody} */ (req.body)),
|
||||
{
|
||||
successMessage: '订单商品查询成功',
|
||||
errorMessage: '手动查询订单商品失败',
|
||||
scope: '[admin/platform-config/fulfillment-bindings/lookup-order]',
|
||||
audit: (req, data) => ({
|
||||
action: 'platform_fulfillment_order_lookup',
|
||||
targetType: 'platform_config',
|
||||
targetId: [
|
||||
data.order?.provider || 'unknown',
|
||||
data.order?.platform || 'unknown',
|
||||
data.order?.shopId || 'unknown',
|
||||
data.order?.platformOrderId || 'unknown',
|
||||
].join(':'),
|
||||
data: {
|
||||
itemCount: Array.isArray(data.items) ? data.items.length : 0,
|
||||
shopId: data.order?.shopId || String(req.body?.shopId || '').trim(),
|
||||
platformOrderId: data.order?.platformOrderId || String(req.body?.platformOrderId || '').trim(),
|
||||
},
|
||||
}),
|
||||
audit: (req, data) => {
|
||||
const result = /** @type {{ order?: { provider?: string, platform?: string, shopId?: string, platformOrderId?: string }, items?: unknown[] }} */ (data)
|
||||
return {
|
||||
action: 'platform_fulfillment_order_lookup',
|
||||
targetType: 'platform_config',
|
||||
targetId: [
|
||||
result.order?.provider || 'unknown',
|
||||
result.order?.platform || 'unknown',
|
||||
result.order?.shopId || 'unknown',
|
||||
result.order?.platformOrderId || 'unknown',
|
||||
].join(':'),
|
||||
data: {
|
||||
itemCount: Array.isArray(result.items) ? result.items.length : 0,
|
||||
shopId: result.order?.shopId || String((/** @type {AdminFulfillmentBindingLookupRouteBody} */ (req.body))?.shopId || '').trim(),
|
||||
platformOrderId: result.order?.platformOrderId || String((/** @type {AdminFulfillmentBindingLookupRouteBody} */ (req.body))?.platformOrderId || '').trim(),
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
))
|
||||
|
||||
router.post('/platform-config/fulfillment-bindings', createJsonHandler(
|
||||
(req) => updateAdminFulfillmentBindingConfigs(req.body),
|
||||
(req) => updateAdminFulfillmentBindingConfigs(/** @type {AdminFulfillmentBindingConfigRouteBody} */ (req.body)),
|
||||
{
|
||||
successMessage: '履约配置已保存',
|
||||
errorMessage: '保存履约配置失败',
|
||||
scope: '[admin/platform-config/fulfillment-bindings]',
|
||||
audit: (_req, data) => ({
|
||||
action: 'platform_fulfillment_config_updated',
|
||||
targetType: 'platform_config',
|
||||
targetId: 'fulfillment_bindings',
|
||||
data: {
|
||||
bindingCount: data.bindings.length,
|
||||
filePath: data.filePath,
|
||||
},
|
||||
}),
|
||||
audit: (_req, data) => {
|
||||
const result = /** @type {{ bindings?: unknown[], filePath?: string }} */ (data)
|
||||
return {
|
||||
action: 'platform_fulfillment_config_updated',
|
||||
targetType: 'platform_config',
|
||||
targetId: 'fulfillment_bindings',
|
||||
data: {
|
||||
bindingCount: Array.isArray(result.bindings) ? result.bindings.length : 0,
|
||||
filePath: result.filePath || '',
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user