33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { Processor, Process, InjectQueue } from '@nestjs/bull';
|
|
import { Job, Queue } from 'bull';
|
|
import { Logger } from '@nestjs/common';
|
|
import { InvoicesService } from './invoice.service';
|
|
|
|
@Processor('invoice-bulk-queue')
|
|
export class BulkUploadProcessor {
|
|
private readonly logger = new Logger(BulkUploadProcessor.name);
|
|
|
|
constructor(
|
|
private readonly invoicesService: InvoicesService,
|
|
@InjectQueue('invoice-bulk-queue') private readonly bulkQueue: Queue,
|
|
) {}
|
|
|
|
@Process('process-zip')
|
|
async handleBulkZip(job: Job<{ filePath: string, companyId: string, tenantId: string }>) {
|
|
const { filePath, companyId, tenantId } = job.data;
|
|
this.logger.log(`Processing bulk ZIP: ${filePath} for Company: ${companyId}`);
|
|
|
|
// TODO: Implement ZIP extraction (adm-zip or unzipper)
|
|
// TODO: For each file in ZIP:
|
|
// 1. Calculate Hash (MD5/SHA256)
|
|
// 2. Check Redis SMEMBERS to prevent duplicate processing
|
|
// const hash = 'calculated_file_hash';
|
|
// const exists = await this.bulkQueue.client.sismember(`company:${companyId}:invoice-hashes`, hash);
|
|
// if (exists) return;
|
|
|
|
// 3. Save hash and trigger individual processing
|
|
// await this.bulkQueue.client.sadd(`company:${companyId}:invoice-hashes`, hash);
|
|
// await this.invoicesService.processSingleFile(fileInZip, tenantId, companyId);
|
|
}
|
|
}
|