Skip to content

Commit

Permalink
🚧 remove typeorm annotations from GDocs classes
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Mar 6, 2024
1 parent 5d00c2b commit 0833773
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 49 deletions.
53 changes: 12 additions & 41 deletions db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,45 +65,19 @@ import {
getVariableOfDatapageIfApplicable,
} from "../Variable.js"

@Entity("tags")
export class Tag extends BaseEntity implements TagInterface {
static table = "tags"
@PrimaryColumn() id!: number
@Column() name!: string
@Column() createdAt!: Date
@Column({ nullable: true }) updatedAt!: Date
@Column({ nullable: true }) parentId!: number
@Column() isBulkImport!: boolean
@Column({ type: "varchar", nullable: true }) slug!: string | null
@Column() specialType!: string
@ManyToMany(() => GdocBase, (gdoc) => gdoc.tags)
gdocs!: GdocBase[]
}

@Entity("posts_gdocs")
export class GdocBase extends BaseEntity implements OwidGdocBaseInterface {
@PrimaryColumn() id!: string
@Column() slug: string = ""
@Column({ default: "{}", type: "json" }) content!: Record<string, any>
@Column() published: boolean = false
@Column() createdAt: Date = new Date()
@Column({ type: Date, nullable: true }) publishedAt: Date | null = null
@UpdateDateColumn({ nullable: true }) updatedAt: Date | null = null
@Column({ type: String, nullable: true }) revisionId: string | null = null
@Column({ type: String, nullable: true }) markdown: string | null = null
@Column() publicationContext: OwidGdocPublicationContext =
export class GdocBase implements OwidGdocBaseInterface {
id: string
slug: string = ""
content!: Record<string, any>
published: boolean = false
createdAt: Date = new Date()
publishedAt: Date | null = null
updatedAt: Date | null = null
revisionId: string | null = null
markdown: string | null = null
publicationContext: OwidGdocPublicationContext =
OwidGdocPublicationContext.unlisted
@Column({ type: "json", nullable: true }) breadcrumbs:
| BreadcrumbItem[]
| null = null
@ManyToMany(() => Tag, { cascade: true })
@JoinTable({
name: "posts_gdocs_x_tags",
joinColumn: { name: "gdocId", referencedColumnName: "id" },
inverseJoinColumn: { name: "tagId", referencedColumnName: "id" },
})
tags!: Tag[]

breadcrumbs: BreadcrumbItem[] | null = null
errors: OwidGdocErrorMessage[] = []
imageMetadata: Record<string, ImageMetadata> = {}
linkedCharts: Record<string, LinkedChart> = {}
Expand All @@ -123,7 +97,6 @@ export class GdocBase extends BaseEntity implements OwidGdocBaseInterface {
_loadSubclassAttachments: () => Promise<void> = async () => undefined

constructor(id?: string) {
super()
if (id) {
this.id = id
}
Expand All @@ -139,8 +112,6 @@ export class GdocBase extends BaseEntity implements OwidGdocBaseInterface {
return enrichedBlockSources
}

@BeforeUpdate()
@BeforeInsert()
updateMarkdown(): void {
try {
this.markdown =
Expand Down
2 changes: 0 additions & 2 deletions db/model/Gdoc/GdocDataInsight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import {
import { GdocBase } from "./GdocBase.js"
import * as db from "../../../db/db.js"

@Entity("posts_gdocs")
export class GdocDataInsight
extends GdocBase
implements OwidGdocDataInsightInterface
{
@Column({ default: "{}", type: "json" })
content!: OwidGdocDataInsightContent

constructor(id?: string) {
Expand Down
3 changes: 1 addition & 2 deletions db/model/Gdoc/GdocFaq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ interface InterfaceGdocFaq {
* instead of using the same endpoint for both posts and faqs.
* For now, we'll just use the GdocPost class.
*/
@Entity("posts_gdocs")
export class GdocFaq extends GdocBase {
static table = "posts_gdocs"
@Column({ default: "{}", type: "json" }) content!: InterfaceGdocFaq
content!: InterfaceGdocFaq

constructor(id?: string) {
super()
Expand Down
2 changes: 0 additions & 2 deletions db/model/Gdoc/GdocHomepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import * as db from "../../db.js"
import { OwidGdocHomepageMetadata } from "@ourworldindata/types"
import { UNIQUE_TOPIC_COUNT } from "../../../site/SiteNavigation.js"

@Entity("posts_gdocs")
export class GdocHomepage
extends GdocBase
implements OwidGdocHomepageInterface
{
@Column({ default: "{}", type: "json" })
content!: OwidGdocHomepageContent

constructor(id?: string) {
Expand Down
3 changes: 1 addition & 2 deletions db/model/Gdoc/GdocPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import { htmlToEnrichedTextBlock } from "./htmlToEnriched.js"
import { GdocBase } from "./GdocBase.js"
import { getConnection } from "../../db.js"

@Entity("posts_gdocs")
export class GdocPost extends GdocBase implements OwidGdocPostInterface {
@Column({ default: "{}", type: "json" }) content!: OwidGdocPostContent
content!: OwidGdocPostContent

constructor(id?: string) {
super(id)
Expand Down

0 comments on commit 0833773

Please sign in to comment.