Skip to content

Commit

Permalink
🐛 add forgotten persisting of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Mar 12, 2024
1 parent 36e4e7a commit a361815
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 2 additions & 5 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
DimensionProperty,
TaggableType,
DbChartTagJoin,
OwidGdoc,
pick,
} from "@ourworldindata/utils"
import {
Expand All @@ -77,7 +76,6 @@ import {
DbPlainDataset,
DbRawPostGdoc,
PostsGdocsXImagesTableName,
DbPlainPostGdocXImage,
DbInsertPostGdocXImage,
PostsGdocsLinksTableName,
PostsGdocsTableName,
Expand All @@ -90,7 +88,6 @@ import {
import { getDatasetById, setTagsForDataset } from "../db/model/Dataset.js"
import { getUserById, insertUser, updateUser } from "../db/model/User.js"
import { GdocPost } from "../db/model/Gdoc/GdocPost.js"
import { GdocBase } from "../db/model/Gdoc/GdocBase.js"
import {
syncDatasetToGitRepo,
removeDatasetFromGitRepo,
Expand Down Expand Up @@ -132,10 +129,10 @@ import {
getAndLoadGdocById,
getGdocBaseObjectById,
loadGdocFromGdocBase,
setTagsForGdoc,
updateGdocContentOnly,
upsertGdoc,
} from "../db/model/Gdoc/GdocFactory.js"
import { GdocDataInsight } from "../db/model/Gdoc/GdocDataInsight.js"

const apiRouter = new FunctionalRouter()

Expand Down Expand Up @@ -2466,8 +2463,8 @@ postRouteWithRWTransaction(
gdoc.createdAt = new Date()
gdoc.publishedAt = post.published_at
await upsertGdoc(trx, gdoc.toDbRawPostGdoc())
await setTagsForGdoc(trx, gdocId, tags)
}

return { googleDocsId: gdocId }
}
)
Expand Down
14 changes: 12 additions & 2 deletions db/model/Gdoc/GdocFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import {
OwidEnrichedGdocBlock,
OwidGdoc,
OwidGdocBaseInterface,
OwidGdocContent,
OwidGdocMinimalPostInterface,
OwidGdocPublicationContext,
OwidGdocType,
PostsGdocsTableName,
PostsGdocsXTagsTableName,
checkIsOwidGdocType,
formatDate,
parsePostsGdocsRow,
serializePostRow,
serializePostsGdocsRow,
} from "@ourworldindata/utils"

Expand Down Expand Up @@ -443,6 +442,17 @@ export async function getAndLoadListedGdocPosts(
return gdocs as GdocPost[]
}

export async function setTagsForGdoc(
knex: KnexReadWriteTransaction,
gdocId: string,
tagIds: Pick<DbPlainTag, "id">[]
): Promise<void> {
await knex.table(PostsGdocsXTagsTableName).where("gdocId", gdocId).delete()
await knex
.table(PostsGdocsXTagsTableName)
.insert(tagIds.map(({ id: tagId }) => ({ gdocId, tagId })))
}

export async function upsertGdoc(
knex: KnexReadWriteTransaction,
gdoc: DbEnrichedPostGdoc
Expand Down

0 comments on commit a361815

Please sign in to comment.