feat: implement AI suggestion

This commit is contained in:
2024-12-12 21:22:50 +07:00
parent 3652fda7d3
commit 68353d8985
7 changed files with 133 additions and 183 deletions

View File

@@ -193,27 +193,32 @@ export class CronService {
@Cron(CronExpression.EVERY_DAY_AT_1AM)
async taskDisableServiceWithoutSchedule() {
Logger.log('Disabling service without any schedule', 'CronService')
const services = await this.prisma.managedService.findMany({
const services = await this.prisma.service.findMany({
where: {
NOT: {
schedule: {
// check if service has any schedule in the past 30 days
managedService: {
some: {
scheduleStart: { gte: DateTimeUtils.now().minus({ days: 30 }).toJSDate() },
schedule: {
some: {
scheduleStart: { gte: DateTimeUtils.now().minus({ days: 30 }).toJSDate() },
},
},
},
},
// and createdAt is more than 3 days ago
createdAt: {
lt: DateTimeUtils.now().minus({ days: 3 }).toJSDate(),
},
},
},
})
for (const service of services) {
await this.prisma.managedService.update({
await this.prisma.service.update({
where: { id: service.id },
data: {
service: {
update: {
status: ServiceStatus.INACTIVE,
},
},
status: ServiceStatus.INACTIVE,
},
})
Logger.log(`Service ${service.id} has been disabled`, 'CronService')