34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
|
import { DataSchedulingLogModel } from '../models/data-scheduling-log.model';
|
|
import { Repository } from 'typeorm';
|
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
|
|
|
@Injectable()
|
|
export class DataSchedulingLogDataService {
|
|
constructor(
|
|
@InjectRepository(DataSchedulingLogModel, CONNECTION_NAME.DEFAULT)
|
|
private repo: Repository<DataSchedulingLogModel>,
|
|
) {}
|
|
|
|
async create(entity: any): Promise<any> {
|
|
return await this.repo.save(entity);
|
|
}
|
|
|
|
async deleteRange(from: number, to: number): Promise<any> {
|
|
try {
|
|
const deleteResult = await this.repo
|
|
.createQueryBuilder()
|
|
.delete()
|
|
.from(TABLE_NAME.DATA_SCHEDULING_LOG)
|
|
.where('log_created_at BETWEEN :from AND :to', { from, to })
|
|
.execute();
|
|
|
|
return deleteResult;
|
|
} catch (error) {
|
|
throw new Error('Failed to delete range due to an internal error.');
|
|
}
|
|
}
|
|
}
|