Skip to content

Commit

Permalink
🐞fix: set top tag deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
blinko-space committed Nov 8, 2024
1 parent eb435f7 commit 07fe3fa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/server/routers/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ export const noteRouter = router({

if (id) {
const note = await prisma.notes.update({ where: { id }, data: update })
if (content == null) return
const oldTagsInThisNote = await prisma.tagsToNote.findMany({ where: { noteId: note.id }, include: { tag: true } })
await handleAddTags(tagTree, undefined)
const oldTags = oldTagsInThisNote.map(i => i.tag).filter(i => !!i)
const oldTagsString = oldTags.map(i => `${i?.name}<key>${i?.parent}`)
const newTagsString = newTags.map(i => `${i?.name}<key>${i?.parent}`)
const needTobeAddedRelationTags = _.difference(newTagsString, oldTagsString);
const needToBeDeletedRelationTags = _.difference(oldTagsString, newTagsString);
console.log({ oldTags, newTags, needTobeAddedRelationTags, needToBeDeletedRelationTags })
if (needToBeDeletedRelationTags.length != 0) {
await prisma.tagsToNote.deleteMany({
where: {
Expand All @@ -142,7 +144,6 @@ export const noteRouter = router({
}
})
}

if (needTobeAddedRelationTags.length != 0) {
await prisma.tagsToNote.createMany({
data: needTobeAddedRelationTags.map(i => {
Expand Down

0 comments on commit 07fe3fa

Please sign in to comment.