generated from alphane/template
This commit is contained in:
@@ -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()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user