From faa7fafe68126fac712dfb0f8f3a7a536a72f79c Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Thu, 25 Jul 2024 01:42:22 +0200 Subject: [PATCH] make filterObjectsByStringEntries and checkDoesObjectMatchReference work with FileContent --- src/Model/Files/fileModel.ts | 3 ++- src/Model/Utility/utility.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Model/Files/fileModel.ts b/src/Model/Files/fileModel.ts index 42f7c795..16b02576 100644 --- a/src/Model/Files/fileModel.ts +++ b/src/Model/Files/fileModel.ts @@ -3,6 +3,7 @@ import { DATA_VERSION, ValidObject } from "../Utility/typeSafety"; import { HandlerManager, + StringEntryObject, createTimestamp, parseValidObject, stringify, @@ -175,7 +176,7 @@ export enum FileModelSubPath { }; // types -export interface FileContent extends ValidObject { +export interface FileContent extends ValidObject, StringEntryObject { fileId: string; fileContentId: string; creationDate: string; diff --git a/src/Model/Utility/utility.ts b/src/Model/Utility/utility.ts index 5b35d4ec..9a309a8b 100644 --- a/src/Model/Utility/utility.ts +++ b/src/Model/Utility/utility.ts @@ -29,7 +29,8 @@ export class HandlerManager { } // objects -export type StringEntryObject = { [key: string]: string }; +export type StringEntryObject = { [key: string]: string | undefined }; + export function filterObjectsByStringEntries( reference: StringEntryObject, converter: (T) => StringEntryObject, @@ -56,7 +57,10 @@ export function checkDoesObjectMatchReference( reference )) { const [referenceKey, referenceValue] = referenceEntry; - const stringEntryObjectValue: string = stringEntryObject[referenceKey]; + const stringEntryObjectValue: string | undefined = + stringEntryObject[referenceKey]; + + if (referenceValue == undefined) return false; if (referenceValue[0] == "-") { const strippedReferenceValue: string = referenceValue.substring(1); @@ -102,7 +106,7 @@ export function collectObjectValuesForKey( for (const object of objects) { const stringEntryObject: StringEntryObject = converter(object); - const stringEntryObjectValue: string = stringEntryObject[key]; + const stringEntryObjectValue: string | undefined = stringEntryObject[key]; if (stringEntryObjectValue == undefined || stringEntryObjectValue == "") continue;