This commit is contained in:
2026-08-15 11:19:13 +08:00
parent 9cc24436d9
commit 16a271f7e0
4 changed files with 14 additions and 12 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import { apiRequest } from '@/api/http'
export type MerchantPartnerType = 'CUSTOMER' | 'SUPPLIER' | 'CARRIER' | 'CUSTOMS_BROKER' | 'SHIPPER' | 'CONSIGNEE'
export type MerchantPartnerType = 'SHIPPER' | 'CONSIGNEE'
export interface MerchantPartner {
id: number | string
@@ -6,23 +6,25 @@ const source = readFileSync(new URL('./firstLegPartySource.ts', import.meta.url)
const viewSource = readFileSync(new URL('../views/FirstLegOrdersView.vue', import.meta.url), 'utf8')
const apiSource = readFileSync(new URL('../api/partners.ts', import.meta.url), 'utf8')
test('keeps the legacy counterparty source available without coupling it to first-leg ordering', () => {
test('only exposes shipper and consignee partners as first-leg order candidates', () => {
assert.match(source, /export interface FirstLegPartySource/)
assert.match(source, /listAvailable\(role/)
assert.match(source, /findAvailable\(id, role/)
assert.match(source, /async load\(\)/)
assert.match(source, /party\.status === 'ACTIVE' && party\.roles\.includes\(role\)/)
assert.match(source, /getMerchantPartnerCandidates/)
assert.match(source, /partner\.types\?\.length/)
assert.match(source, /ORDER_PARTNER_ROLES: readonly FirstLegPartyRole\[\] = \['SHIPPER', 'CONSIGNEE'\]/)
assert.match(source, /partner\.types\?\.includes\(role\)/)
assert.match(source, /: \['SHIPPER', 'CONSIGNEE'\]/)
assert.match(source, /\.filter\(\(party\) => party\.roles\.length > 0\)/)
assert.doesNotMatch(source, /: \['SHIPPER', 'CONSIGNEE'\]/)
assert.match(source, /await getMerchantPartnerCandidates\(\)/)
assert.doesNotMatch(source, /getMerchantPartnerCandidates\('SENDER'\)|getMerchantPartnerCandidates\('RECEIVER'\)/)
assert.doesNotMatch(viewSource, /firstLegPartySource/)
assert.doesNotMatch(viewSource, /发货单位|收货单位/)
assert.doesNotMatch(viewSource, /DEMO_FIRST_LEG_PARTIES/)
assert.match(apiSource, /url: '\/merchant\/v1\/partners\/candidates'/)
assert.match(apiSource, /'CARRIER' \| 'CUSTOMS_BROKER' \| 'SHIPPER' \| 'CONSIGNEE'/)
assert.match(apiSource, /export type MerchantPartnerType = 'SHIPPER' \| 'CONSIGNEE'/)
assert.doesNotMatch(apiSource, /'CUSTOMER'|'SUPPLIER'|'CARRIER'|'CUSTOMS_BROKER'/)
assert.match(apiSource, /types\?: MerchantPartnerType\[\]/)
assert.match(apiSource, /url: `\/merchant\/v1\/partners\/\$\{id\}`/)
})
@@ -12,16 +12,14 @@ function isAvailableForRole(party: FirstLegParty, role: FirstLegPartyRole) {
}
const parties: FirstLegParty[] = []
const ORDER_PARTNER_ROLES: readonly FirstLegPartyRole[] = ['SHIPPER', 'CONSIGNEE']
function mapPartner(partner: MerchantPartner): FirstLegParty {
const roles: FirstLegPartyRole[] = partner.types?.length
? (['SHIPPER', 'CONSIGNEE'] as FirstLegPartyRole[]).filter((role) => partner.types?.includes(role))
: ['SHIPPER', 'CONSIGNEE']
const roles = ORDER_PARTNER_ROLES.filter((role) => partner.types?.includes(role))
return {
id: String(partner.id),
code: partner.partnerCode,
name: partner.partnerName,
// 新契约按稳定类型限制订单角色;旧响应无 types 时保持原有兼容行为。
roles,
contactName: partner.contactName ?? '',
phone: partner.contactPhone ?? '',
@@ -44,6 +42,10 @@ export const firstLegPartySource: FirstLegPartySource = {
},
async load() {
parties.splice(0, parties.length)
parties.push(...(await getMerchantPartnerCandidates()).map(mapPartner))
parties.push(
...(await getMerchantPartnerCandidates())
.map(mapPartner)
.filter((party) => party.roles.length > 0),
)
},
}