-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3120 from owid/homepage-gdoc
🎉 Homepage Gdoc type
- Loading branch information
Showing
26 changed files
with
716 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Entity, Column } from "typeorm" | ||
import * as db from "../../db" | ||
import { | ||
OwidGdocErrorMessage, | ||
OwidGdocErrorMessageType, | ||
OwidGdocHomepageContent, | ||
OwidGdocHomepageInterface, | ||
OwidGdocMinimalPostInterface, | ||
OwidGdocType, | ||
} from "@ourworldindata/utils" | ||
import { GdocBase } from "./GdocBase.js" | ||
|
||
@Entity("posts_gdocs") | ||
export class GdocHomepage | ||
extends GdocBase | ||
implements OwidGdocHomepageInterface | ||
{ | ||
@Column({ default: "{}", type: "json" }) | ||
content!: OwidGdocHomepageContent | ||
|
||
constructor(id?: string) { | ||
super() | ||
if (id) { | ||
this.id = id | ||
} | ||
} | ||
|
||
linkedDocuments: Record<string, OwidGdocMinimalPostInterface> = {} | ||
_urlProperties: string[] = [] | ||
|
||
_validateSubclass = async (): Promise<OwidGdocErrorMessage[]> => { | ||
const errors: OwidGdocErrorMessage[] = [] | ||
const otherPublishedHomepages = await db.knexRaw<{ id: string }>( | ||
` | ||
SELECT | ||
id | ||
FROM posts_gdocs | ||
WHERE content->>"$.type" = "${OwidGdocType.Homepage}" | ||
AND published = TRUE | ||
AND id != ?`, | ||
db.knexInstance(), | ||
[this.id] | ||
) | ||
if (otherPublishedHomepages.length > 0) { | ||
errors.push({ | ||
property: "published", | ||
message: `There can only be one published homepage. There is a homepage with the ID ${otherPublishedHomepages[0].id} that is already published.`, | ||
type: OwidGdocErrorMessageType.Error, | ||
}) | ||
} | ||
return errors | ||
} | ||
|
||
_loadSubclassAttachments = async (): Promise<void> => {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.