From 54ca3a7007727b3e49e2aa4867bc55ea9314abf3 Mon Sep 17 00:00:00 2001 From: yhostc Date: Thu, 9 May 2024 12:47:17 +0800 Subject: [PATCH] chore: update --- .../src/modules/files/service/file.service.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/bodhi-service/src/modules/files/service/file.service.ts b/apps/bodhi-service/src/modules/files/service/file.service.ts index 9c1e703..f52f644 100644 --- a/apps/bodhi-service/src/modules/files/service/file.service.ts +++ b/apps/bodhi-service/src/modules/files/service/file.service.ts @@ -15,12 +15,18 @@ export class FileService { @Cron(CronExpression.EVERY_HOUR) async handleExpired() { - const files = await this.repository.find({ where: { expires_at: LessThan(new Date()), state: FileState.ACTIVE } }); + const expires_at = moment.utc().toDate(); + const files = await this.repository.find({ where: { expires_at: LessThan(expires_at), state: FileState.ACTIVE } }); for (const file of files) { this.repository.update(file.id, { state: FileState.EXPIRED }); } } + async findExpired7Days() { + const expires_at = moment.utc().add(7, 'days').toDate(); + return this.repository.find({ where: { expires_at: LessThan(expires_at), state: FileState.EXPIRED } }); + } + async create(opts: Partial) { return this.repository.save(this.repository.create(opts)); } @@ -86,9 +92,4 @@ export class FileService { async findActiveByFileID(file_id: string) { return this.repository.findOne({ where: { file_id, state: FileState.ACTIVE } }); } - - async findExpired7Days() { - const expires_at = moment.utc().add(7, 'days').toDate(); - return this.repository.find({ where: { expires_at: MoreThan(expires_at), state: FileState.EXPIRED } }); - } }