init
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export interface IDeliveryProvider {
|
||||
scheduleAutoAdvance(orderId: bigint): Promise<void>;
|
||||
advanceTo(orderId: bigint, targetStatus: string): Promise<void>;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
import { Queue } from 'bullmq';
|
||||
import { loadAppConfig } from '@dukang/shared-types';
|
||||
import { IDeliveryProvider } from './delivery.interface';
|
||||
import { DELIVERY_QUEUE } from '../../jobs/jobs.constants';
|
||||
|
||||
@Injectable()
|
||||
export class DeliveryMockProvider implements IDeliveryProvider {
|
||||
private readonly config = loadAppConfig();
|
||||
|
||||
constructor(@InjectQueue(DELIVERY_QUEUE) private readonly queue: Queue) {}
|
||||
|
||||
async scheduleAutoAdvance(orderId: bigint): Promise<void> {
|
||||
if (!this.config.mockDeliveryAuto) return;
|
||||
const steps = [
|
||||
{ delay: 0, status: 'OUT_WAREHOUSE' },
|
||||
{ delay: 10000, status: 'SHIPPING' },
|
||||
{ delay: 30000, status: 'PENDING_RECEIVE' },
|
||||
{ delay: 60000, status: 'COMPLETED' },
|
||||
];
|
||||
for (const step of steps) {
|
||||
await this.queue.add(
|
||||
'advance-status',
|
||||
{ orderId: orderId.toString(), targetStatus: step.status },
|
||||
{ delay: step.delay, jobId: `${orderId}-${step.status}` },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async advanceTo(orderId: bigint, targetStatus: string): Promise<void> {
|
||||
await this.queue.add('advance-status', {
|
||||
orderId: orderId.toString(),
|
||||
targetStatus,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user