Fix tests and add changelog
This commit is contained in:
@@ -21,6 +21,7 @@ export async function getNotes(includeArchived = false) {
|
||||
where: includeArchived ? {} : { isArchived: false },
|
||||
orderBy: [
|
||||
{ isPinned: 'desc' },
|
||||
{ order: 'asc' },
|
||||
{ updatedAt: 'desc' }
|
||||
]
|
||||
})
|
||||
@@ -245,30 +246,56 @@ export async function getAllLabels() {
|
||||
|
||||
// Reorder notes (drag and drop)
|
||||
export async function reorderNotes(draggedId: string, targetId: string) {
|
||||
console.log('[REORDER-DEBUG] reorderNotes called:', { draggedId, targetId })
|
||||
|
||||
try {
|
||||
const draggedNote = await prisma.note.findUnique({ where: { id: draggedId } })
|
||||
const targetNote = await prisma.note.findUnique({ where: { id: targetId } })
|
||||
|
||||
console.log('[REORDER-DEBUG] Notes found:', {
|
||||
draggedNote: draggedNote ? { id: draggedNote.id, title: draggedNote.title, isPinned: draggedNote.isPinned, order: draggedNote.order } : null,
|
||||
targetNote: targetNote ? { id: targetNote.id, title: targetNote.title, isPinned: targetNote.isPinned, order: targetNote.order } : null
|
||||
})
|
||||
|
||||
if (!draggedNote || !targetNote) {
|
||||
console.error('[REORDER-DEBUG] Notes not found')
|
||||
throw new Error('Notes not found')
|
||||
}
|
||||
|
||||
// Swap the order values
|
||||
await prisma.$transaction([
|
||||
// Get all notes in the same category (pinned or unpinned)
|
||||
const allNotes = await prisma.note.findMany({
|
||||
where: {
|
||||
isPinned: draggedNote.isPinned,
|
||||
isArchived: false
|
||||
},
|
||||
orderBy: { order: 'asc' }
|
||||
})
|
||||
|
||||
console.log('[REORDER-DEBUG] All notes in category:', allNotes.map(n => ({ id: n.id, title: n.title, order: n.order })))
|
||||
|
||||
// Create new order array
|
||||
const reorderedNotes = allNotes.filter(n => n.id !== draggedId)
|
||||
const targetIndex = reorderedNotes.findIndex(n => n.id === targetId)
|
||||
reorderedNotes.splice(targetIndex, 0, draggedNote)
|
||||
|
||||
console.log('[REORDER-DEBUG] New order:', reorderedNotes.map((n, i) => ({ id: n.id, title: n.title, newOrder: i })))
|
||||
|
||||
// Update all notes with new order
|
||||
const updates = reorderedNotes.map((note, index) =>
|
||||
prisma.note.update({
|
||||
where: { id: draggedId },
|
||||
data: { order: targetNote.order }
|
||||
}),
|
||||
prisma.note.update({
|
||||
where: { id: targetId },
|
||||
data: { order: draggedNote.order }
|
||||
where: { id: note.id },
|
||||
data: { order: index }
|
||||
})
|
||||
])
|
||||
)
|
||||
|
||||
console.log('[REORDER-DEBUG] Executing transaction with', updates.length, 'updates')
|
||||
await prisma.$transaction(updates)
|
||||
console.log('[REORDER-DEBUG] Transaction completed successfully')
|
||||
|
||||
revalidatePath('/')
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
console.error('Error reordering notes:', error)
|
||||
console.error('[REORDER-DEBUG] Error reordering notes:', error)
|
||||
throw new Error('Failed to reorder notes')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user