make filterObjectsByStringEntries and checkDoesObjectMatchReference work with FileContent

This commit is contained in:
marlon-erler
2024-07-25 01:42:22 +02:00
parent 538cc4f9e0
commit faa7fafe68
2 changed files with 9 additions and 4 deletions
+2 -1
View File
@@ -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<T extends string> extends ValidObject {
export interface FileContent<T extends string> extends ValidObject, StringEntryObject {
fileId: string;
fileContentId: string;
creationDate: string;
+7 -3
View File
@@ -29,7 +29,8 @@ export class HandlerManager<T> {
}
// objects
export type StringEntryObject = { [key: string]: string };
export type StringEntryObject = { [key: string]: string | undefined };
export function filterObjectsByStringEntries<T>(
reference: StringEntryObject,
converter: (T) => StringEntryObject,
@@ -56,7 +57,10 @@ export function checkDoesObjectMatchReference<T>(
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<T>(
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;