hotfix: only delete recipe relations that are being updated
Some checks failed
Basil CI/CD Pipeline / Shared Package Tests (push) Successful in 1m5s
Basil CI/CD Pipeline / Code Linting (push) Successful in 1m10s
Basil CI/CD Pipeline / Web Tests (push) Successful in 1m18s
Basil CI/CD Pipeline / API Tests (push) Failing after 1m31s
Basil CI/CD Pipeline / Security Scanning (push) Successful in 1m9s
Basil CI/CD Pipeline / Build All Packages (push) Has been skipped
Basil CI/CD Pipeline / E2E Tests (push) Has been skipped
Basil CI/CD Pipeline / Build & Push Docker Images (push) Has been skipped
Basil CI/CD Pipeline / Trigger Deployment (push) Has been skipped
Some checks failed
Basil CI/CD Pipeline / Shared Package Tests (push) Successful in 1m5s
Basil CI/CD Pipeline / Code Linting (push) Successful in 1m10s
Basil CI/CD Pipeline / Web Tests (push) Successful in 1m18s
Basil CI/CD Pipeline / API Tests (push) Failing after 1m31s
Basil CI/CD Pipeline / Security Scanning (push) Successful in 1m9s
Basil CI/CD Pipeline / Build All Packages (push) Has been skipped
Basil CI/CD Pipeline / E2E Tests (push) Has been skipped
Basil CI/CD Pipeline / Build & Push Docker Images (push) Has been skipped
Basil CI/CD Pipeline / Trigger Deployment (push) Has been skipped
CRITICAL BUG FIX: - Change PUT /recipes/:id to only delete relations present in request - Prevents deleting ingredients/instructions when only updating tags - Fixes production bug where adding quick tags removed all recipe content - Makes update endpoint behave like PATCH for nested relations This was causing all ingredients and instructions to disappear when adding tags via the quick tag feature.
This commit is contained in:
@@ -363,11 +363,19 @@ router.put('/:id', async (req, res) => {
|
||||
try {
|
||||
const { sections, ingredients, instructions, tags, ...recipeData } = req.body;
|
||||
|
||||
// Delete existing relations
|
||||
await prisma.recipeSection.deleteMany({ where: { recipeId: req.params.id } });
|
||||
await prisma.ingredient.deleteMany({ where: { recipeId: req.params.id } });
|
||||
await prisma.instruction.deleteMany({ where: { recipeId: req.params.id } });
|
||||
await prisma.recipeTag.deleteMany({ where: { recipeId: req.params.id } });
|
||||
// Only delete relations that are being updated (not undefined)
|
||||
if (sections !== undefined) {
|
||||
await prisma.recipeSection.deleteMany({ where: { recipeId: req.params.id } });
|
||||
}
|
||||
if (ingredients !== undefined) {
|
||||
await prisma.ingredient.deleteMany({ where: { recipeId: req.params.id } });
|
||||
}
|
||||
if (instructions !== undefined) {
|
||||
await prisma.instruction.deleteMany({ where: { recipeId: req.params.id } });
|
||||
}
|
||||
if (tags !== undefined) {
|
||||
await prisma.recipeTag.deleteMany({ where: { recipeId: req.params.id } });
|
||||
}
|
||||
|
||||
// Helper to clean IDs from nested data
|
||||
const cleanIngredient = (ing: any, index: number) => ({
|
||||
|
||||
Reference in New Issue
Block a user