diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index 48ae2b306e..90afc08798 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -1,6 +1,435 @@ /* eslint @typescript-eslint/no-unused-vars: [ "warn", { argsIgnorePattern: "^(res|req)$" } ] */ +import { TaggableType } from "@ourworldindata/types" +import { DeployQueueServer } from "../baker/DeployQueueServer.js" +import { + updateVariableAnnotations, + getChartBulkUpdate, + updateBulkChartConfigs, + getVariableAnnotations, +} from "./apiRoutes/bulkUpdates.js" +import { + getChartViews, + getChartViewById, + createChartView, + updateChartView, + deleteChartView, +} from "./apiRoutes/chartViews.js" +import { + getDatasets, + getDataset, + updateDataset, + setArchived, + setTags, + deleteDataset, + republishCharts, +} from "./apiRoutes/datasets.js" +import { addExplorerTags, deleteExplorerTags } from "./apiRoutes/explorer.js" +import { + getAllGdocIndexItems, + getIndividualGdoc, + createOrUpdateGdoc, + deleteGdoc, + setGdocTags, +} from "./apiRoutes/gdocs.js" +import { + getImagesHandler, + postImageHandler, + putImageHandler, + patchImageHandler, + deleteImageHandler, + getImageUsageHandler, +} from "./apiRoutes/images.js" +import { handleMultiDimDataPageRequest } from "./apiRoutes/mdims.js" +import { + fetchAllWork, + fetchNamespaces, + fetchSourceById, +} from "./apiRoutes/misc.js" +import { + handleGetPostsJson, + handleSetTagsForPost, + handleGetPostById, + handleCreateGdoc, + handleUnlinkGdoc, +} from "./apiRoutes/posts.js" +import { + handleGetSiteRedirects, + handlePostNewSiteRedirect, + handleDeleteSiteRedirect, + handleGetRedirects, + handlePostNewChartRedirect, + handleDeleteChartRedirect, +} from "./apiRoutes/redirects.js" +import { triggerStaticBuild } from "./apiRoutes/routeUtils.js" +import { suggestGptTopics, suggestGptAltText } from "./apiRoutes/suggest.js" +import { + handleGetFlatTagGraph, + handlePostTagGraph, +} from "./apiRoutes/tagGraph.js" +import { + getTagById, + updateTag, + createTag, + getAllTags, + deleteTag, +} from "./apiRoutes/tags.js" +import { + getUsers, + getUserByIdHandler, + deleteUser, + updateUserHandler, + addUser, + addImageToUser, + removeUserImage, +} from "./apiRoutes/users.js" +import { + getEditorVariablesJson, + getVariableDataJson, + getVariableMetadataJson, + getVariablesJson, + getVariablesUsagesJson, + getVariablesGrapherConfigETLPatchConfigJson, + getVariablesGrapherConfigAdminPatchConfigJson, + getVariablesMergedGrapherConfigJson, + getVariablesVariableIdJson, + putVariablesVariableIdGrapherConfigETL, + deleteVariablesVariableIdGrapherConfigETL, + putVariablesVariableIdGrapherConfigAdmin, + deleteVariablesVariableIdGrapherConfigAdmin, + getVariablesVariableIdChartsJson, +} from "./apiRoutes/variables.js" import { FunctionalRouter } from "./FunctionalRouter.js" +import { + patchRouteWithRWTransaction, + getRouteWithROTransaction, + postRouteWithRWTransaction, + putRouteWithRWTransaction, + deleteRouteWithRWTransaction, + getRouteNonIdempotentWithRWTransaction, +} from "./functionalRouterHelpers.js" +import { + getChartsJson, + getChartsCsv, + getChartConfigJson, + getChartParentJson, + getChartPatchConfigJson, + getChartLogsJson, + getChartReferencesJson, + getChartRedirectsJson, + getChartPageviewsJson, + createChart, + setChartTagsHandler, + updateChart, + deleteChart, +} from "./apiRoutes/charts.js" const apiRouter = new FunctionalRouter() + +// Bulk chart update routes +patchRouteWithRWTransaction( + apiRouter, + "/variable-annotations", + updateVariableAnnotations +) +getRouteWithROTransaction(apiRouter, "/chart-bulk-update", getChartBulkUpdate) +patchRouteWithRWTransaction( + apiRouter, + "/chart-bulk-update", + updateBulkChartConfigs +) +getRouteWithROTransaction( + apiRouter, + "/variable-annotations", + getVariableAnnotations +) + +// Chart routes +getRouteWithROTransaction(apiRouter, "/charts.json", getChartsJson) +getRouteWithROTransaction(apiRouter, "/charts.csv", getChartsCsv) +getRouteWithROTransaction( + apiRouter, + "/charts/:chartId.config.json", + getChartConfigJson +) +getRouteWithROTransaction( + apiRouter, + "/charts/:chartId.parent.json", + getChartParentJson +) +getRouteWithROTransaction( + apiRouter, + "/charts/:chartId.patchConfig.json", + getChartPatchConfigJson +) +getRouteWithROTransaction( + apiRouter, + "/charts/:chartId.logs.json", + getChartLogsJson +) +getRouteWithROTransaction( + apiRouter, + "/charts/:chartId.references.json", + getChartReferencesJson +) +getRouteWithROTransaction( + apiRouter, + "/charts/:chartId.redirects.json", + getChartRedirectsJson +) +getRouteWithROTransaction( + apiRouter, + "/charts/:chartId.pageviews.json", + getChartPageviewsJson +) +postRouteWithRWTransaction(apiRouter, "/charts", createChart) +postRouteWithRWTransaction( + apiRouter, + "/charts/:chartId/setTags", + setChartTagsHandler +) +putRouteWithRWTransaction(apiRouter, "/charts/:chartId", updateChart) +deleteRouteWithRWTransaction(apiRouter, "/charts/:chartId", deleteChart) + +// Chart view routes +getRouteWithROTransaction(apiRouter, "/chartViews", getChartViews) +getRouteWithROTransaction(apiRouter, "/chartViews/:id", getChartViewById) +postRouteWithRWTransaction(apiRouter, "/chartViews", createChartView) +putRouteWithRWTransaction(apiRouter, "/chartViews/:id", updateChartView) +deleteRouteWithRWTransaction(apiRouter, "/chartViews/:id", deleteChartView) + +// Dataset routes +getRouteWithROTransaction(apiRouter, "/datasets.json", getDatasets) +getRouteWithROTransaction(apiRouter, "/datasets/:datasetId.json", getDataset) +putRouteWithRWTransaction(apiRouter, "/datasets/:datasetId", updateDataset) +postRouteWithRWTransaction( + apiRouter, + "/datasets/:datasetId/setArchived", + setArchived +) +postRouteWithRWTransaction(apiRouter, "/datasets/:datasetId/setTags", setTags) +deleteRouteWithRWTransaction(apiRouter, "/datasets/:datasetId", deleteDataset) +postRouteWithRWTransaction( + apiRouter, + "/datasets/:datasetId/charts", + republishCharts +) + +// explorer routes +postRouteWithRWTransaction(apiRouter, "/explorer/:slug/tags", addExplorerTags) +deleteRouteWithRWTransaction( + apiRouter, + "/explorer/:slug/tags", + deleteExplorerTags +) + +// Gdoc routes +getRouteWithROTransaction(apiRouter, "/gdocs", getAllGdocIndexItems) +getRouteNonIdempotentWithRWTransaction( + apiRouter, + "/gdocs/:id", + getIndividualGdoc +) +putRouteWithRWTransaction(apiRouter, "/gdocs/:id", createOrUpdateGdoc) +deleteRouteWithRWTransaction(apiRouter, "/gdocs/:id", deleteGdoc) +postRouteWithRWTransaction(apiRouter, "/gdocs/:gdocId/setTags", setGdocTags) + +// Images routes +getRouteNonIdempotentWithRWTransaction( + apiRouter, + "/images.json", + getImagesHandler +) +postRouteWithRWTransaction(apiRouter, "/images", postImageHandler) +putRouteWithRWTransaction(apiRouter, "/images/:id", putImageHandler) +// Update alt text via patch +patchRouteWithRWTransaction(apiRouter, "/images/:id", patchImageHandler) +deleteRouteWithRWTransaction(apiRouter, "/images/:id", deleteImageHandler) +getRouteWithROTransaction(apiRouter, "/images/usage", getImageUsageHandler) + +// Mdim routes +putRouteWithRWTransaction( + apiRouter, + "/multi-dim/:slug", + handleMultiDimDataPageRequest +) + +// Misc routes +getRouteWithROTransaction(apiRouter, "/all-work", fetchAllWork) +getRouteWithROTransaction( + apiRouter, + "/editorData/namespaces.json", + fetchNamespaces +) +getRouteWithROTransaction(apiRouter, "/sources/:sourceId.json", fetchSourceById) + +// Wordpress posts routes +getRouteWithROTransaction(apiRouter, "/posts.json", handleGetPostsJson) +postRouteWithRWTransaction( + apiRouter, + "/posts/:postId/setTags", + handleSetTagsForPost +) +getRouteWithROTransaction(apiRouter, "/posts/:postId.json", handleGetPostById) +postRouteWithRWTransaction( + apiRouter, + "/posts/:postId/createGdoc", + handleCreateGdoc +) +postRouteWithRWTransaction( + apiRouter, + "/posts/:postId/unlinkGdoc", + handleUnlinkGdoc +) + +// Redirects routes +getRouteWithROTransaction( + apiRouter, + "/site-redirects.json", + handleGetSiteRedirects +) +postRouteWithRWTransaction( + apiRouter, + "/site-redirects/new", + handlePostNewSiteRedirect +) +deleteRouteWithRWTransaction( + apiRouter, + "/site-redirects/:id", + handleDeleteSiteRedirect +) +getRouteWithROTransaction(apiRouter, "/redirects.json", handleGetRedirects) +postRouteWithRWTransaction( + apiRouter, + "/charts/:chartId/redirects/new", + handlePostNewChartRedirect +) +deleteRouteWithRWTransaction( + apiRouter, + "/redirects/:id", + handleDeleteChartRedirect +) + +// GPT routes +getRouteWithROTransaction( + apiRouter, + `/gpt/suggest-topics/${TaggableType.Charts}/:chartId.json`, + suggestGptTopics +) +getRouteWithROTransaction( + apiRouter, + `/gpt/suggest-alt-text/:imageId`, + suggestGptAltText +) + +// Tag graph routes +getRouteWithROTransaction( + apiRouter, + "/flatTagGraph.json", + handleGetFlatTagGraph +) +postRouteWithRWTransaction(apiRouter, "/tagGraph", handlePostTagGraph) +getRouteWithROTransaction(apiRouter, "/tags/:tagId.json", getTagById) +putRouteWithRWTransaction(apiRouter, "/tags/:tagId", updateTag) +postRouteWithRWTransaction(apiRouter, "/tags/new", createTag) +getRouteWithROTransaction(apiRouter, "/tags.json", getAllTags) +deleteRouteWithRWTransaction(apiRouter, "/tags/:tagId/delete", deleteTag) + +// User routes +getRouteWithROTransaction(apiRouter, "/users.json", getUsers) +getRouteWithROTransaction(apiRouter, "/users/:userId.json", getUserByIdHandler) +deleteRouteWithRWTransaction(apiRouter, "/users/:userId", deleteUser) +putRouteWithRWTransaction(apiRouter, "/users/:userId", updateUserHandler) +postRouteWithRWTransaction(apiRouter, "/users/add", addUser) +postRouteWithRWTransaction( + apiRouter, + "/users/:userId/images/:imageId", + addImageToUser +) +deleteRouteWithRWTransaction( + apiRouter, + "/users/:userId/images/:imageId", + removeUserImage +) + +// Variable routes +getRouteWithROTransaction( + apiRouter, + "/editorData/variables.json", + getEditorVariablesJson +) +getRouteWithROTransaction( + apiRouter, + "/data/variables/data/:variableStr.json", + getVariableDataJson +) +getRouteWithROTransaction( + apiRouter, + "/data/variables/metadata/:variableStr.json", + getVariableMetadataJson +) +getRouteWithROTransaction(apiRouter, "/variables.json", getVariablesJson) +getRouteWithROTransaction( + apiRouter, + "/variables.usages.json", + getVariablesUsagesJson +) +getRouteWithROTransaction( + apiRouter, + "/variables/grapherConfigETL/:variableId.patchConfig.json", + getVariablesGrapherConfigETLPatchConfigJson +) +getRouteWithROTransaction( + apiRouter, + "/variables/grapherConfigAdmin/:variableId.patchConfig.json", + getVariablesGrapherConfigAdminPatchConfigJson +) +getRouteWithROTransaction( + apiRouter, + "/variables/mergedGrapherConfig/:variableId.json", + getVariablesMergedGrapherConfigJson +) +// Used in VariableEditPage +getRouteWithROTransaction( + apiRouter, + "/variables/:variableId.json", + getVariablesVariableIdJson +) +// inserts a new config or updates an existing one +putRouteWithRWTransaction( + apiRouter, + "/variables/:variableId/grapherConfigETL", + putVariablesVariableIdGrapherConfigETL +) +deleteRouteWithRWTransaction( + apiRouter, + "/variables/:variableId/grapherConfigETL", + deleteVariablesVariableIdGrapherConfigETL +) +// inserts a new config or updates an existing one +putRouteWithRWTransaction( + apiRouter, + "/variables/:variableId/grapherConfigAdmin", + putVariablesVariableIdGrapherConfigAdmin +) +deleteRouteWithRWTransaction( + apiRouter, + "/variables/:variableId/grapherConfigAdmin", + deleteVariablesVariableIdGrapherConfigAdmin +) +getRouteWithROTransaction( + apiRouter, + "/variables/:variableId/charts.json", + getVariablesVariableIdChartsJson +) + +// Deploy helpers +apiRouter.get("/deploys.json", async () => ({ + deploys: await new DeployQueueServer().getDeploys(), +})) + +apiRouter.put("/deploy", async (req, res) => { + return triggerStaticBuild(res.locals.user, "Manually triggered deploy") +}) + export { apiRouter } diff --git a/adminSiteServer/apiRoutes/bulkUpdates.ts b/adminSiteServer/apiRoutes/bulkUpdates.ts index 364146238c..82aa5b598c 100644 --- a/adminSiteServer/apiRoutes/bulkUpdates.ts +++ b/adminSiteServer/apiRoutes/bulkUpdates.ts @@ -22,14 +22,9 @@ import { getGrapherConfigsForVariable, updateGrapherConfigAdminOfVariable, } from "../../db/model/Variable.js" -import { - getRouteWithROTransaction, - patchRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import { saveGrapher } from "./charts.js" import * as db from "../../db/db.js" import * as lodash from "lodash" -import { apiRouter } from "../apiRouter.js" import { Request } from "../authentication.js" import e from "express" @@ -245,22 +240,3 @@ export async function updateVariableAnnotations( return { success: true } } - -patchRouteWithRWTransaction( - apiRouter, - "/variable-annotations", - updateVariableAnnotations -) - -getRouteWithROTransaction(apiRouter, "/chart-bulk-update", getChartBulkUpdate) - -patchRouteWithRWTransaction( - apiRouter, - "/chart-bulk-update", - updateBulkChartConfigs -) -getRouteWithROTransaction( - apiRouter, - "/variable-annotations", - getVariableAnnotations -) diff --git a/adminSiteServer/apiRoutes/chartViews.ts b/adminSiteServer/apiRoutes/chartViews.ts index 4eda8ff3aa..1bb86557bd 100644 --- a/adminSiteServer/apiRoutes/chartViews.ts +++ b/adminSiteServer/apiRoutes/chartViews.ts @@ -19,18 +19,11 @@ import { diffGrapherConfigs, mergeGrapherConfigs } from "@ourworldindata/utils" import { omit, pick } from "lodash" import { ApiChartViewOverview } from "../../adminShared/AdminTypes.js" import { expectInt } from "../../serverUtils/serverUtil.js" -import { apiRouter } from "../apiRouter.js" import { saveNewChartConfigInDbAndR2, updateChartConfigInDbAndR2, } from "../chartConfigHelpers.js" import { deleteGrapherConfigFromR2ByUUID } from "../chartConfigR2Helpers.js" -import { - getRouteWithROTransaction, - postRouteWithRWTransaction, - putRouteWithRWTransaction, - deleteRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import * as db from "../../db/db.js" import { expectChartById } from "./charts.js" @@ -288,13 +281,3 @@ export async function deleteChartView( return { success: true } } - -getRouteWithROTransaction(apiRouter, "/chartViews", getChartViews) - -getRouteWithROTransaction(apiRouter, "/chartViews/:id", getChartViewById) - -postRouteWithRWTransaction(apiRouter, "/chartViews", createChartView) - -putRouteWithRWTransaction(apiRouter, "/chartViews/:id", updateChartView) - -deleteRouteWithRWTransaction(apiRouter, "/chartViews/:id", deleteChartView) diff --git a/adminSiteServer/apiRoutes/charts.ts b/adminSiteServer/apiRoutes/charts.ts index 0ab2670cdd..2b19a204a8 100644 --- a/adminSiteServer/apiRoutes/charts.ts +++ b/adminSiteServer/apiRoutes/charts.ts @@ -45,7 +45,6 @@ import { BAKED_BASE_URL, ADMIN_BASE_URL, } from "../../settings/clientSettings.js" -import { apiRouter } from "../apiRouter.js" import { retrieveChartConfigFromDbAndSaveToR2, updateChartConfigInDbAndR2, @@ -55,12 +54,6 @@ import { deleteGrapherConfigFromR2ByUUID, saveGrapherConfigToR2ByUUID, } from "../chartConfigR2Helpers.js" -import { - deleteRouteWithRWTransaction, - getRouteWithROTransaction, - postRouteWithRWTransaction, - putRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import { triggerStaticBuild } from "./routeUtils.js" import * as db from "../../db/db.js" import { getLogsByChartId } from "../getLogsByChartId.js" @@ -503,7 +496,7 @@ export async function updateGrapherConfigsInR2( } } -async function getChartsJson( +export async function getChartsJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -529,7 +522,7 @@ async function getChartsJson( return { charts } } -async function getChartsCsv( +export async function getChartsCsv( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -589,7 +582,7 @@ async function getChartsCsv( return csv } -async function getChartConfigJson( +export async function getChartConfigJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -597,7 +590,7 @@ async function getChartConfigJson( return expectChartById(trx, req.params.chartId) } -async function getChartParentJson( +export async function getChartParentJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -615,7 +608,7 @@ async function getChartParentJson( }) } -async function getChartPatchConfigJson( +export async function getChartPatchConfigJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -625,7 +618,7 @@ async function getChartPatchConfigJson( return config } -async function getChartLogsJson( +export async function getChartLogsJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -638,7 +631,7 @@ async function getChartLogsJson( } } -async function getChartReferencesJson( +export async function getChartReferencesJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -652,7 +645,7 @@ async function getChartReferencesJson( return references } -async function getChartRedirectsJson( +export async function getChartRedirectsJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -665,7 +658,7 @@ async function getChartRedirectsJson( } } -async function getChartPageviewsJson( +export async function getChartPageviewsJson( req: Request, res: e.Response>, trx: db.KnexReadonlyTransaction @@ -692,7 +685,7 @@ async function getChartPageviewsJson( } } -async function createChart( +export async function createChart( req: Request, res: e.Response>, trx: db.KnexReadWriteTransaction @@ -715,7 +708,7 @@ async function createChart( } } -async function setChartTagsHandler( +export async function setChartTagsHandler( req: Request, res: e.Response>, trx: db.KnexReadWriteTransaction @@ -727,7 +720,7 @@ async function setChartTagsHandler( return { success: true } } -async function updateChart( +export async function updateChart( req: Request, res: e.Response>, trx: db.KnexReadWriteTransaction @@ -762,7 +755,7 @@ async function updateChart( } } -async function deleteChart( +export async function deleteChart( req: Request, res: e.Response>, trx: db.KnexReadWriteTransaction @@ -814,49 +807,3 @@ async function deleteChart( return { success: true } } - -getRouteWithROTransaction(apiRouter, "/charts.json", getChartsJson) -getRouteWithROTransaction(apiRouter, "/charts.csv", getChartsCsv) -getRouteWithROTransaction( - apiRouter, - "/charts/:chartId.config.json", - getChartConfigJson -) -getRouteWithROTransaction( - apiRouter, - "/charts/:chartId.parent.json", - getChartParentJson -) -getRouteWithROTransaction( - apiRouter, - "/charts/:chartId.patchConfig.json", - getChartPatchConfigJson -) -getRouteWithROTransaction( - apiRouter, - "/charts/:chartId.logs.json", - getChartLogsJson -) -getRouteWithROTransaction( - apiRouter, - "/charts/:chartId.references.json", - getChartReferencesJson -) -getRouteWithROTransaction( - apiRouter, - "/charts/:chartId.redirects.json", - getChartRedirectsJson -) -getRouteWithROTransaction( - apiRouter, - "/charts/:chartId.pageviews.json", - getChartPageviewsJson -) -postRouteWithRWTransaction(apiRouter, "/charts", createChart) -postRouteWithRWTransaction( - apiRouter, - "/charts/:chartId/setTags", - setChartTagsHandler -) -putRouteWithRWTransaction(apiRouter, "/charts/:chartId", updateChart) -deleteRouteWithRWTransaction(apiRouter, "/charts/:chartId", deleteChart) diff --git a/adminSiteServer/apiRoutes/datasets.ts b/adminSiteServer/apiRoutes/datasets.ts index d6bac477a2..fb490bc42e 100644 --- a/adminSiteServer/apiRoutes/datasets.ts +++ b/adminSiteServer/apiRoutes/datasets.ts @@ -14,13 +14,6 @@ import { import { getDatasetById, setTagsForDataset } from "../../db/model/Dataset.js" import { logErrorAndMaybeSendToBugsnag } from "../../serverUtils/errorLog.js" import { expectInt } from "../../serverUtils/serverUtil.js" -import { apiRouter } from "../apiRouter.js" -import { - getRouteWithROTransaction, - putRouteWithRWTransaction, - postRouteWithRWTransaction, - deleteRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import { syncDatasetToGitRepo, removeDatasetFromGitRepo, @@ -413,19 +406,3 @@ export async function republishCharts( return { success: true } } - -getRouteWithROTransaction(apiRouter, "/datasets.json", getDatasets) -getRouteWithROTransaction(apiRouter, "/datasets/:datasetId.json", getDataset) -putRouteWithRWTransaction(apiRouter, "/datasets/:datasetId", updateDataset) -postRouteWithRWTransaction( - apiRouter, - "/datasets/:datasetId/setArchived", - setArchived -) -postRouteWithRWTransaction(apiRouter, "/datasets/:datasetId/setTags", setTags) -deleteRouteWithRWTransaction(apiRouter, "/datasets/:datasetId", deleteDataset) -postRouteWithRWTransaction( - apiRouter, - "/datasets/:datasetId/charts", - republishCharts -) diff --git a/adminSiteServer/apiRoutes/explorer.ts b/adminSiteServer/apiRoutes/explorer.ts index f0228fafff..44b9caf630 100644 --- a/adminSiteServer/apiRoutes/explorer.ts +++ b/adminSiteServer/apiRoutes/explorer.ts @@ -1,9 +1,4 @@ import { JsonError } from "@ourworldindata/types" -import { apiRouter } from "../apiRouter.js" -import { - postRouteWithRWTransaction, - deleteRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import { Request } from "express" import * as e from "express" @@ -36,11 +31,3 @@ export async function deleteExplorerTags( await trx.table("explorer_tags").where({ explorerSlug: slug }).delete() return { success: true } } - -postRouteWithRWTransaction(apiRouter, "/explorer/:slug/tags", addExplorerTags) - -deleteRouteWithRWTransaction( - apiRouter, - "/explorer/:slug/tags", - deleteExplorerTags -) diff --git a/adminSiteServer/apiRoutes/gdocs.ts b/adminSiteServer/apiRoutes/gdocs.ts index ed96cb2417..fbeb412e0d 100644 --- a/adminSiteServer/apiRoutes/gdocs.ts +++ b/adminSiteServer/apiRoutes/gdocs.ts @@ -42,14 +42,6 @@ import { } from "../../db/model/Gdoc/GdocFactory.js" import { GdocHomepage } from "../../db/model/Gdoc/GdocHomepage.js" import { GdocPost } from "../../db/model/Gdoc/GdocPost.js" -import { apiRouter } from "../apiRouter.js" -import { - getRouteWithROTransaction, - getRouteNonIdempotentWithRWTransaction, - putRouteWithRWTransaction, - deleteRouteWithRWTransaction, - postRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import { triggerStaticBuild, enqueueLightningChange } from "./routeUtils.js" import * as db from "../../db/db.js" import * as lodash from "lodash" @@ -295,17 +287,3 @@ export async function setGdocTags( return { success: true } } - -getRouteWithROTransaction(apiRouter, "/gdocs", getAllGdocIndexItems) - -getRouteNonIdempotentWithRWTransaction( - apiRouter, - "/gdocs/:id", - getIndividualGdoc -) - -putRouteWithRWTransaction(apiRouter, "/gdocs/:id", createOrUpdateGdoc) - -deleteRouteWithRWTransaction(apiRouter, "/gdocs/:id", deleteGdoc) - -postRouteWithRWTransaction(apiRouter, "/gdocs/:gdocId/setTags", setGdocTags) diff --git a/adminSiteServer/apiRoutes/images.ts b/adminSiteServer/apiRoutes/images.ts index 481415858f..63b55e5b05 100644 --- a/adminSiteServer/apiRoutes/images.ts +++ b/adminSiteServer/apiRoutes/images.ts @@ -1,14 +1,5 @@ import { DbEnrichedImage, JsonError } from "@ourworldindata/types" import pMap from "p-map" -import { apiRouter } from "../apiRouter.js" -import { - getRouteNonIdempotentWithRWTransaction, - postRouteWithRWTransaction, - putRouteWithRWTransaction, - patchRouteWithRWTransaction, - deleteRouteWithRWTransaction, - getRouteWithROTransaction, -} from "../functionalRouterHelpers.js" import { validateImagePayload, processImageContent, @@ -268,20 +259,3 @@ export async function getImageUsageHandler( usage, } } - -getRouteNonIdempotentWithRWTransaction( - apiRouter, - "/images.json", - getImagesHandler -) - -postRouteWithRWTransaction(apiRouter, "/images", postImageHandler) - -putRouteWithRWTransaction(apiRouter, "/images/:id", putImageHandler) - -// Update alt text via patch -patchRouteWithRWTransaction(apiRouter, "/images/:id", patchImageHandler) - -deleteRouteWithRWTransaction(apiRouter, "/images/:id", deleteImageHandler) - -getRouteWithROTransaction(apiRouter, "/images/usage", getImageUsageHandler) diff --git a/adminSiteServer/apiRoutes/mdims.ts b/adminSiteServer/apiRoutes/mdims.ts index 34a05595d2..39ec7ab35c 100644 --- a/adminSiteServer/apiRoutes/mdims.ts +++ b/adminSiteServer/apiRoutes/mdims.ts @@ -35,9 +35,3 @@ export async function handleMultiDimDataPageRequest( } return { success: true, id } } - -putRouteWithRWTransaction( - apiRouter, - "/multi-dim/:slug", - handleMultiDimDataPageRequest -) diff --git a/adminSiteServer/apiRoutes/misc.ts b/adminSiteServer/apiRoutes/misc.ts index a5ade731c0..a056c177aa 100644 --- a/adminSiteServer/apiRoutes/misc.ts +++ b/adminSiteServer/apiRoutes/misc.ts @@ -4,15 +4,11 @@ // [.secondary] section of the {.research-and-writing} block of author pages import { DbRawPostGdoc, JsonError } from "@ourworldindata/types" -import { apiRouter } from "../apiRouter.js" -import { getRouteWithROTransaction } from "../functionalRouterHelpers.js" import * as db from "../../db/db.js" import * as lodash from "lodash" import path from "path" -import { DeployQueueServer } from "../../baker/DeployQueueServer.js" import { expectInt } from "../../serverUtils/serverUtil.js" -import { triggerStaticBuild } from "./routeUtils.js" import { Request } from "../authentication.js" import e from "express" // using the alternate template, which highlights topics rather than articles. @@ -179,19 +175,3 @@ export async function fetchSourceById( return { source: source } } - -apiRouter.get("/deploys.json", async () => ({ - deploys: await new DeployQueueServer().getDeploys(), -})) - -apiRouter.put("/deploy", async (req, res) => { - return triggerStaticBuild(res.locals.user, "Manually triggered deploy") -}) - -getRouteWithROTransaction(apiRouter, "/all-work", fetchAllWork) -getRouteWithROTransaction( - apiRouter, - "/editorData/namespaces.json", - fetchNamespaces -) -getRouteWithROTransaction(apiRouter, "/sources/:sourceId.json", fetchSourceById) diff --git a/adminSiteServer/apiRoutes/posts.ts b/adminSiteServer/apiRoutes/posts.ts index efd31d99db..f34714fc30 100644 --- a/adminSiteServer/apiRoutes/posts.ts +++ b/adminSiteServer/apiRoutes/posts.ts @@ -13,11 +13,6 @@ import { upsertGdoc, setTagsForGdoc } from "../../db/model/Gdoc/GdocFactory.js" import { GdocPost } from "../../db/model/Gdoc/GdocPost.js" import { setTagsForPost, getTagsByPostId } from "../../db/model/Post.js" import { expectInt } from "../../serverUtils/serverUtil.js" -import { apiRouter } from "../apiRouter.js" -import { - getRouteWithROTransaction, - postRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import * as db from "../../db/db.js" import { Request } from "../authentication.js" import e from "express" @@ -218,25 +213,3 @@ export async function handleUnlinkGdoc( return { success: true } } - -getRouteWithROTransaction(apiRouter, "/posts.json", handleGetPostsJson) - -postRouteWithRWTransaction( - apiRouter, - "/posts/:postId/setTags", - handleSetTagsForPost -) - -getRouteWithROTransaction(apiRouter, "/posts/:postId.json", handleGetPostById) - -postRouteWithRWTransaction( - apiRouter, - "/posts/:postId/createGdoc", - handleCreateGdoc -) - -postRouteWithRWTransaction( - apiRouter, - "/posts/:postId/unlinkGdoc", - handleUnlinkGdoc -) diff --git a/adminSiteServer/apiRoutes/redirects.ts b/adminSiteServer/apiRoutes/redirects.ts index 00f8971b07..44452fe026 100644 --- a/adminSiteServer/apiRoutes/redirects.ts +++ b/adminSiteServer/apiRoutes/redirects.ts @@ -6,12 +6,6 @@ import { getRedirectById, } from "../../db/model/Redirect.js" import { expectInt } from "../../serverUtils/serverUtil.js" -import { apiRouter } from "../apiRouter.js" -import { - getRouteWithROTransaction, - postRouteWithRWTransaction, - deleteRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import { triggerStaticBuild } from "./routeUtils.js" import * as db from "../../db/db.js" import { Request } from "../authentication.js" @@ -151,35 +145,3 @@ export async function handleDeleteChartRedirect( return { success: true } } - -getRouteWithROTransaction( - apiRouter, - "/site-redirects.json", - handleGetSiteRedirects -) - -postRouteWithRWTransaction( - apiRouter, - "/site-redirects/new", - handlePostNewSiteRedirect -) - -deleteRouteWithRWTransaction( - apiRouter, - "/site-redirects/:id", - handleDeleteSiteRedirect -) - -getRouteWithROTransaction(apiRouter, "/redirects.json", handleGetRedirects) - -postRouteWithRWTransaction( - apiRouter, - "/charts/:chartId/redirects/new", - handlePostNewChartRedirect -) - -deleteRouteWithRWTransaction( - apiRouter, - "/redirects/:id", - handleDeleteChartRedirect -) diff --git a/adminSiteServer/apiRoutes/routeUtils.ts b/adminSiteServer/apiRoutes/routeUtils.ts index c9a8bbc908..0e647f290c 100644 --- a/adminSiteServer/apiRoutes/routeUtils.ts +++ b/adminSiteServer/apiRoutes/routeUtils.ts @@ -1,13 +1,6 @@ import { DbPlainUser } from "@ourworldindata/types" import { DeployQueueServer } from "../../baker/DeployQueueServer.js" import { BAKE_ON_CHANGE } from "../../settings/serverSettings.js" -import { References } from "../../adminSiteClient/AbstractChartEditor.js" -import { ChartViewMinimalInformation } from "../../adminSiteClient/ChartEditor.js" -import * as db from "../../db/db.js" -import { - getWordpressPostReferencesByChartId, - getGdocsPostReferencesByChartId, -} from "../../db/model/Post.js" // Call this to trigger build and deployment of static charts on change export const triggerStaticBuild = async ( diff --git a/adminSiteServer/apiRoutes/suggest.ts b/adminSiteServer/apiRoutes/suggest.ts index 657d0b6b1f..4a294d4328 100644 --- a/adminSiteServer/apiRoutes/suggest.ts +++ b/adminSiteServer/apiRoutes/suggest.ts @@ -1,5 +1,4 @@ import { - TaggableType, DbChartTagJoin, JsonError, DbEnrichedImage, @@ -7,8 +6,6 @@ import { import { parseIntOrUndefined } from "@ourworldindata/utils" import { getGptTopicSuggestions } from "../../db/model/Chart.js" import { CLOUDFLARE_IMAGES_URL } from "../../settings/clientSettings.js" -import { apiRouter } from "../apiRouter.js" -import { getRouteWithROTransaction } from "../functionalRouterHelpers.js" import { fetchGptGeneratedAltText } from "../imagesHelpers.js" import * as db from "../../db/db.js" import e from "express" @@ -65,15 +62,3 @@ export async function suggestGptAltText( return { success: true, altText } } - -getRouteWithROTransaction( - apiRouter, - `/gpt/suggest-topics/${TaggableType.Charts}/:chartId.json`, - suggestGptTopics -) - -getRouteWithROTransaction( - apiRouter, - `/gpt/suggest-alt-text/:imageId`, - suggestGptAltText -) diff --git a/adminSiteServer/apiRoutes/tagGraph.ts b/adminSiteServer/apiRoutes/tagGraph.ts index f4dfc8b7b2..bafeec6d51 100644 --- a/adminSiteServer/apiRoutes/tagGraph.ts +++ b/adminSiteServer/apiRoutes/tagGraph.ts @@ -1,10 +1,5 @@ import { JsonError, FlatTagGraph } from "@ourworldindata/types" import { checkIsPlainObjectWithGuard } from "@ourworldindata/utils" -import { apiRouter } from "../apiRouter.js" -import { - getRouteWithROTransaction, - postRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import * as db from "../../db/db.js" import * as lodash from "lodash" import { Request } from "../authentication.js" @@ -65,11 +60,3 @@ export async function handlePostTagGraph( await db.updateTagGraph(trx, tagGraph) res.send({ success: true }) } - -getRouteWithROTransaction( - apiRouter, - "/flatTagGraph.json", - handleGetFlatTagGraph -) - -postRouteWithRWTransaction(apiRouter, "/tagGraph", handlePostTagGraph) diff --git a/adminSiteServer/apiRoutes/tags.ts b/adminSiteServer/apiRoutes/tags.ts index 578209cfe2..40bec68cec 100644 --- a/adminSiteServer/apiRoutes/tags.ts +++ b/adminSiteServer/apiRoutes/tags.ts @@ -12,13 +12,6 @@ import { } from "../../db/model/Chart.js" import { expectInt } from "../../serverUtils/serverUtil.js" import { UNCATEGORIZED_TAG_ID } from "../../settings/serverSettings.js" -import { apiRouter } from "../apiRouter.js" -import { - getRouteWithROTransaction, - putRouteWithRWTransaction, - postRouteWithRWTransaction, - deleteRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import * as db from "../../db/db.js" import * as lodash from "lodash" import e from "express" @@ -266,9 +259,3 @@ export async function deleteTag( return { success: true } } - -getRouteWithROTransaction(apiRouter, "/tags/:tagId.json", getTagById) -putRouteWithRWTransaction(apiRouter, "/tags/:tagId", updateTag) -postRouteWithRWTransaction(apiRouter, "/tags/new", createTag) -getRouteWithROTransaction(apiRouter, "/tags.json", getAllTags) -deleteRouteWithRWTransaction(apiRouter, "/tags/:tagId/delete", deleteTag) diff --git a/adminSiteServer/apiRoutes/users.ts b/adminSiteServer/apiRoutes/users.ts index ea2016608e..e232fd15a3 100644 --- a/adminSiteServer/apiRoutes/users.ts +++ b/adminSiteServer/apiRoutes/users.ts @@ -3,13 +3,6 @@ import { parseIntOrUndefined } from "@ourworldindata/utils" import { pick } from "lodash" import { getUserById, updateUser, insertUser } from "../../db/model/User.js" import { expectInt } from "../../serverUtils/serverUtil.js" -import { apiRouter } from "../apiRouter.js" -import { - getRouteWithROTransaction, - deleteRouteWithRWTransaction, - putRouteWithRWTransaction, - postRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import * as db from "../../db/db.js" import { Request } from "../authentication.js" import e from "express" @@ -120,25 +113,3 @@ export async function removeUserImage( await trx("images").where({ id: imageId, userId }).update({ userId: null }) return { success: true } } - -getRouteWithROTransaction(apiRouter, "/users.json", getUsers) - -getRouteWithROTransaction(apiRouter, "/users/:userId.json", getUserByIdHandler) - -deleteRouteWithRWTransaction(apiRouter, "/users/:userId", deleteUser) - -putRouteWithRWTransaction(apiRouter, "/users/:userId", updateUserHandler) - -postRouteWithRWTransaction(apiRouter, "/users/add", addUser) - -postRouteWithRWTransaction( - apiRouter, - "/users/:userId/images/:imageId", - addImageToUser -) - -deleteRouteWithRWTransaction( - apiRouter, - "/users/:userId/images/:imageId", - removeUserImage -) diff --git a/adminSiteServer/apiRoutes/variables.ts b/adminSiteServer/apiRoutes/variables.ts index f8f21a65ab..d8f21c20ed 100644 --- a/adminSiteServer/apiRoutes/variables.ts +++ b/adminSiteServer/apiRoutes/variables.ts @@ -26,12 +26,6 @@ import { updateGrapherConfigETLOfVariable, } from "../../db/model/Variable.js" import { DATA_API_URL } from "../../settings/clientSettings.js" -import { apiRouter } from "../apiRouter.js" -import { - deleteRouteWithRWTransaction, - getRouteWithROTransaction, - putRouteWithRWTransaction, -} from "../functionalRouterHelpers.js" import * as db from "../../db/db.js" import { getParentVariableIdFromChartConfig, @@ -546,86 +540,3 @@ export async function getVariablesVariableIdChartsJson( isPublished: chart.isPublished, })) } - -getRouteWithROTransaction( - apiRouter, - "/editorData/variables.json", - getEditorVariablesJson -) - -getRouteWithROTransaction( - apiRouter, - "/data/variables/data/:variableStr.json", - getVariableDataJson -) - -getRouteWithROTransaction( - apiRouter, - "/data/variables/metadata/:variableStr.json", - getVariableMetadataJson -) - -getRouteWithROTransaction(apiRouter, "/variables.json", getVariablesJson) - -getRouteWithROTransaction( - apiRouter, - "/variables.usages.json", - getVariablesUsagesJson -) - -getRouteWithROTransaction( - apiRouter, - "/variables/grapherConfigETL/:variableId.patchConfig.json", - getVariablesGrapherConfigETLPatchConfigJson -) - -getRouteWithROTransaction( - apiRouter, - "/variables/grapherConfigAdmin/:variableId.patchConfig.json", - getVariablesGrapherConfigAdminPatchConfigJson -) - -getRouteWithROTransaction( - apiRouter, - "/variables/mergedGrapherConfig/:variableId.json", - getVariablesMergedGrapherConfigJson -) - -// Used in VariableEditPage -getRouteWithROTransaction( - apiRouter, - "/variables/:variableId.json", - getVariablesVariableIdJson -) - -// inserts a new config or updates an existing one -putRouteWithRWTransaction( - apiRouter, - "/variables/:variableId/grapherConfigETL", - putVariablesVariableIdGrapherConfigETL -) - -deleteRouteWithRWTransaction( - apiRouter, - "/variables/:variableId/grapherConfigETL", - deleteVariablesVariableIdGrapherConfigETL -) - -// inserts a new config or updates an existing one -putRouteWithRWTransaction( - apiRouter, - "/variables/:variableId/grapherConfigAdmin", - putVariablesVariableIdGrapherConfigAdmin -) - -deleteRouteWithRWTransaction( - apiRouter, - "/variables/:variableId/grapherConfigAdmin", - deleteVariablesVariableIdGrapherConfigAdmin -) - -getRouteWithROTransaction( - apiRouter, - "/variables/:variableId/charts.json", - getVariablesVariableIdChartsJson -)