mirror of
https://gitee.com/qqtt-ah/ai-crm.git
synced 2026-11-25 01:09:20 +08:00
init
This commit is contained in:
@@ -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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user