Skip to content

Commit

Permalink
feat(api): cascade budget users when delete budget
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdev98 committed Aug 20, 2024
1 parent 6eea783 commit c10f340
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "BudgetUser" DROP CONSTRAINT "BudgetUser_budgetId_fkey";

-- DropForeignKey
ALTER TABLE "BudgetUser" DROP CONSTRAINT "BudgetUser_userId_fkey";

-- AddForeignKey
ALTER TABLE "BudgetUser" ADD CONSTRAINT "BudgetUser_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "BudgetUser" ADD CONSTRAINT "BudgetUser_budgetId_fkey" FOREIGN KEY ("budgetId") REFERENCES "Budget"("id") ON DELETE CASCADE ON UPDATE CASCADE;
4 changes: 2 additions & 2 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ model BudgetUser {
permission BudgetUserPermission
userId String
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
budgetId String
budget Budget @relation(fields: [budgetId], references: [id])
budget Budget @relation(fields: [budgetId], references: [id], onDelete: Cascade)
@@unique([userId, budgetId])
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/v1/services/budget.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export async function createBudget({
create: {
id: period.id,
type: period.type,
amount: period.amount,
amount: period.amount ?? 0,
startDate: period.startDate ?? periodConfig.startDate,
endDate: period.endDate ?? periodConfig.endDate,
},
Expand Down

0 comments on commit c10f340

Please sign in to comment.