diff --git a/src/app/actions/violationActions.ts b/src/app/actions/violationActions.ts index 5110136..66347b7 100644 --- a/src/app/actions/violationActions.ts +++ b/src/app/actions/violationActions.ts @@ -612,4 +612,74 @@ export async function createCase( errorMessage: errors } } +} + +export async function fetchLastCase() { + const token = await getSessionData('token'); + + try { + const response = await fetch(`${API_BASE_URL}/api/v1/data`, { + method: 'POST', + body: JSON.stringify({ + version: 1, + msg_id: 30017, + message_body: { + action: "get_all", + token: token + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + let parsed = await response.json(); + if (parsed) { + return parsed; + } else { + throw null; + } + } else { + throw (`${response.status}`); + } + } catch (error) { + return null + } +} + +export async function fetchLastComplaint() { + const token = await getSessionData('token'); + + try { + const response = await fetch(`${API_BASE_URL}/api/v1/data`, { + method: 'POST', + body: JSON.stringify({ + version: 1, + msg_id: 30017, + message_body: { + action: "get_all", + token: token + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + let parsed = await response.json(); + if (parsed) { + return parsed; + } else { + throw null; + } + } else { + throw (`${response.status}`); + } + } catch (error) { + return null + } } \ No newline at end of file diff --git a/src/app/hooks/react-query/useLastCases.ts b/src/app/hooks/react-query/useLastCases.ts new file mode 100644 index 0000000..ce3cc69 --- /dev/null +++ b/src/app/hooks/react-query/useLastCases.ts @@ -0,0 +1,22 @@ +import { useQuery } from '@tanstack/react-query'; +import { fetchLastCase } from '@/app/actions/violationActions'; + +export interface useLastCase { + test: number, +} + +export const useLastCases = () => { + return useQuery({ + queryKey: ['lastCases'], + queryFn: () => { + return fetchLastCase() + }, + select: (data: useLastCase | null) => { + if (!data) { + return null + } + return data; + }, + retry: false + }); +}; \ No newline at end of file diff --git a/src/app/hooks/react-query/useLastComplaints.ts b/src/app/hooks/react-query/useLastComplaints.ts new file mode 100644 index 0000000..145deeb --- /dev/null +++ b/src/app/hooks/react-query/useLastComplaints.ts @@ -0,0 +1,22 @@ +import { useQuery } from '@tanstack/react-query'; +import { fetchLastComplaint } from '@/app/actions/violationActions'; + +export interface useLastComplaint { + test: number, +} + +export const useLastComplaints = () => { + return useQuery({ + queryKey: ['lastComplaints'], + queryFn: () => { + return fetchLastComplaint() + }, + select: (data: useLastComplaint | null) => { + if (!data) { + return null + } + return data; + }, + retry: false + }); +}; \ No newline at end of file