Destory deck helper
Build and Push Docker Image / build (push) Successful in 2m58s

This commit is contained in:
2026-06-29 00:17:15 -07:00
parent 39afe80a6c
commit 0595285c25
3 changed files with 48 additions and 7 deletions
@@ -1,5 +1,5 @@
import db from "@/db/db-client"
import { FlashcardDeck } from "@/models"
import { Flashcard, FlashcardDeck } from "@/models"
import BaseService from "@/services/base-service"
export class DestroyService extends BaseService {
@@ -8,12 +8,19 @@ export class DestroyService extends BaseService {
}
async perform(): Promise<void> {
await db.transaction(async (transaction) => {
await db.transaction(async () => {
await FlashcardDeck.update(
{ parentDeckId: null },
{ where: { parentDeckId: this.flashcardDeck.id }, transaction }
{ where: { parentDeckId: this.flashcardDeck.id } }
)
await this.flashcardDeck.destroy({ transaction })
await Flashcard.destroy({
where: {
flashcardDeckId: this.flashcardDeck.id,
},
})
await this.flashcardDeck.destroy()
})
}
}