345d5db9c9
Extend Courier adapter for XFX sign photos and route callbacks; mini-user logistics UI with timeline, phone dial, and estimated arrival. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { COURIER_PROVIDER } from './courier.constants';
|
|
import type {
|
|
BatchShipmentQuery,
|
|
CourierCallOptions,
|
|
CreateShipmentInput,
|
|
CreateShipmentResult,
|
|
DeliveryCoverageResult,
|
|
FreightEstimateResult,
|
|
ICourierProvider,
|
|
ShipmentDetail,
|
|
ShipmentQuery,
|
|
TrackCallbackResponse,
|
|
TrackNode,
|
|
TrackCallbackPayload,
|
|
CourierMappedOrderStatus,
|
|
} from './courier.types';
|
|
|
|
/**
|
|
* 快递统一门面:业务层只依赖本 Service,不感知具体快递商实现。
|
|
*/
|
|
@Injectable()
|
|
export class CourierService {
|
|
constructor(@Inject(COURIER_PROVIDER) private readonly provider: ICourierProvider) {}
|
|
|
|
get activeProvider() {
|
|
return this.provider.code;
|
|
}
|
|
|
|
createShipment(input: CreateShipmentInput, options?: CourierCallOptions): Promise<CreateShipmentResult> {
|
|
return this.provider.createShipment(input, options);
|
|
}
|
|
|
|
cancelShipment(query: ShipmentQuery, options?: CourierCallOptions): Promise<void> {
|
|
return this.provider.cancelShipment(query, options);
|
|
}
|
|
|
|
getShipment(query: ShipmentQuery, options?: CourierCallOptions): Promise<ShipmentDetail> {
|
|
return this.provider.getShipment(query, options);
|
|
}
|
|
|
|
batchGetShipments(query: BatchShipmentQuery, options?: CourierCallOptions): Promise<ShipmentDetail[]> {
|
|
return this.provider.batchGetShipments(query, options);
|
|
}
|
|
|
|
getTrack(query: ShipmentQuery, options?: CourierCallOptions): Promise<TrackNode[]> {
|
|
return this.provider.getTrack(query, options);
|
|
}
|
|
|
|
getSignPhotos(query: ShipmentQuery, options?: CourierCallOptions): Promise<string[]> {
|
|
return this.provider.getSignPhotos(query, options);
|
|
}
|
|
|
|
checkDeliveryCoverage(toAddress: string, options?: CourierCallOptions): Promise<DeliveryCoverageResult> {
|
|
return this.provider.checkDeliveryCoverage(toAddress, options);
|
|
}
|
|
|
|
estimateFreight(weight: number, options?: CourierCallOptions): Promise<FreightEstimateResult> {
|
|
return this.provider.estimateFreight(weight, options);
|
|
}
|
|
|
|
buildTrackCallbackResponse(success?: boolean): TrackCallbackResponse {
|
|
return this.provider.buildTrackCallbackResponse(success);
|
|
}
|
|
|
|
parseTrackCallback(body: unknown): TrackCallbackPayload | null {
|
|
return this.provider.parseTrackCallback(body);
|
|
}
|
|
|
|
mapTrackStatus(status: string): CourierMappedOrderStatus | null {
|
|
return this.provider.mapTrackStatus(status);
|
|
}
|
|
}
|