import { healthService } from 'App/services'; import { categoryKeyNames, lastAskedKey, healthResponseKey } from "Components/Header/HealthStatus/const"; import { IServiceStats } from "Components/Header/HealthStatus/HealthStatus"; function mapResponse(resp: Record) { const services = Object.keys(resp); const healthMap: Record = {}; services.forEach((service) => { healthMap[service] = { // @ts-ignore name: categoryKeyNames[service], healthOk: true, subservices: resp[service], serviceName: service, }; Object.values(healthMap[service].subservices).forEach((subservice: Record) => { if (!subservice?.health) healthMap[service].healthOk = false; }); }); const overallHealth = Object.values(healthMap).every( (service: Record) => service.healthOk ); return { overallHealth, healthMap }; } export async function getHealthRequest(isPublic?: boolean) { const r = await healthService.fetchStatus(isPublic); const healthMap = mapResponse(r); const asked = new Date().getTime(); localStorage.setItem(healthResponseKey, JSON.stringify(healthMap)); localStorage.setItem(lastAskedKey, asked.toString()); return { healthMap, asked } }