小飞侠接口对接
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { COURIER_PROVIDER } from './courier.constants';
|
||||
import type {
|
||||
BatchShipmentQuery,
|
||||
CreateShipmentInput,
|
||||
CreateShipmentResult,
|
||||
DeliveryCoverageResult,
|
||||
FreightEstimateResult,
|
||||
ICourierProvider,
|
||||
ShipmentDetail,
|
||||
ShipmentQuery,
|
||||
TrackCallbackResponse,
|
||||
TrackNode,
|
||||
} 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): Promise<CreateShipmentResult> {
|
||||
return this.provider.createShipment(input);
|
||||
}
|
||||
|
||||
cancelShipment(query: ShipmentQuery): Promise<void> {
|
||||
return this.provider.cancelShipment(query);
|
||||
}
|
||||
|
||||
getShipment(query: ShipmentQuery): Promise<ShipmentDetail> {
|
||||
return this.provider.getShipment(query);
|
||||
}
|
||||
|
||||
batchGetShipments(query: BatchShipmentQuery): Promise<ShipmentDetail[]> {
|
||||
return this.provider.batchGetShipments(query);
|
||||
}
|
||||
|
||||
getTrack(query: ShipmentQuery): Promise<TrackNode[]> {
|
||||
return this.provider.getTrack(query);
|
||||
}
|
||||
|
||||
checkDeliveryCoverage(toAddress: string): Promise<DeliveryCoverageResult> {
|
||||
return this.provider.checkDeliveryCoverage(toAddress);
|
||||
}
|
||||
|
||||
estimateFreight(weight: number): Promise<FreightEstimateResult> {
|
||||
return this.provider.estimateFreight(weight);
|
||||
}
|
||||
|
||||
buildTrackCallbackResponse(success?: boolean): TrackCallbackResponse {
|
||||
return this.provider.buildTrackCallbackResponse(success);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user