diff --git a/apps/dispatch/app/api/aircrafts/positionlog/route.ts b/apps/dispatch/app/api/aircrafts/positionlog/route.ts index 61e14582..be1ed15d 100644 --- a/apps/dispatch/app/api/aircrafts/positionlog/route.ts +++ b/apps/dispatch/app/api/aircrafts/positionlog/route.ts @@ -5,18 +5,12 @@ export async function GET(request: NextRequest): Promise { try { const connectedAircraftId = request.nextUrl.searchParams.get("connectedAircraftId"); - const aircraft = await prisma.connectedAircraft.findUnique({ - where: { - id: connectedAircraftId ? parseInt(connectedAircraftId) : undefined, - }, - }); - if (!aircraft) return NextResponse.json({ error: "Aircraft not found" }, { status: 404 }); + if (!connectedAircraftId) + return NextResponse.json({ error: "connectedAircraftId is required" }, { status: 400 }); const positionLog = await prisma.positionLog.findMany({ where: { - id: { - in: aircraft.positionLogIds, - }, + connectedAircraftId: Number(connectedAircraftId), timestamp: { gte: new Date(Date.now() - 2 * 60 * 60 * 1000), // Last 2 hours }, diff --git a/apps/dispatch/app/api/position-log/route.ts b/apps/dispatch/app/api/position-log/route.ts index 42dd9960..0f1c36f9 100644 --- a/apps/dispatch/app/api/position-log/route.ts +++ b/apps/dispatch/app/api/position-log/route.ts @@ -44,9 +44,11 @@ export const PUT = async (req: Request) => { if (!activeAircraft) { return Response.json({ message: "No active aircraft found" }, { status: 400 }); } + const positionLog = await prisma.positionLog.create({ data: { ...position, + connectedAircraftId: activeAircraft.id, userId, }, }); @@ -64,9 +66,6 @@ export const PUT = async (req: Request) => { posHeading: positionLog.heading, posSpeed: positionLog.speed, posH145active: h145, - positionLogIds: { - push: positionLog.id, - }, }, }); diff --git a/apps/hub-server/modules/mail-templates/Bann.tsx b/apps/hub-server/modules/mail-templates/Bann.tsx index 5f547bbf..b555073d 100644 --- a/apps/hub-server/modules/mail-templates/Bann.tsx +++ b/apps/hub-server/modules/mail-templates/Bann.tsx @@ -54,7 +54,7 @@ const styles = ` `; const PenaltyNoticeTemplate = ({ user, staffName }: { user: User; staffName: string }) => ( - + - + ); export function renderBannNotice({ user, staffName }: { user: User; staffName: string }) { diff --git a/apps/hub-server/modules/mail-templates/ConfirmEmail.tsx b/apps/hub-server/modules/mail-templates/ConfirmEmail.tsx index 8e95f541..6f7bc85b 100644 --- a/apps/hub-server/modules/mail-templates/ConfirmEmail.tsx +++ b/apps/hub-server/modules/mail-templates/ConfirmEmail.tsx @@ -65,7 +65,7 @@ const styles = ` `; const Template = ({ user, code }: { user: User; code: string }) => ( - + ( - + ); export function renderVerificationCode({ user, code }: { user: User; code: string }) { diff --git a/apps/hub-server/modules/mail-templates/CourseCompleted.tsx b/apps/hub-server/modules/mail-templates/CourseCompleted.tsx index 3777e3b9..400fbeb1 100644 --- a/apps/hub-server/modules/mail-templates/CourseCompleted.tsx +++ b/apps/hub-server/modules/mail-templates/CourseCompleted.tsx @@ -66,7 +66,7 @@ const styles = ` `; const Template = ({ event, user }: { user: User; event: Event }) => ( - + ( - + ); export function renderCourseCompleted({ user, event }: { user: User; event: Event }) { diff --git a/apps/hub-server/modules/mail-templates/PasswordChanged.tsx b/apps/hub-server/modules/mail-templates/PasswordChanged.tsx index ea543935..4d98804d 100644 --- a/apps/hub-server/modules/mail-templates/PasswordChanged.tsx +++ b/apps/hub-server/modules/mail-templates/PasswordChanged.tsx @@ -65,7 +65,7 @@ const styles = ` `; const Template = ({ user, password }: { user: User; password: string }) => ( - + ( - + ); export function renderPasswordChanged({ user, password }: { user: User; password: string }) { diff --git a/apps/hub-server/modules/mail-templates/TimeBann.tsx b/apps/hub-server/modules/mail-templates/TimeBann.tsx index a12eb60e..67bc3d04 100644 --- a/apps/hub-server/modules/mail-templates/TimeBann.tsx +++ b/apps/hub-server/modules/mail-templates/TimeBann.tsx @@ -54,7 +54,7 @@ const styles = ` `; const TimeBanTemplate = ({ user, staffName }: { user: User; staffName: string }) => ( - + - + ); export function renderTimeBanNotice({ user, staffName }: { user: User; staffName: string }) { diff --git a/apps/hub-server/tsconfig.json b/apps/hub-server/tsconfig.json index d2d77763..429fa224 100644 --- a/apps/hub-server/tsconfig.json +++ b/apps/hub-server/tsconfig.json @@ -1,10 +1,14 @@ { - "extends": "@repo/typescript-config/nextjs.json", + "extends": "@repo/typescript-config/base.json", "compilerOptions": { - "baseUrl": ".", + "outDir": "dist", + "module": "ESNext", + "moduleResolution": "bundler", "jsx": "react-jsx", + "noEmit": true, + "baseUrl": ".", "types": ["node", "react"] }, - "include": ["."], + "include": ["**/*.ts", "./index.ts", "**/*.d.ts"], "exclude": ["node_modules", "dist"] } diff --git a/apps/hub/app/api/user/route.ts b/apps/hub/app/api/user/route.ts index 719ba6fd..364358fd 100644 --- a/apps/hub/app/api/user/route.ts +++ b/apps/hub/app/api/user/route.ts @@ -56,5 +56,6 @@ export const GET = async (req: NextRequest) => { return NextResponse.json({ ...user, moodleLastname: `${user?.lastname.split("")[0]}. - ${user?.publicId}`, + fullName: `${user?.firstname} ${user?.lastname} - ${user?.publicId}`, }); }; diff --git a/apps/hub/helper/authServices.ts b/apps/hub/helper/authServices.ts index c7841488..0cb333f4 100644 --- a/apps/hub/helper/authServices.ts +++ b/apps/hub/helper/authServices.ts @@ -28,6 +28,6 @@ export const services = [ "https://nextcloud.virtualairrescue.com", "http://nextcloud.virtualairrescue.com/", ], - requiredPermissions: ["ADMIN_USER"], + requiredPermissions: ["LOGIN_NEXTCLOUD"], }, ]; diff --git a/packages/database/prisma/schema/connectedAircraft.prisma b/packages/database/prisma/schema/connectedAircraft.prisma index faf3168f..19e3d239 100644 --- a/packages/database/prisma/schema/connectedAircraft.prisma +++ b/packages/database/prisma/schema/connectedAircraft.prisma @@ -16,9 +16,9 @@ model ConnectedAircraft { loginTime DateTime @default(now()) esimatedLogoutTime DateTime? logoutTime DateTime? - positionLogIds Int[] @default([]) // relations: - User User @relation(fields: [userId], references: [id], onDelete: Cascade) - Station Station @relation(fields: [stationId], references: [id], onDelete: Cascade) + User User @relation(fields: [userId], references: [id], onDelete: Cascade) + Station Station @relation(fields: [stationId], references: [id], onDelete: Cascade) + PositionLog PositionLog[] } diff --git a/packages/database/prisma/schema/migrations/20250630074323_change_positionlog_relations/migration.sql b/packages/database/prisma/schema/migrations/20250630074323_change_positionlog_relations/migration.sql new file mode 100644 index 00000000..98b1135b --- /dev/null +++ b/packages/database/prisma/schema/migrations/20250630074323_change_positionlog_relations/migration.sql @@ -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; diff --git a/packages/database/prisma/schema/migrations/20250630201638_add_nextcloud_permission/migration.sql b/packages/database/prisma/schema/migrations/20250630201638_add_nextcloud_permission/migration.sql new file mode 100644 index 00000000..ef4b7f8e --- /dev/null +++ b/packages/database/prisma/schema/migrations/20250630201638_add_nextcloud_permission/migration.sql @@ -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"; diff --git a/packages/database/prisma/schema/positionLog.prisma b/packages/database/prisma/schema/positionLog.prisma index 2f2df182..593fefdc 100644 --- a/packages/database/prisma/schema/positionLog.prisma +++ b/packages/database/prisma/schema/positionLog.prisma @@ -1,13 +1,15 @@ model PositionLog { - id Int @id @default(autoincrement()) - userId String - simulator String - lat Float - lng Float - alt Int - speed Int - heading Int - timestamp DateTime @default(now()) + id Int @id @default(autoincrement()) + userId String + connectedAircraftId Int + simulator String + lat Float + lng Float + alt Int + speed Int + heading Int + timestamp DateTime @default(now()) // 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) } diff --git a/packages/database/prisma/schema/user.prisma b/packages/database/prisma/schema/user.prisma index 179e48e9..ee9ae70e 100644 --- a/packages/database/prisma/schema/user.prisma +++ b/packages/database/prisma/schema/user.prisma @@ -20,6 +20,7 @@ enum PERMISSION { AUDIO PILOT DISPO + LOGIN_NEXTCLOUD } model User {