From c6d2547cd29e901cc20c1db8bc1e6eb65cfed85b Mon Sep 17 00:00:00 2001 From: Matthieu Bergel Date: Thu, 9 May 2024 12:58:56 +0000 Subject: [PATCH] fix(gdoc): do not override subclass props if defined --- db/model/Gdoc/GdocDataInsight.ts | 3 ++- db/model/Gdoc/GdocHomepage.ts | 3 ++- db/model/Gdoc/GdocPost.ts | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/db/model/Gdoc/GdocDataInsight.ts b/db/model/Gdoc/GdocDataInsight.ts index cb7ffb42a33..4123a12156c 100644 --- a/db/model/Gdoc/GdocDataInsight.ts +++ b/db/model/Gdoc/GdocDataInsight.ts @@ -7,6 +7,7 @@ import { OwidGdocMinimalPostInterface, OwidGdocBaseInterface, excludeNullish, + defaults, } from "@ourworldindata/utils" import { GdocBase } from "./GdocBase.js" import * as db from "../../../db/db.js" @@ -27,7 +28,7 @@ export class GdocDataInsight static create(obj: OwidGdocBaseInterface): GdocDataInsight { const gdoc = new GdocDataInsight() - Object.assign(gdoc, obj) + defaults(gdoc, obj) // see GdocAuthor.ts for rationale return gdoc } diff --git a/db/model/Gdoc/GdocHomepage.ts b/db/model/Gdoc/GdocHomepage.ts index a0cbc6047d3..7e9c99f6fa0 100644 --- a/db/model/Gdoc/GdocHomepage.ts +++ b/db/model/Gdoc/GdocHomepage.ts @@ -5,6 +5,7 @@ import { OwidGdocHomepageInterface, OwidGdocMinimalPostInterface, OwidGdocType, + defaults, } from "@ourworldindata/utils" import { GdocBase } from "./GdocBase.js" import * as db from "../../db.js" @@ -28,7 +29,7 @@ export class GdocHomepage static create(obj: OwidGdocBaseInterface): GdocHomepage { const gdoc = new GdocHomepage() - Object.assign(gdoc, obj) + defaults(gdoc, obj) // see GdocAuthor.ts for rationale return gdoc } diff --git a/db/model/Gdoc/GdocPost.ts b/db/model/Gdoc/GdocPost.ts index 712625c11d7..b71aebddbd3 100644 --- a/db/model/Gdoc/GdocPost.ts +++ b/db/model/Gdoc/GdocPost.ts @@ -12,6 +12,7 @@ import { OwidGdocMinimalPostInterface, OwidGdocBaseInterface, excludeNullish, + defaults, } from "@ourworldindata/utils" import { GDOCS_DETAILS_ON_DEMAND_ID } from "../../../settings/serverSettings.js" import { @@ -37,7 +38,7 @@ export class GdocPost extends GdocBase implements OwidGdocPostInterface { } static create(obj: OwidGdocBaseInterface): GdocPost { const gdoc = new GdocPost() - Object.assign(gdoc, obj) + defaults(gdoc, obj) // see GdocAuthor.ts for rationale return gdoc } linkedDocuments: Record = {}