48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
import { INFO, ConsoleFormattedStream, createLogger as _createLogger, stdSerializers } from "browser-bunyan";
|
|
import { ListingCriteria } from "../../../../bizmatch-server/src/models/main.model";
|
|
import { BusinessListing, CommercialPropertyListing } from "../../../../bizmatch-server/src/models/db.model";
|
|
|
|
export function createGenericObject<T>(): T {
|
|
// Ein leeres Objekt vom Typ T erstellen
|
|
const ergebnis: Partial<T> = {};
|
|
|
|
// Für ein reales Interface funktioniert diese direkte Iteration nicht,
|
|
// da Interfaces zur Compile-Zeit entfernt werden. Stattdessen könnten Sie
|
|
// ein Dummy-Objekt oder spezifische Typtransformationen verwenden.
|
|
// Hier nur als Pseudocode dargestellt, um die Idee zu vermitteln:
|
|
for (const key in ergebnis) {
|
|
ergebnis[key] = null; // oder undefined, je nach Bedarf
|
|
}
|
|
|
|
return ergebnis as T;
|
|
}
|
|
|
|
export function createLogger(name:string, level: number = INFO, options:any = {}){
|
|
return _createLogger({
|
|
name,
|
|
streams:[{level, stream: new ConsoleFormattedStream()}],
|
|
serializers:stdSerializers,
|
|
src:true,
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export const getSessionStorageHandler = function(path,value,previous,applyData){
|
|
sessionStorage.setItem('criteria',JSON.stringify(this));
|
|
}
|
|
|
|
export function getCriteriaStateObject(){
|
|
const initialState = createGenericObject<ListingCriteria>();
|
|
const storedState = sessionStorage.getItem('criteria');
|
|
return storedState ? JSON.parse(storedState) : initialState;
|
|
}
|
|
|
|
export function getListingType(listing:BusinessListing|CommercialPropertyListing):'business'|'commercialProperty'{
|
|
return listing?.type<100?'business':'commercialProperty';
|
|
}
|
|
export function isBusinessListing(listing: BusinessListing | CommercialPropertyListing): listing is BusinessListing {
|
|
return listing?.type < 100;
|
|
}
|
|
export function isCommercialPropertyListing(listing: BusinessListing | CommercialPropertyListing): listing is CommercialPropertyListing {
|
|
return listing?.type >= 100;
|
|
} |