diff --git a/src/app/api/export-import/route.ts b/src/app/api/export-import/route.ts index ebf6c15..04e0c04 100644 --- a/src/app/api/export-import/route.ts +++ b/src/app/api/export-import/route.ts @@ -105,21 +105,22 @@ export async function POST(req: NextRequest) { const createdAt = parseDate((item as { createdAt?: string }).createdAt) const updatedAt = parseDate((item as { updatedAt?: string }).updatedAt) + const itemWithId = item as { id?: string } - if (item.id) { - const existing = await tx.note.findUnique({ where: { id: item.id } }) + if (itemWithId.id) { + const existing = await tx.note.findUnique({ where: { id: itemWithId.id } }) if (existing) { await tx.note.update({ - where: { id: item.id }, + where: { id: itemWithId.id }, data: { ...noteData, createdAt, updatedAt }, }) - await tx.noteTag.deleteMany({ where: { noteId: item.id } }) + await tx.noteTag.deleteMany({ where: { noteId: itemWithId.id } }) processed++ } else { await tx.note.create({ data: { ...noteData, - id: item.id, + id: itemWithId.id, createdAt, updatedAt, creationSource: 'import', @@ -150,8 +151,8 @@ export async function POST(req: NextRequest) { processed++ } - const noteId = item.id - ? (await tx.note.findUnique({ where: { id: item.id } }))?.id + const noteId = itemWithId.id + ? (await tx.note.findUnique({ where: { id: itemWithId.id } }))?.id : (await tx.note.findFirst({ where: { title: item.title } }))?.id if (noteId && tags.length > 0) {