This commit is contained in:
2026-10-21 23:23:48 +08:00
commit a9e4f6cd90
2983 changed files with 303453 additions and 0 deletions
@@ -0,0 +1,41 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, MoreThan } from 'typeorm';
import { LcCustomer } from '../../entities/lc-customer.entity';
import { LcLicense } from '../../entities/lc-license.entity';
@Injectable()
export class DashboardService {
constructor(
@InjectRepository(LcCustomer)
private readonly customerRepo: Repository<LcCustomer>,
@InjectRepository(LcLicense)
private readonly licenseRepo: Repository<LcLicense>,
) {}
async stats() {
const customerCount = await this.customerRepo.count();
const activeLicenseCount = await this.licenseRepo.count({ where: { status: 'active' } });
const thirtyDaysLater = new Date();
thirtyDaysLater.setDate(thirtyDaysLater.getDate() + 30);
const expiringSoonCount = await this.licenseRepo.count({
where: {
status: 'active',
expiresAt: MoreThan(new Date()),
},
});
const expiring = await this.licenseRepo
.createQueryBuilder('l')
.where('l.status = :status', { status: 'active' })
.andWhere('l.expires_at <= :date', { date: thirtyDaysLater })
.andWhere('l.expires_at > NOW()')
.getCount();
return {
customerCount,
activeLicenseCount,
expiringSoonCount: expiring,
totalLicenses: await this.licenseRepo.count(),
};
}
}