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:
19
apps/dispatch/app/querys/connected-user.ts
Normal file
19
apps/dispatch/app/querys/connected-user.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ConnectedAircraft, ConnectedDispatcher, Prisma } from "@repo/db";
|
||||
import axios from "axios";
|
||||
|
||||
export const getConnectedUserAPI = async (
|
||||
filter?: Prisma.KeywordWhereInput,
|
||||
) => {
|
||||
const res = await axios.get<(ConnectedAircraft | ConnectedDispatcher)[]>(
|
||||
"/api/connected-user",
|
||||
{
|
||||
params: {
|
||||
filter: JSON.stringify(filter),
|
||||
},
|
||||
},
|
||||
);
|
||||
if (res.status !== 200) {
|
||||
throw new Error("Failed to fetch Connected User");
|
||||
}
|
||||
return res.data;
|
||||
};
|
||||
14
apps/dispatch/app/querys/keywords.ts
Normal file
14
apps/dispatch/app/querys/keywords.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Keyword, Prisma } from "@repo/db";
|
||||
import axios from "axios";
|
||||
|
||||
export const getKeywordsAPI = async (filter?: Prisma.KeywordWhereInput) => {
|
||||
const res = await axios.get<Keyword[]>("/api/keywords", {
|
||||
params: {
|
||||
filter: JSON.stringify(filter),
|
||||
},
|
||||
});
|
||||
if (res.status !== 200) {
|
||||
throw new Error("Failed to fetch keywords");
|
||||
}
|
||||
return res.data;
|
||||
};
|
||||
32
apps/dispatch/app/querys/missions.ts
Normal file
32
apps/dispatch/app/querys/missions.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Mission, Prisma } from "@repo/db";
|
||||
import axios from "axios";
|
||||
import { serverApi } from "helpers/axios";
|
||||
|
||||
export const getMissionsAPI = async (filter?: Prisma.MissionWhereInput) => {
|
||||
const res = await axios.get<Mission[]>("/api/missions", {
|
||||
params: {
|
||||
filter: JSON.stringify(filter),
|
||||
},
|
||||
});
|
||||
if (res.status !== 200) {
|
||||
throw new Error("Failed to fetch stations");
|
||||
}
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const createMissionAPI = async (mission: Prisma.MissionCreateInput) => {
|
||||
const response = await serverApi.put<Mission>("/mission", mission);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const editMissionAPI = async (
|
||||
id: number,
|
||||
mission: Prisma.MissionUpdateInput,
|
||||
) => {
|
||||
const respone = await serverApi.patch<Mission>(`/mission/${id}`, mission);
|
||||
return respone.data;
|
||||
};
|
||||
|
||||
export const deleteMissionAPI = async (id: number) => {
|
||||
await serverApi.delete(`/mission/${id}`);
|
||||
};
|
||||
14
apps/dispatch/app/querys/stations.ts
Normal file
14
apps/dispatch/app/querys/stations.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Prisma, Station } from "@repo/db";
|
||||
import axios from "axios";
|
||||
|
||||
export const getStationsAPI = async (filter?: Prisma.StationWhereInput) => {
|
||||
const res = await axios.get<Station[]>("/api/stations", {
|
||||
params: {
|
||||
filter: JSON.stringify(filter),
|
||||
},
|
||||
});
|
||||
if (res.status !== 200) {
|
||||
throw new Error("Failed to fetch stations");
|
||||
}
|
||||
return res.data;
|
||||
};
|
||||
Reference in New Issue
Block a user