Use the same create logic for Mailer report creation
This commit is contained in:
parent
f927b0a911
commit
bd3e42f83e
4 changed files with 13 additions and 24 deletions
|
|
@ -59,12 +59,13 @@ async function doMounted() {
|
|||
console.error("failed to find matching district", props.slug, districts);
|
||||
return;
|
||||
}
|
||||
const report = await storePublicReport.create({
|
||||
const report = await storePublicReport.createCompliance({
|
||||
client_id: client_id,
|
||||
district: district.uri,
|
||||
});
|
||||
storeLocal.setExistingComplianceReportURI(report.uri);
|
||||
router.replace(`/compliance/${report.public_id}`);
|
||||
console.log("Created new compliance report", report);
|
||||
}
|
||||
onMounted(() => {
|
||||
doMounted();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import type { Image } from "@/components/ImageUpload.vue";
|
|||
import { useStoreDistrict } from "@/rmo/store/district";
|
||||
import { useStoreLocal } from "@/store/local";
|
||||
import { useStoreLocation } from "@/store/location";
|
||||
import { useStorePublicReport } from "@/store/publicreport";
|
||||
import Intro from "@/rmo/content/compliance/Intro.vue";
|
||||
import LoadingOverlay from "@/components/LoadingOverlay.vue";
|
||||
import {
|
||||
|
|
@ -40,30 +41,17 @@ const districtStore = useStoreDistrict();
|
|||
const props = defineProps<Props>();
|
||||
const router = useRouter();
|
||||
const storeLocal = useStoreLocal();
|
||||
async function createReport(
|
||||
client_id: string,
|
||||
): Promise<PublicReportCompliance> {
|
||||
let content = {
|
||||
client_id: client_id,
|
||||
mailer_id: props.public_id,
|
||||
};
|
||||
const resp = await fetch("/api/rmo/compliance", {
|
||||
body: JSON.stringify(content),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
const body = (await resp.json()) as PublicReportComplianceOptions;
|
||||
return new PublicReportCompliance(body);
|
||||
}
|
||||
const storePublicReport = useStorePublicReport();
|
||||
async function doMounted() {
|
||||
const client_id = storeLocal.getClientID();
|
||||
const report_uri = storeLocal.getExistingComplianceReportURI();
|
||||
if (report_uri && report_uri.endsWith(props.public_id)) {
|
||||
console.log("Loading previous report", report_uri);
|
||||
} else {
|
||||
const report = await createReport(client_id);
|
||||
const report = await storePublicReport.createCompliance({
|
||||
client_id: client_id,
|
||||
mailer_id: props.public_id,
|
||||
});
|
||||
storeLocal.setExistingComplianceReportURI(report.uri);
|
||||
console.log("Created new compliance report", report);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { ref } from "vue";
|
|||
import { apiClient } from "@/client";
|
||||
import {
|
||||
PublicReport,
|
||||
type PublicReportCreateRequest,
|
||||
type PublicReportComplianceCreateRequest,
|
||||
type PublicReportDTO,
|
||||
} from "@/type/api";
|
||||
|
||||
|
|
@ -43,8 +43,8 @@ export const useStorePublicReport = defineStore("publicreport", () => {
|
|||
}
|
||||
return byID(id);
|
||||
}
|
||||
async function create(
|
||||
data: PublicReportCreateRequest,
|
||||
async function createCompliance(
|
||||
data: PublicReportComplianceCreateRequest,
|
||||
): Promise<PublicReport> {
|
||||
const resp = (await apiClient.JSONPost(
|
||||
"/api/rmo/compliance",
|
||||
|
|
@ -59,6 +59,6 @@ export const useStorePublicReport = defineStore("publicreport", () => {
|
|||
add,
|
||||
byID,
|
||||
byURI,
|
||||
create,
|
||||
createCompliance,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ export interface PublicReportDTO {
|
|||
//water?: Water;
|
||||
uri: string;
|
||||
}
|
||||
export interface PublicReportCreateRequest {
|
||||
export interface PublicReportComplianceCreateRequest {
|
||||
client_id: string;
|
||||
district?: string;
|
||||
mailer_id?: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue