feat: Implement connected user API and integrate chat and report components
- Added API routes for fetching connected users, keywords, missions, and stations. - Created a new QueryProvider component for managing query states and socket events. - Introduced connection stores for dispatch and pilot, managing socket connections and states. - Updated Prisma schema for connected aircraft model. - Enhanced UI with toast notifications for status updates and chat interactions. - Implemented query functions for fetching connected users and keywords with error handling.
This commit is contained in:
28
apps/dispatch/app/api/connected-user/route.ts
Normal file
28
apps/dispatch/app/api/connected-user/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@repo/db";
|
||||
|
||||
export async function GET(): Promise<NextResponse> {
|
||||
try {
|
||||
const connectedDispatcher = await prisma.connectedDispatcher.findMany({
|
||||
where: {
|
||||
logoutTime: null,
|
||||
},
|
||||
});
|
||||
|
||||
const connectedAircraft = await prisma.connectedAircraft.findMany({
|
||||
where: {
|
||||
logoutTime: null,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json([...connectedDispatcher, ...connectedAircraft], {
|
||||
status: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch connected User" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
25
apps/dispatch/app/api/keywords/route.ts
Normal file
25
apps/dispatch/app/api/keywords/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@repo/db";
|
||||
|
||||
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
const filter = searchParams.get("filter");
|
||||
|
||||
try {
|
||||
const data = await prisma.keyword.findMany({
|
||||
where: {
|
||||
id: id ? Number(id) : undefined,
|
||||
...(filter ? JSON.parse(filter) : {}),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(data, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch keyword" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
25
apps/dispatch/app/api/missions/route.ts
Normal file
25
apps/dispatch/app/api/missions/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@repo/db";
|
||||
|
||||
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
const filter = searchParams.get("filter");
|
||||
|
||||
try {
|
||||
const data = await prisma.mission.findMany({
|
||||
where: {
|
||||
id: id ? Number(id) : undefined,
|
||||
...(filter ? JSON.parse(filter) : {}),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(data, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch mission" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
25
apps/dispatch/app/api/stations/route.ts
Normal file
25
apps/dispatch/app/api/stations/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@repo/db";
|
||||
|
||||
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
const filter = searchParams.get("filter");
|
||||
|
||||
try {
|
||||
const data = await prisma.station.findMany({
|
||||
where: {
|
||||
id: id ? Number(id) : undefined,
|
||||
...(filter ? JSON.parse(filter) : {}),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(data, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch station" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user