Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove remaining TypeORM call #3463

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ import { DeployQueueServer } from "../baker/DeployQueueServer.js"
import { FunctionalRouter } from "./FunctionalRouter.js"
import Papa from "papaparse"
import {
postsTable,
setTagsForPost,
getTagsByPostId,
getWordpressPostReferencesByChartId,
Expand All @@ -111,7 +110,6 @@ import {
checkHasChanges,
checkIsLightningUpdate,
} from "../adminSiteClient/gdocsDeploy.js"
import { dataSource } from "../db/dataSource.js"
import { createGdocAndInsertOwidGdocPostContent } from "../db/model/Gdoc/archieToGdoc.js"
import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js"
import {
Expand Down Expand Up @@ -2162,7 +2160,7 @@ postRouteWithRWTransaction(
// which means that we can't wrap this in a transaction. We should probably
// move posts to use typeorm as well or at least have a typeorm alternative for it
await trx
.table(postsTable)
.table(PostsTableName)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting complex logic into separate functions or modules.

The logic for creating or updating Google Docs based on posts appears complex and is embedded within a large function. Extracting this logic into separate, well-named functions or even a dedicated module could improve readability, maintainability, and testability.

.where({ id: postId })
.update("gdocSuccessorId", gdocId)

Expand Down Expand Up @@ -2205,11 +2203,14 @@ postRouteWithRWTransaction(
// which means that we can't wrap this in a transaction. We should probably
// move posts to use typeorm as well or at least have a typeorm alternative for it
await trx
.table(postsTable)
.table(PostsTableName)
.where({ id: postId })
.update("gdocSuccessorId", null)

await dataSource.getRepository(GdocPost).delete(existingGdocId)
await trx
.table(PostsGdocsTableName)
.where({ id: existingGdocId })
.delete()

return { success: true }
}
Expand Down