From 20a86114e8d8d63463005f6e5d50a30520b6907c Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Thu, 28 Mar 2024 09:53:29 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9D=20(db)=20add=20type=20and=20sort?= =?UTF-8?q?=20to=20db=20type=20definitions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../types/src/dbTypes/Variables.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/@ourworldindata/types/src/dbTypes/Variables.ts b/packages/@ourworldindata/types/src/dbTypes/Variables.ts index 7f0fd857b61..ce241a997c8 100644 --- a/packages/@ourworldindata/types/src/dbTypes/Variables.ts +++ b/packages/@ourworldindata/types/src/dbTypes/Variables.ts @@ -1,3 +1,4 @@ +import { OwidVariableType } from "../OwidVariable.js" import { OwidVariableDisplayConfigInterface } from "../OwidVariableDisplayConfigInterface.js" import { JsonString } from "../domainTypes/Various.js" import { GrapherInterface } from "../grapherTypes/GrapherTypes.js" @@ -37,7 +38,10 @@ export interface DbInsertVariable { titleVariant?: string | null unit: string updatedAt?: Date | null + type?: OwidVariableType | null + sort?: JsonString | null } + export type DbRawVariable = Required export interface VariableDisplayDimension { @@ -65,6 +69,7 @@ export type DbEnrichedVariable = Omit< | "grapherConfigAdmin" | "grapherConfigETL" | "processingLog" + | "sort" > & { display: OwidVariableDisplayConfigInterface license: License | null @@ -75,6 +80,7 @@ export type DbEnrichedVariable = Omit< grapherConfigAdmin: GrapherInterface | null grapherConfigETL: GrapherInterface | null processingLog: unknown | null + sort: string[] | null } export function parseVariableDisplayConfig( @@ -179,6 +185,16 @@ export function serializeVariableProcessingLog( return processingLog ? JSON.stringify(processingLog) : null } +export function parseVariableSort(sort: JsonString | null): string[] | null { + return sort ? JSON.parse(sort) : null +} + +export function serializeVariableSort( + sort: string[] | null +): JsonString | null { + return sort ? JSON.stringify(sort) : null +} + export function parseVariablesRow(row: DbRawVariable): DbEnrichedVariable { return { ...row, @@ -193,6 +209,7 @@ export function parseVariablesRow(row: DbRawVariable): DbEnrichedVariable { ), grapherConfigETL: parseVariableGrapherConfigETL(row.grapherConfigETL), processingLog: parseVariableProcessingLog(row.processingLog), + sort: parseVariableSort(row.sort), } } @@ -214,5 +231,6 @@ export function serializeVariablesRow(row: DbEnrichedVariable): DbRawVariable { row.grapherConfigETL ), processingLog: serializeVariableProcessingLog(row.processingLog), + sort: serializeVariableSort(row.sort), } }