All files / src/domains/hr/leave/import-export import-export.service.ts

0% Statements 0/19
0% Branches 0/12
0% Functions 0/5
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                                                         
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { LeaveImportJob, LeaveExportJob } from '../schemas';
 
@Injectable()
export class ImportExportService {
  constructor(
    @InjectModel(LeaveImportJob.name)
    private importModel: Model<LeaveImportJob>,
    @InjectModel(LeaveExportJob.name)
    private exportModel: Model<LeaveExportJob>,
  ) {}
 
  async createImportJob(tenantId: string, dto: any, userId: string) {
    return this.importModel.create({
      ...dto,
      tenantId,
      status: 'queued',
      importedBy: userId,
    });
  }
 
  async getImportJob(tenantId: string, id: string) {
    const job = await this.importModel.findOne({ _id: id, tenantId }).exec();
    if (!job) throw new NotFoundException('Import job not found');
    return job;
  }
 
  async createExportJob(tenantId: string, dto: any, userId: string) {
    return this.exportModel.create({
      ...dto,
      tenantId,
      status: 'queued',
      requestedBy: userId,
    });
  }
 
  async getExportJob(tenantId: string, id: string) {
    const job = await this.exportModel.findOne({ _id: id, tenantId }).exec();
    if (!job) throw new NotFoundException('Export job not found');
    return job;
  }
}