feat: implement AI suggestion
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user