diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index 99f658e811b..62d8c4080f8 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -53,7 +53,6 @@ import { DimensionProperty, TaggableType, DbChartTagJoin, - OwidGdoc, pick, } from "@ourworldindata/utils" import { @@ -77,7 +76,6 @@ import { DbPlainDataset, DbRawPostGdoc, PostsGdocsXImagesTableName, - DbPlainPostGdocXImage, DbInsertPostGdocXImage, PostsGdocsLinksTableName, PostsGdocsTableName, @@ -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, @@ -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() @@ -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 } } ) diff --git a/db/model/Gdoc/GdocFactory.ts b/db/model/Gdoc/GdocFactory.ts index 6ee9dbed0d7..5a368c5441b 100644 --- a/db/model/Gdoc/GdocFactory.ts +++ b/db/model/Gdoc/GdocFactory.ts @@ -9,15 +9,14 @@ import { OwidEnrichedGdocBlock, OwidGdoc, OwidGdocBaseInterface, - OwidGdocContent, OwidGdocMinimalPostInterface, OwidGdocPublicationContext, OwidGdocType, PostsGdocsTableName, + PostsGdocsXTagsTableName, checkIsOwidGdocType, formatDate, parsePostsGdocsRow, - serializePostRow, serializePostsGdocsRow, } from "@ourworldindata/utils" @@ -443,6 +442,17 @@ export async function getAndLoadListedGdocPosts( return gdocs as GdocPost[] } +export async function setTagsForGdoc( + knex: KnexReadWriteTransaction, + gdocId: string, + tagIds: Pick[] +): Promise { + 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