Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
isnolan committed May 9, 2024
1 parent 12c941a commit 54ca3a7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions apps/bodhi-service/src/modules/files/service/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<File>) {
return this.repository.save(this.repository.create(opts));
}
Expand Down Expand Up @@ -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 } });
}
}

0 comments on commit 54ca3a7

Please sign in to comment.