removed AircraftID, Added NExtcloud permission

This commit is contained in:
PxlLoewe
2025-06-30 13:37:42 -07:00
parent b940b70839
commit 536d214840
15 changed files with 58 additions and 39 deletions

View File

@@ -5,18 +5,12 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
try { try {
const connectedAircraftId = request.nextUrl.searchParams.get("connectedAircraftId"); const connectedAircraftId = request.nextUrl.searchParams.get("connectedAircraftId");
const aircraft = await prisma.connectedAircraft.findUnique({ if (!connectedAircraftId)
where: { return NextResponse.json({ error: "connectedAircraftId is required" }, { status: 400 });
id: connectedAircraftId ? parseInt(connectedAircraftId) : undefined,
},
});
if (!aircraft) return NextResponse.json({ error: "Aircraft not found" }, { status: 404 });
const positionLog = await prisma.positionLog.findMany({ const positionLog = await prisma.positionLog.findMany({
where: { where: {
id: { connectedAircraftId: Number(connectedAircraftId),
in: aircraft.positionLogIds,
},
timestamp: { timestamp: {
gte: new Date(Date.now() - 2 * 60 * 60 * 1000), // Last 2 hours gte: new Date(Date.now() - 2 * 60 * 60 * 1000), // Last 2 hours
}, },

View File

@@ -44,9 +44,11 @@ export const PUT = async (req: Request) => {
if (!activeAircraft) { if (!activeAircraft) {
return Response.json({ message: "No active aircraft found" }, { status: 400 }); return Response.json({ message: "No active aircraft found" }, { status: 400 });
} }
const positionLog = await prisma.positionLog.create({ const positionLog = await prisma.positionLog.create({
data: { data: {
...position, ...position,
connectedAircraftId: activeAircraft.id,
userId, userId,
}, },
}); });
@@ -64,9 +66,6 @@ export const PUT = async (req: Request) => {
posHeading: positionLog.heading, posHeading: positionLog.heading,
posSpeed: positionLog.speed, posSpeed: positionLog.speed,
posH145active: h145, posH145active: h145,
positionLogIds: {
push: positionLog.id,
},
}, },
}); });

View File

@@ -54,7 +54,7 @@ const styles = `
`; `;
const PenaltyNoticeTemplate = ({ user, staffName }: { user: User; staffName: string }) => ( const PenaltyNoticeTemplate = ({ user, staffName }: { user: User; staffName: string }) => (
<Html lang="de"> <html lang="de">
<meta content="text/html; charset=utf-8" httpEquiv="Content-Type" /> <meta content="text/html; charset=utf-8" httpEquiv="Content-Type" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link <link
@@ -158,7 +158,7 @@ const PenaltyNoticeTemplate = ({ user, staffName }: { user: User; staffName: str
</tbody> </tbody>
</table> </table>
</body> </body>
</Html> </html>
); );
export function renderBannNotice({ user, staffName }: { user: User; staffName: string }) { export function renderBannNotice({ user, staffName }: { user: User; staffName: string }) {

View File

@@ -65,7 +65,7 @@ const styles = `
`; `;
const Template = ({ user, code }: { user: User; code: string }) => ( const Template = ({ user, code }: { user: User; code: string }) => (
<Html lang="de"> <html lang="de">
<meta content="text/html; charset=utf-8" httpEquiv="Content-Type" /> <meta content="text/html; charset=utf-8" httpEquiv="Content-Type" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link <link
@@ -191,7 +191,7 @@ const Template = ({ user, code }: { user: User; code: string }) => (
</tbody> </tbody>
</table> </table>
</body> </body>
</Html> </html>
); );
export function renderVerificationCode({ user, code }: { user: User; code: string }) { export function renderVerificationCode({ user, code }: { user: User; code: string }) {

View File

@@ -66,7 +66,7 @@ const styles = `
`; `;
const Template = ({ event, user }: { user: User; event: Event }) => ( const Template = ({ event, user }: { user: User; event: Event }) => (
<Html lang="de"> <html lang="de">
<meta content="text/html; charset=utf-8" httpEquiv="Content-Type" /> <meta content="text/html; charset=utf-8" httpEquiv="Content-Type" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link <link
@@ -142,7 +142,7 @@ const Template = ({ event, user }: { user: User; event: Event }) => (
</tbody> </tbody>
</table> </table>
</body> </body>
</Html> </html>
); );
export function renderCourseCompleted({ user, event }: { user: User; event: Event }) { export function renderCourseCompleted({ user, event }: { user: User; event: Event }) {

View File

@@ -65,7 +65,7 @@ const styles = `
`; `;
const Template = ({ user, password }: { user: User; password: string }) => ( const Template = ({ user, password }: { user: User; password: string }) => (
<Html lang="de"> <html lang="de">
<meta content="text/html; charset=utf-8" httpEquiv="Content-Type" /> <meta content="text/html; charset=utf-8" httpEquiv="Content-Type" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link <link
@@ -148,7 +148,7 @@ const Template = ({ user, password }: { user: User; password: string }) => (
</tbody> </tbody>
</table> </table>
</body> </body>
</Html> </html>
); );
export function renderPasswordChanged({ user, password }: { user: User; password: string }) { export function renderPasswordChanged({ user, password }: { user: User; password: string }) {

View File

@@ -54,7 +54,7 @@ const styles = `
`; `;
const TimeBanTemplate = ({ user, staffName }: { user: User; staffName: string }) => ( const TimeBanTemplate = ({ user, staffName }: { user: User; staffName: string }) => (
<Html lang="de"> <html lang="de">
<meta content="text/html; charset=utf-8" httpEquiv="Content-Type" /> <meta content="text/html; charset=utf-8" httpEquiv="Content-Type" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link <link
@@ -160,7 +160,7 @@ const TimeBanTemplate = ({ user, staffName }: { user: User; staffName: string })
</tbody> </tbody>
</table> </table>
</body> </body>
</Html> </html>
); );
export function renderTimeBanNotice({ user, staffName }: { user: User; staffName: string }) { export function renderTimeBanNotice({ user, staffName }: { user: User; staffName: string }) {

View File

@@ -1,10 +1,14 @@
{ {
"extends": "@repo/typescript-config/nextjs.json", "extends": "@repo/typescript-config/base.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "outDir": "dist",
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx", "jsx": "react-jsx",
"noEmit": true,
"baseUrl": ".",
"types": ["node", "react"] "types": ["node", "react"]
}, },
"include": ["."], "include": ["**/*.ts", "./index.ts", "**/*.d.ts"],
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist"]
} }

View File

@@ -56,5 +56,6 @@ export const GET = async (req: NextRequest) => {
return NextResponse.json({ return NextResponse.json({
...user, ...user,
moodleLastname: `${user?.lastname.split("")[0]}. - ${user?.publicId}`, moodleLastname: `${user?.lastname.split("")[0]}. - ${user?.publicId}`,
fullName: `${user?.firstname} ${user?.lastname} - ${user?.publicId}`,
}); });
}; };

View File

@@ -28,6 +28,6 @@ export const services = [
"https://nextcloud.virtualairrescue.com", "https://nextcloud.virtualairrescue.com",
"http://nextcloud.virtualairrescue.com/", "http://nextcloud.virtualairrescue.com/",
], ],
requiredPermissions: ["ADMIN_USER"], requiredPermissions: ["LOGIN_NEXTCLOUD"],
}, },
]; ];

View File

@@ -16,9 +16,9 @@ model ConnectedAircraft {
loginTime DateTime @default(now()) loginTime DateTime @default(now())
esimatedLogoutTime DateTime? esimatedLogoutTime DateTime?
logoutTime DateTime? logoutTime DateTime?
positionLogIds Int[] @default([])
// relations: // relations:
User User @relation(fields: [userId], references: [id], onDelete: Cascade) User User @relation(fields: [userId], references: [id], onDelete: Cascade)
Station Station @relation(fields: [stationId], references: [id], onDelete: Cascade) Station Station @relation(fields: [stationId], references: [id], onDelete: Cascade)
PositionLog PositionLog[]
} }

View File

@@ -0,0 +1,7 @@
DELETE FROM "PositionLog";
DELETE FROM "ConnectedAircraft";
ALTER TABLE "PositionLog" ADD COLUMN "connectedAircraftId" INTEGER NOT NULL;
-- AddForeignKey
ALTER TABLE "PositionLog" ADD CONSTRAINT "PositionLog_connectedAircraftId_fkey" FOREIGN KEY ("connectedAircraftId") REFERENCES "ConnectedAircraft"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,11 @@
/*
Warnings:
- You are about to drop the column `positionLogIds` on the `ConnectedAircraft` table. All the data in the column will be lost.
*/
-- AlterEnum
ALTER TYPE "PERMISSION" ADD VALUE 'LOGIN_NEXTCLOUD';
-- AlterTable
ALTER TABLE "ConnectedAircraft" DROP COLUMN "positionLogIds";

View File

@@ -1,13 +1,15 @@
model PositionLog { model PositionLog {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
userId String userId String
simulator String connectedAircraftId Int
lat Float simulator String
lng Float lat Float
alt Int lng Float
speed Int alt Int
heading Int speed Int
timestamp DateTime @default(now()) heading Int
timestamp DateTime @default(now())
// relations: // relations:
user User @relation(fields: [userId], references: [id], onDelete: Cascade) User User @relation(fields: [userId], references: [id], onDelete: Cascade)
ConnectedAircraft ConnectedAircraft @relation(fields: [connectedAircraftId], references: [id], onDelete: Cascade)
} }

View File

@@ -20,6 +20,7 @@ enum PERMISSION {
AUDIO AUDIO
PILOT PILOT
DISPO DISPO
LOGIN_NEXTCLOUD
} }
model User { model User {