fix: label management - transaction safety, deletion sync, error handling
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s
- Use prisma.$transaction in auto-label-creation.service with tx client - Fix DELETE /api/labels to properly JSON.parse + disconnect labelRelations - Fix PUT /api/labels rename to handle JSON labels - Graceful error handling in /api/ai/tags and /api/ai/auto-labels - Client-side label-deleted event in home-client, notes-tabs-view, label-management-dialog Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -431,14 +431,16 @@ Deine Antwort (nur JSON):
|
||||
): Promise<number> {
|
||||
let createdCount = 0
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
for (const suggestedLabel of suggestions.suggestedLabels) {
|
||||
if (!selectedLabels.includes(suggestedLabel.name)) continue
|
||||
|
||||
// Create the label
|
||||
const label = await prisma.label.create({
|
||||
data: {
|
||||
const label = await tx.label.upsert({
|
||||
where: { notebookId_name: { notebookId, name: suggestedLabel.name } as any },
|
||||
update: {},
|
||||
create: {
|
||||
name: suggestedLabel.name,
|
||||
color: 'gray', // Default color, user can change later
|
||||
color: 'gray',
|
||||
notebookId,
|
||||
userId,
|
||||
},
|
||||
@@ -446,7 +448,7 @@ Deine Antwort (nur JSON):
|
||||
|
||||
// Assign to notes: UI reads `Note.labels` (JSON string[]); relations must stay in sync
|
||||
for (const noteId of suggestedLabel.noteIds) {
|
||||
const note = await prisma.note.findFirst({
|
||||
const note = await tx.note.findFirst({
|
||||
where: { id: noteId, userId, notebookId },
|
||||
select: { labels: true },
|
||||
})
|
||||
@@ -469,7 +471,7 @@ Deine Antwort (nur JSON):
|
||||
names = [...names, suggestedLabel.name]
|
||||
}
|
||||
|
||||
await prisma.note.update({
|
||||
await tx.note.update({
|
||||
where: { id: noteId },
|
||||
data: {
|
||||
labels: JSON.stringify(names),
|
||||
@@ -482,6 +484,7 @@ Deine Antwort (nur JSON):
|
||||
|
||||
createdCount++
|
||||
}
|
||||
})
|
||||
|
||||
return createdCount
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user