-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 설정한 시간이 지나면 노트를 자동으로 삭제할 수 있음 (1673beta#70)
- Loading branch information
Showing
25 changed files
with
425 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export class AddDeleteAt1720161864577 { | ||
name = 'AddDeleteAt1720161864577' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "note" ADD "deleteAt" TIMESTAMP WITH TIME ZONE`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "deleteAt"`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/backend/src/queue/processors/ScheduledNoteDeleteProcessorService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { DI } from '@/di-symbols.js'; | ||
import type { NotesRepository, UsersRepository } from '@/models/_.js'; | ||
import type Logger from '@/logger.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
import { NoteDeleteService } from '@/core/NoteDeleteService.js'; | ||
import { QueueLoggerService } from '../QueueLoggerService.js'; | ||
import type * as Bull from 'bullmq'; | ||
import type { ScheduledNoteDeleteJobData } from '../types.js'; | ||
|
||
@Injectable() | ||
export class ScheduledNoteDeleteProcessorService { | ||
private logger: Logger; | ||
|
||
constructor( | ||
@Inject(DI.notesRepository) | ||
private notesRepository: NotesRepository, | ||
|
||
@Inject(DI.usersRepository) | ||
private usersRepository: UsersRepository, | ||
|
||
private noteDeleteService: NoteDeleteService, | ||
private queueLoggerService: QueueLoggerService, | ||
) { | ||
this.logger = this.queueLoggerService.logger.createSubLogger('scheduled-note-delete'); | ||
} | ||
|
||
@bindThis | ||
public async process(job: Bull.Job<ScheduledNoteDeleteJobData>): Promise<void> { | ||
const note = await this.notesRepository.findOneBy({ id: job.data.noteId }); | ||
|
||
if (note == null) { | ||
return; | ||
} | ||
|
||
const user = await this.usersRepository.findOneBy({ id: note.userId }); | ||
|
||
if (user == null) { | ||
return; | ||
} | ||
|
||
await this.noteDeleteService.delete(user, note); | ||
this.logger.info(`Delete note ${note.id}`); | ||
} | ||
} |
Oops, something went wrong.