From 32a0d895c4a473724ffe57cadfae5e89ca47b25c Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Tue, 28 Apr 2026 06:54:16 +0000 Subject: [PATCH] Fix missing RMO report store --- ts/rmo/store/publicreport.ts | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 ts/rmo/store/publicreport.ts diff --git a/ts/rmo/store/publicreport.ts b/ts/rmo/store/publicreport.ts new file mode 100644 index 00000000..5f4a9f3c --- /dev/null +++ b/ts/rmo/store/publicreport.ts @@ -0,0 +1,80 @@ +import { defineStore } from "pinia"; +import { ref } from "vue"; + +import { apiClient } from "@/client"; +import { + PublicReport, + type PublicReportComplianceCreateRequest, + type PublicReportDTO, + type PublicReportUpdate, +} from "@/type/api"; + +export const useStorePublicReport = defineStore("publicreport", () => { + // State + const _byID = ref>(new Map()); + const loading = ref(false); + //const ongoingFetch = ref | null>(null); + + function add(pr: PublicReport) { + _byID.value.set(pr.public_id, pr); + } + // Actions + async function byID(id: string): Promise { + const r = _byID.value.get(id); + if (r) { + return r; + } + return fetchByID(id); + } + async function byURI(uri: string): Promise { + const id = uri.split("/").pop() || ""; + if (!id) { + throw new Error(`${uri} is not a recognized public report URI`); + } + return byID(id); + } + async function createCompliance( + data: PublicReportComplianceCreateRequest, + ): Promise { + const resp = (await apiClient.JSONPost( + "/api/rmo/compliance", + data, + )) as PublicReportDTO; + const result = PublicReport.fromJSON(resp); + _byID.value.set(result.public_id, result); + return result; + } + async function fetchByID(id: string): Promise { + const uri = `/api/rmo/publicreport/${id}`; + return fetchByURI(uri); + } + async function fetchByURI(uri: string): Promise { + loading.value = true; + try { + const body = (await apiClient.JSONGet(uri)) as PublicReportDTO; + const report = PublicReport.fromJSON(body); + _byID.value.set(report.public_id, report); + return report; + } catch (err) { + console.error("Error loading users:", err); + throw err; + } + } + async function update( + uri: string, + updates: PublicReportUpdate, + ): Promise { + const resp = (await apiClient.JSONPut(uri, updates)) as PublicReportDTO; + return PublicReport.fromJSON(resp); + } + return { + // Actions + add, + byID, + byURI, + createCompliance, + fetchByID, + fetchByURI, + update, + }; +});