Skip to content

Commit

Permalink
Merge pull request #3421 from owid:fix-gdoc-tagging-bug
Browse files Browse the repository at this point in the history
🐛 fix gdoc tagging bug
  • Loading branch information
danyx23 authored Mar 28, 2024
2 parents 7eb7ccc + 0cd669f commit 1c8abdf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,14 +2416,11 @@ postRouteWithRWTransaction(
async (req, res, trx) => {
const { gdocId } = req.params
const { tagIds } = req.body
const tagIdsAsObjects: { id: number }[] = tagIds.map((id: number) => ({
id: id,
}))

await setTagsForGdoc(
trx,
gdocId,
tagIds.map((id: number) => {
id
})
)
await setTagsForGdoc(trx, gdocId, tagIdsAsObjects)

return { success: true }
}
Expand Down
5 changes: 3 additions & 2 deletions db/model/Gdoc/GdocFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,11 @@ export async function setTagsForGdoc(
tagIds: Pick<DbPlainTag, "id">[]
): Promise<void> {
await knex.table(PostsGdocsXTagsTableName).where({ gdocId }).delete()
if (tagIds.length)
const tagIdsForInsert = tagIds.map(({ id: tagId }) => ({ gdocId, tagId }))
if (tagIdsForInsert.length)
await knex
.table(PostsGdocsXTagsTableName)
.insert(tagIds.map(({ id: tagId }) => ({ gdocId, tagId })))
.insert(tagIdsForInsert)
}

export enum GdocLinkUpdateMode {
Expand Down

0 comments on commit 1c8abdf

Please sign in to comment.