Add a resource for getting service requests
This commit is contained in:
parent
28ec1c3d67
commit
4a440e3022
18 changed files with 387 additions and 51 deletions
52
ts/store/service_request.ts
Normal file
52
ts/store/service_request.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { ServiceRequest } from "@/type/api";
|
||||
import { SSEManager, SSEMessage } from "@/SSEManager";
|
||||
import { useSessionStore } from "@/store/session";
|
||||
|
||||
export const useStoreServiceRequest = defineStore("service-request", () => {
|
||||
// State
|
||||
const all = ref<ServiceRequest[] | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref(null);
|
||||
|
||||
// Subscription
|
||||
SSEManager.subscribe((msg: SSEMessage) => {
|
||||
if (msg.resource.startsWith("sync:service-request")) {
|
||||
fetchAll();
|
||||
}
|
||||
});
|
||||
// Actions
|
||||
async function fetchAll(): Promise<ServiceRequest[]> {
|
||||
const session = useSessionStore();
|
||||
if (session.urls == null) {
|
||||
throw new Error("can't fetch without user URL data");
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
const response = await fetch(
|
||||
`${session.urls.api.service_request}?${params}`,
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = (await response.json()) as ServiceRequest[];
|
||||
all.value = data;
|
||||
return data;
|
||||
} catch (err) {
|
||||
console.error("Error loading communications:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return {
|
||||
// State
|
||||
all,
|
||||
// Actions
|
||||
fetchAll,
|
||||
};
|
||||
});
|
||||
|
|
@ -637,6 +637,77 @@ export interface Session {
|
|||
self: User;
|
||||
urls: URLs;
|
||||
}
|
||||
export interface ServiceRequestDTO {
|
||||
address: string;
|
||||
assigned_technician: string;
|
||||
city: string;
|
||||
created: string;
|
||||
h3cell: number;
|
||||
has_dog: boolean;
|
||||
has_spanish_speaker: boolean;
|
||||
id: string;
|
||||
priority: string;
|
||||
recorded_date: string;
|
||||
source: string;
|
||||
status: string;
|
||||
target: string;
|
||||
zip: string;
|
||||
}
|
||||
export interface ServiceRequestOptions {
|
||||
address: string;
|
||||
assigned_technician: string;
|
||||
city: string;
|
||||
created: Date;
|
||||
h3cell: number;
|
||||
has_dog: boolean;
|
||||
has_spanish_speaker: boolean;
|
||||
id: string;
|
||||
priority: string;
|
||||
recorded_date: Date;
|
||||
source: string;
|
||||
status: string;
|
||||
target: string;
|
||||
zip: string;
|
||||
}
|
||||
export class ServiceRequest {
|
||||
address: string;
|
||||
assigned_technician: string;
|
||||
city: string;
|
||||
created: Date;
|
||||
h3cell: number;
|
||||
has_dog: boolean;
|
||||
has_spanish_speaker: boolean;
|
||||
id: string;
|
||||
priority: string;
|
||||
recorded_date: Date;
|
||||
source: string;
|
||||
status: string;
|
||||
target: string;
|
||||
zip: string;
|
||||
constructor(options: ServiceRequestOptions) {
|
||||
this.address = options.address;
|
||||
this.assigned_technician = options.assigned_technician;
|
||||
this.city = options.city;
|
||||
this.created = options.created;
|
||||
this.h3cell = options.h3cell;
|
||||
this.has_dog = options.has_dog;
|
||||
this.has_spanish_speaker = options.has_spanish_speaker;
|
||||
this.id = options.id;
|
||||
this.priority = options.priority;
|
||||
this.recorded_date = options.recorded_date;
|
||||
this.source = options.source;
|
||||
this.status = options.status;
|
||||
this.target = options.target;
|
||||
this.zip = options.zip;
|
||||
}
|
||||
static fromJSON(json: ServiceRequestDTO): ServiceRequest {
|
||||
return new ServiceRequest({
|
||||
...json,
|
||||
created: new Date(json.created),
|
||||
recorded_date: new Date(json.recorded_date),
|
||||
});
|
||||
}
|
||||
}
|
||||
export interface SyncDTO {
|
||||
created: Date;
|
||||
id: string;
|
||||
|
|
@ -677,6 +748,7 @@ interface URLsAPI {
|
|||
impersonation: string;
|
||||
publicreport_message: string;
|
||||
review_task: string;
|
||||
service_request: string;
|
||||
signal: string;
|
||||
sync: string;
|
||||
upload: string;
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ import { onMounted, reactive } from "vue";
|
|||
import MapAggregate from "@/components/MapAggregate.vue";
|
||||
import { formatBigNumber, formatTimeRelative } from "@/format";
|
||||
import { useSessionStore } from "@/store/session";
|
||||
import { useStoreServiceRequest } from "@/store/service_request";
|
||||
import { useStoreSync } from "@/store/sync";
|
||||
import type { Bounds } from "@/type/api";
|
||||
|
||||
|
|
@ -181,9 +182,11 @@ const dashboard = reactive({
|
|||
},
|
||||
recentRequests: [],
|
||||
});
|
||||
const storeServiceRequest = useStoreServiceRequest();
|
||||
const storeSync = useStoreSync();
|
||||
const session = useSessionStore();
|
||||
onMounted(async () => {
|
||||
const service_requests = await storeServiceRequest.fetchAll();
|
||||
const syncs = await storeSync.fetchAll();
|
||||
console.log("syncs", syncs);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue