2021-04-13 21:53:58 +02:00
|
|
|
import { Controller } from '@nestjs/common';
|
|
|
|
|
|
|
|
import { PrismaService } from '../services/prisma.service';
|
|
|
|
import { RedisCacheService } from './redis-cache/redis-cache.service';
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
export class AppController {
|
|
|
|
public constructor(
|
2021-08-07 22:38:07 +02:00
|
|
|
private readonly prismaService: PrismaService,
|
2021-04-13 21:53:58 +02:00
|
|
|
private readonly redisCacheService: RedisCacheService
|
|
|
|
) {
|
|
|
|
this.initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
private async initialize() {
|
|
|
|
this.redisCacheService.reset();
|
|
|
|
|
2021-08-07 22:38:07 +02:00
|
|
|
const isDataGatheringLocked = await this.prismaService.property.findUnique({
|
2021-04-13 21:53:58 +02:00
|
|
|
where: { key: 'LOCKED_DATA_GATHERING' }
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!isDataGatheringLocked) {
|
|
|
|
// Prepare for automatical data gather if not locked
|
2021-08-07 22:38:07 +02:00
|
|
|
await this.prismaService.property.deleteMany({
|
2021-04-13 21:53:58 +02:00
|
|
|
where: {
|
|
|
|
OR: [{ key: 'LAST_DATA_GATHERING' }, { key: 'LOCKED_DATA_GATHERING' }]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|