Merge branch 'main' of https://github.com/VAR-Virtual-Air-Rescue/var-monorepo
This commit is contained in:
@@ -1,19 +1,25 @@
|
|||||||
import { ConnectedAircraft, ConnectedDispatcher, Prisma } from "@repo/db";
|
import { ConnectedAircraft, ConnectedDispatcher, Prisma } from "@repo/db";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export const getConnectedUserAPI = async (
|
export const getConnectedUserAPI = async () => {
|
||||||
filter?: Prisma.KeywordWhereInput,
|
|
||||||
) => {
|
|
||||||
const res = await axios.get<(ConnectedAircraft | ConnectedDispatcher)[]>(
|
const res = await axios.get<(ConnectedAircraft | ConnectedDispatcher)[]>(
|
||||||
"/api/connected-user",
|
"/api/connected-user",
|
||||||
{
|
{},
|
||||||
params: {
|
|
||||||
filter: JSON.stringify(filter),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
throw new Error("Failed to fetch Connected User");
|
throw new Error("Failed to fetch Connected User");
|
||||||
}
|
}
|
||||||
return res.data;
|
return res.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getConnectedDispatcherAPI = async (filter?: Prisma.ConnectedDispatcherWhereInput) => {
|
||||||
|
const res = await axios.get<ConnectedDispatcher[]>("/api/dispatcher", {
|
||||||
|
params: {
|
||||||
|
filter: JSON.stringify(filter),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error("Failed to fetch Connected Dispatcher");
|
||||||
|
}
|
||||||
|
return res.data;
|
||||||
|
};
|
||||||
|
|||||||
36
apps/dispatch/app/api/dispatcher/route.ts
Normal file
36
apps/dispatch/app/api/dispatcher/route.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { getPublicUser, Prisma, prisma } from "@repo/db";
|
||||||
|
|
||||||
|
export async function GET(request: Request): Promise<NextResponse> {
|
||||||
|
try {
|
||||||
|
const filter = JSON.parse(
|
||||||
|
new URL(request.url).searchParams.get("filter") || "{}",
|
||||||
|
) as Prisma.ConnectedDispatcherWhereInput;
|
||||||
|
|
||||||
|
const connectedDispatcher = await prisma.connectedDispatcher.findMany({
|
||||||
|
where: {
|
||||||
|
logoutTime: null,
|
||||||
|
...filter, // Ensure filter is parsed correctly
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
user: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
connectedDispatcher.map((d) => {
|
||||||
|
return {
|
||||||
|
...d,
|
||||||
|
user: undefined,
|
||||||
|
publicUser: getPublicUser(d.user),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return NextResponse.json({ error: "Failed to fetch Dispatchers" }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { getConnectedDispatcherAPI } from "_querys/connected-user";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
export const ConnectedDispatcher = () => {
|
export const ConnectedDispatcher = () => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const {} = useQuery({
|
const { data: dispatcher } = useQuery({
|
||||||
queryKey: [""],
|
queryKey: ["dispatcher"],
|
||||||
|
queryFn: () => getConnectedDispatcherAPI(),
|
||||||
|
refetchInterval: 10000,
|
||||||
});
|
});
|
||||||
|
console.log("ConnectedDispatcher", dispatcher);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute top-5 right-10 min-w-120 z-99999">
|
<div className="absolute top-5 right-10 min-w-120 z-99999">
|
||||||
|
|||||||
Reference in New Issue
Block a user