diff --git a/.vscode/settings.json b/.vscode/settings.json index a8c108c3..4b37761f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,5 +14,8 @@ } ] } - ] + ], + "[prisma]": { + "editor.defaultFormatter": "Prisma.prisma" + } } diff --git a/apps/hub/app/admin/page.tsx b/apps/hub/app/(app)/admin/page.tsx similarity index 100% rename from apps/hub/app/admin/page.tsx rename to apps/hub/app/(app)/admin/page.tsx diff --git a/apps/hub/app/(app)/layout.tsx b/apps/hub/app/(app)/layout.tsx new file mode 100644 index 00000000..efdb3bbe --- /dev/null +++ b/apps/hub/app/(app)/layout.tsx @@ -0,0 +1,99 @@ +import type { Metadata } from 'next'; +import { + DiscordLogoIcon, + InstagramLogoIcon, + ReaderIcon, +} from '@radix-ui/react-icons'; +import { HorizontalNav, VerticalNav } from '../_components/ui/Nav'; +import { Toaster } from 'react-hot-toast'; + +export const metadata: Metadata = { + title: 'Create Next App', + description: 'Generated by create next app', +}; + +export default async function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( +
+
+
+ +
+ {/* Card */} +
+
+ {/* Top Navbar */} + + + {/* Hauptlayout: Sidebar + Content (nimmt Resthöhe ein) */} +
+ {/* Linke Sidebar */} + + + {/* Scrollbarer Content-Bereich */} +
+ {children} +
+
+ + {/* Footer */} + +
+
+
+ ); +} diff --git a/apps/hub/app/page.tsx b/apps/hub/app/(app)/page.tsx similarity index 85% rename from apps/hub/app/page.tsx rename to apps/hub/app/(app)/page.tsx index f19145dd..b37a4be8 100644 --- a/apps/hub/app/page.tsx +++ b/apps/hub/app/(app)/page.tsx @@ -1,6 +1,6 @@ import Link from 'next/link'; -import { PaginatedTable } from './_components/PaginatedTable'; -import { Header } from './_components/ui/Header'; +import { PaginatedTable } from '../_components/PaginatedTable'; +import { Header } from '../_components/ui/Header'; import { PrismaClient } from '@repo/db'; export default async function Home() { @@ -30,15 +30,15 @@ export default async function Home() { }, ]} /> - gd + Map
- gd + Logbuch
- gd + Einlog-Zeit (7 Tage, total)
- gd + Stats
- gd + Badges
gd
diff --git a/apps/hub/app/(app)/settings/account/_components/forms.tsx b/apps/hub/app/(app)/settings/account/_components/forms.tsx new file mode 100644 index 00000000..537d6108 --- /dev/null +++ b/apps/hub/app/(app)/settings/account/_components/forms.tsx @@ -0,0 +1,253 @@ +'use client'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { DiscordAccount, User } from '@repo/db'; +import { useState } from 'react'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { unlinkDiscord, updateUser } from '../actions'; +import { Toaster, toast } from 'react-hot-toast'; +import { useSession } from 'next-auth/react'; +import { useRouter } from 'next/navigation'; +import { Button } from '../../../../_components/ui/Button'; +import { + PersonIcon, + EnvelopeClosedIcon, + BookmarkIcon, + DiscordLogoIcon, + PaperPlaneIcon, + Link2Icon, + MixerHorizontalIcon, +} from '@radix-ui/react-icons'; + +export const ProfileForm = ({ user }: { user: User }) => { + const schema = z.object({ + firstname: z.string().min(2).max(30), + lastname: z.string().min(2).max(30), + email: z.string().email({ + message: 'Bitte gebe eine gültige E-Mail Adresse ein', + }), + }); + const [isLoading, setIsLoading] = useState(false); + type IFormInput = z.infer; + + const form = useForm({ + defaultValues: { + firstname: user.firstname, + lastname: user.lastname, + email: user.email, + }, + resolver: zodResolver(schema), + }); + return ( +
{ + setIsLoading(true); + await updateUser(values); + form.reset(values); + setIsLoading(false); + toast.success('Deine Änderungen wurden gespeichert!', { + style: { + background: + 'var(--fallback-b1, oklch(var(--b1) / var(--tw-bg-opacity, 1)))', + color: + 'var(--fallback-nc, oklch(var(--nc) / var(--tw-text-opacity, 1)))', + }, + }); + })} + > +

+ Persönliche Informationen +

+
+ + {form.formState.errors.firstname && ( +

+ {form.formState.errors.firstname.message} +

+ )} + + {form.formState.errors.lastname && ( +

+ {form.formState.errors.lastname?.message} +

+ )} + + {form.formState.errors.email && ( +

{form.formState.errors.email?.message}

+ )} +
+ +
+
+
+ ); +}; + +export const SocialForm = ({ + discordAccount, + user, +}: { + discordAccount?: DiscordAccount; + user: User; +}) => { + const [isLoading, setIsLoading] = useState(false); + const [vatsimLoading, setVatsimLoading] = useState(false); + const router = useRouter(); + + const schema = z.object({ + vatsimCid: z.number().min(1000).max(9999999), + }); + + type IFormInput = z.infer; + + const form = useForm({ + defaultValues: { + vatsimCid: user?.vatsimCid || undefined, + }, + resolver: zodResolver(schema), + }); + + if (!user) return null; + return ( +
{ + form.handleSubmit(async () => { + setVatsimLoading(true); + }); + await updateUser({ + vatsimCid: values.vatsimCid, + }); + setVatsimLoading(false); + form.reset(values); + toast.success('Deine Änderungen wurden gespeichert!', { + style: { + background: + 'var(--fallback-b1, oklch(var(--b1) / var(--tw-bg-opacity, 1)))', + color: + 'var(--fallback-nc, oklch(var(--nc) / var(--tw-text-opacity, 1)))', + }, + }); + })} + > +

+ Verbindungen & Benachrichtigungen +

+
+
+
+ + Discord + +
+ + {discordAccount ? ( + + ) : ( + + + + )} +
+
+
+ + {form.formState.errors.vatsimCid && ( +

+ {form.formState.errors.vatsimCid.message} +

+ )} +
+
+ +
+
+ ); +}; diff --git a/apps/hub/app/(app)/settings/account/actions.ts b/apps/hub/app/(app)/settings/account/actions.ts new file mode 100644 index 00000000..a3c6dcdc --- /dev/null +++ b/apps/hub/app/(app)/settings/account/actions.ts @@ -0,0 +1,26 @@ +'use server'; +import { Prisma, PrismaClient } from '@repo/db'; +import { getServerSession } from '../../../api/auth/[...nextauth]/auth'; + +export const unlinkDiscord = async (userId: string) => { + const client = new PrismaClient(); + await client.discordAccount.deleteMany({ + where: { + userId, + }, + }); +}; + +export const updateUser = async (changes: Prisma.UserUpdateInput) => { + const session = await getServerSession(); + if (!session) return null; + + const client = new PrismaClient(); + + await client.user.update({ + where: { + id: session.user.id, + }, + data: changes, + }); +}; diff --git a/apps/hub/app/(app)/settings/account/page.tsx b/apps/hub/app/(app)/settings/account/page.tsx new file mode 100644 index 00000000..f81673c1 --- /dev/null +++ b/apps/hub/app/(app)/settings/account/page.tsx @@ -0,0 +1,35 @@ +import { getServerSession } from '../../../api/auth/[...nextauth]/auth'; +import { PrismaClient } from '@repo/db'; +import { ProfileForm, SocialForm } from './_components/forms'; +import { GearIcon } from '@radix-ui/react-icons'; + +export default async () => { + const prisma = new PrismaClient(); + const session = await getServerSession(); + if (!session) return null; + const user = await prisma.user.findFirst({ + where: { + id: session.user.id, + }, + include: { + discordAccounts: true, + }, + }); + if (!user) return null; + const discordAccount = user?.discordAccounts[0]; + return ( +
+
+

+ Einstellungen +

+
+
+ +
+
+ +
+
+ ); +}; diff --git a/apps/hub/app/(app)/settings/privacy/page.tsx b/apps/hub/app/(app)/settings/privacy/page.tsx new file mode 100644 index 00000000..a8c6cee3 --- /dev/null +++ b/apps/hub/app/(app)/settings/privacy/page.tsx @@ -0,0 +1,8 @@ +export default () => { + return ( +
+

Settings

+

Settings page content

+
+ ); +}; diff --git a/apps/hub/app/(auth)/register/_components/Register.tsx b/apps/hub/app/(auth)/register/_components/Register.tsx index 79eb42bc..cb4871d1 100644 --- a/apps/hub/app/(auth)/register/_components/Register.tsx +++ b/apps/hub/app/(auth)/register/_components/Register.tsx @@ -34,10 +34,6 @@ export const Register = () => { const [isLoading, setIsLoading] = useState(false); - const cn = (...inputs: ClassValue[]) => { - return twMerge(clsx(inputs)); - }; - const form = useForm({ resolver: zodResolver(schema), defaultValues: { diff --git a/apps/hub/app/_components/ui/Button.tsx b/apps/hub/app/_components/ui/Button.tsx new file mode 100644 index 00000000..2e53a1e6 --- /dev/null +++ b/apps/hub/app/_components/ui/Button.tsx @@ -0,0 +1,25 @@ +import { ButtonHTMLAttributes, DetailedHTMLProps } from 'react'; +import { cn } from '../../../helper/cn'; + +export const Button = ({ + isLoading, + ...props +}: DetailedHTMLProps< + ButtonHTMLAttributes, + HTMLButtonElement +> & { + isLoading?: boolean; +}) => { + return ( + + ); +}; diff --git a/apps/hub/app/_components/ui/Nav.tsx b/apps/hub/app/_components/ui/Nav.tsx new file mode 100644 index 00000000..11816e40 --- /dev/null +++ b/apps/hub/app/_components/ui/Nav.tsx @@ -0,0 +1,60 @@ +import { + HomeIcon, + PersonIcon, + GearIcon, + ExitIcon, +} from '@radix-ui/react-icons'; +import Link from 'next/link'; + +export const VerticalNav = () => { + return ( +
+
    +
  • + + Dashboard + +
  • +
  • + + Profile + +
  • +
  • + + + Einstellungen + +
  • +
+
+ ); +}; + +export const HorizontalNav = () => ( +
+ +
+
    +
  • + + + +
  • +
  • + + + +
  • +
+
+
+); diff --git a/apps/hub/app/api/discord-redirect/route.ts b/apps/hub/app/api/discord-redirect/route.ts new file mode 100644 index 00000000..6fbb6f8f --- /dev/null +++ b/apps/hub/app/api/discord-redirect/route.ts @@ -0,0 +1,92 @@ +import axios, { AxiosError } from 'axios'; +import { NextRequest, NextResponse } from 'next/server'; +import { DiscordAccount, PrismaClient } from '@repo/db'; +import { getServerSession } from '../auth/[...nextauth]/auth'; + +export const GET = async (req: NextRequest) => { + const session = await getServerSession(); + const prisma = new PrismaClient(); + const code = req.nextUrl.searchParams.get('code'); + + if (!session) { + return NextResponse.redirect(`${process.env.NEXTAUTH_URL}/login`); + } + + if ( + !process.env.DISCORD_OAUTH_CLIENT_ID || + !process.env.DISCORD_OAUTH_SECRET || + !process.env.DISCORD_REDIRECT || + !code + ) { + return NextResponse.json( + { + error: 'Discord OAuth not configured', + }, + { + status: 500, + } + ); + } + + const params = new URLSearchParams({ + client_id: process.env.DISCORD_OAUTH_CLIENT_ID, + client_secret: process.env.DISCORD_OAUTH_SECRET, + redirect_uri: process.env.DISCORD_REDIRECT, + grant_type: 'authorization_code', + code, + }); + + const headers = { + 'Content-Type': 'application/x-www-form-urlencoded', + }; + try { + const { data: authData } = await axios.post( + 'https://discord.com/api/oauth2/token', + params, + { + headers, + } + ); + + const { data: discordUser } = await axios.get( + 'https://discord.com/api/users/@me', + { + headers: { + Authorization: `Bearer ${authData.access_token}`, + }, + } + ); + + const discordObject = { + userId: session.user.id, + accessToken: authData.access_token, + refreshToken: authData.refresh_token, + discordId: discordUser.id, + email: discordUser.email, + avatar: discordUser.avatar, + username: discordUser.username, + globalName: discordUser.global_name, + verified: discordUser.verified, + tokenType: authData.token_type, + } as DiscordAccount; + + const discord = await prisma.discordAccount.upsert({ + where: { discordId: discordUser.id }, + update: discordObject, // Updates if found + create: discordObject, // Creates if not found + }); + return NextResponse.redirect( + `${process.env.NEXTAUTH_URL}/settings/account` + ); + } catch (error: any) { + console.error(error); + return NextResponse.json( + { + error: "Couldn't connect to Discord", + }, + { + status: 500, + } + ); + } +}; diff --git a/apps/hub/app/globals.css b/apps/hub/app/globals.css index ee27bcf8..f2f484fe 100644 --- a/apps/hub/app/globals.css +++ b/apps/hub/app/globals.css @@ -5,4 +5,5 @@ :root { --background: #ffffff; --foreground: #171717; -} \ No newline at end of file + /* --p: 47.67% 0.2484 267.02; */ +} diff --git a/apps/hub/app/layout.tsx b/apps/hub/app/layout.tsx index 3912df13..749013d9 100644 --- a/apps/hub/app/layout.tsx +++ b/apps/hub/app/layout.tsx @@ -1,169 +1,35 @@ -import Link from "next/link"; -import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; -import "./globals.css"; -import { getServerSession } from "next-auth"; import { NextAuthSessionProvider } from "./_components/AuthSessionProvider"; -import { options } from "./api/auth/[...nextauth]/auth"; -import { - ExitIcon, - DiscordLogoIcon, - InstagramLogoIcon, - ReaderIcon, - HomeIcon, - PersonIcon, - GearIcon, -} from "@radix-ui/react-icons"; +import { getServerSession } from "./api/auth/[...nextauth]/auth"; +import './globals.css'; + const geistSans = Geist({ - variable: "--font-geist-sans", - subsets: ["latin"], -}); + variable: '--font-geist-sans', + subsets: ['latin'], + }); + + const geistMono = Geist_Mono({ + variable: '--font-geist-mono', + subsets: ['latin'], + }); -const geistMono = Geist_Mono({ - variable: "--font-geist-mono", - subsets: ["latin"], -}); - -export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", -}; - -export default async function RootLayout({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) { - const session = await getServerSession(options); - return ( - - - -
) => { + const session = await getServerSession(); + + return ( + + + -
- - {/* Card */} -
-
- {/* Top Navbar */} -
- -
-
    -
  • - - - -
  • -
  • - - - -
  • -
-
-
- - {/* Hauptlayout: Sidebar + Content (nimmt Resthöhe ein) */} -
- {/* Linke Sidebar */} - - - {/* Scrollbarer Content-Bereich */} -
- {children} -
-
- - {/* Footer */} - -
-
-
- -
- - ); -} + {children} + + + + ) +} \ No newline at end of file diff --git a/apps/hub/helper/cn.ts b/apps/hub/helper/cn.ts new file mode 100644 index 00000000..2430735f --- /dev/null +++ b/apps/hub/helper/cn.ts @@ -0,0 +1,6 @@ +import clsx, { ClassValue } from 'clsx'; +import { twMerge } from 'tailwind-merge'; + +export const cn = (...inputs: ClassValue[]) => { + return twMerge(clsx(inputs)); +}; diff --git a/apps/hub/package.json b/apps/hub/package.json index 743fa793..9b17976a 100644 --- a/apps/hub/package.json +++ b/apps/hub/package.json @@ -12,7 +12,9 @@ "@hookform/resolvers": "^3.10.0", "@next-auth/prisma-adapter": "^1.0.7", "@repo/ui": "*", + "@repo/db": "*", "@tanstack/react-table": "^8.20.6", + "axios": "^1.7.9", "bcryptjs": "^2.4.3", "clsx": "^2.1.1", "jsonwebtoken": "^9.0.2", diff --git a/apps/hub/tailwind.config.ts b/apps/hub/tailwind.config.ts index d4947001..42346bcf 100644 --- a/apps/hub/tailwind.config.ts +++ b/apps/hub/tailwind.config.ts @@ -6,13 +6,5 @@ export default { './components/**/*.{js,ts,jsx,tsx,mdx}', './app/**/*.{js,ts,jsx,tsx,mdx}', ], - theme: { - extend: { - colors: { - background: 'var(--background)', - foreground: 'var(--foreground)', - }, - }, - }, plugins: [require('daisyui')], } satisfies Config; diff --git a/package-lock.json b/package-lock.json index ff325407..3c7cf4cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -109,6 +109,7 @@ "@next-auth/prisma-adapter": "^1.0.7", "@repo/ui": "*", "@tanstack/react-table": "^8.20.6", + "axios": "^1.7.9", "bcryptjs": "^2.4.3", "clsx": "^2.1.1", "jsonwebtoken": "^9.0.2", @@ -2254,6 +2255,11 @@ "integrity": "sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -2278,6 +2284,16 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.7.9", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", + "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz", @@ -2433,7 +2449,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.1.tgz", "integrity": "sha512-BhYE+WDaywFg2TBWYNXAE+8B1ATnThNBqXHP5nQu0jWJdVvY2hvkpyB3qOmtmDePiS5/BDQ8wASEWGMWRG148g==", - "dev": true, "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2" @@ -2707,6 +2722,17 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "optional": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", @@ -3003,6 +3029,14 @@ "node": ">=8" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/detect-libc": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", @@ -3087,7 +3121,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "dev": true, "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", @@ -3198,7 +3231,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -3207,7 +3239,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -3243,7 +3274,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.0.tgz", "integrity": "sha512-Ujz8Al/KfOVR7fkaghAB1WvnLsdYxHDWmfoi2vlA2jZWRg31XhIC1a4B+/I24muD8iSbHxJ1JkrfqmWb65P/Mw==", - "dev": true, "dependencies": { "es-errors": "^1.3.0" }, @@ -3255,7 +3285,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "dev": true, "dependencies": { "es-errors": "^1.3.0", "get-intrinsic": "^1.2.6", @@ -4151,6 +4180,25 @@ "integrity": "sha512-AiwGJM8YcNOaobumgtng+6NHuOqC3A7MixFeDafM3X9cIUM+xUXoS5Vfgf+OihAYe20fxqNM9yPBXJzRtZ/4eA==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -4188,6 +4236,20 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", + "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs-extra": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", @@ -4226,7 +4288,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -4264,7 +4325,6 @@ "version": "1.2.7", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.7.tgz", "integrity": "sha512-VW6Pxhsrk0KAOqs3WEd0klDiF/+V7gQOpAvY1jVU/LHmaD/kQO4523aiJuikX/QAKYiW6x8Jh+RJej1almdtCA==", - "dev": true, "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-define-property": "^1.0.1", @@ -4288,7 +4348,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "dev": true, "dependencies": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" @@ -4467,7 +4526,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -4642,7 +4700,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -4654,7 +4711,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "dev": true, "dependencies": { "has-symbols": "^1.0.3" }, @@ -4669,7 +4725,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "dev": true, "dependencies": { "function-bind": "^1.1.2" }, @@ -6062,7 +6117,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -6095,6 +6149,25 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -7274,8 +7347,7 @@ "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "node_modules/punycode": { "version": "2.3.1", diff --git a/packages/database/package.json b/packages/database/package.json index c42584b9..939f3e60 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -2,7 +2,8 @@ "name": "@repo/db", "version": "0.0.0", "description": "VAR Databse package", - "main": "index.js", + "main": "generated/client/index.js", + "types": "generated/client/index.d.ts", "scripts": { "db:generate": "npx prisma generate", "db:migrate": "npx prisma migrate dev", diff --git a/packages/database/prisma/migrations/20250215203417_/migration.sql b/packages/database/prisma/migrations/20250215203417_/migration.sql new file mode 100644 index 00000000..8f6afb65 --- /dev/null +++ b/packages/database/prisma/migrations/20250215203417_/migration.sql @@ -0,0 +1,19 @@ +-- CreateTable +CREATE TABLE "discord_accounts" ( + "id" SERIAL NOT NULL, + "user_id" TEXT NOT NULL, + "discord_id" TEXT NOT NULL, + "access_token" TEXT NOT NULL, + "refresh_token" TEXT NOT NULL, + "token_type" TEXT NOT NULL, + "scope" TEXT NOT NULL, + "guild_id" TEXT NOT NULL, + "guild_name" TEXT NOT NULL, + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "discord_accounts_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "discord_accounts" ADD CONSTRAINT "discord_accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/packages/database/prisma/migrations/20250215205041_/migration.sql b/packages/database/prisma/migrations/20250215205041_/migration.sql new file mode 100644 index 00000000..4435bb7b --- /dev/null +++ b/packages/database/prisma/migrations/20250215205041_/migration.sql @@ -0,0 +1,13 @@ +/* + Warnings: + + - You are about to drop the column `guild_id` on the `discord_accounts` table. All the data in the column will be lost. + - You are about to drop the column `guild_name` on the `discord_accounts` table. All the data in the column will be lost. + - You are about to drop the column `scope` on the `discord_accounts` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "discord_accounts" DROP COLUMN "guild_id", +DROP COLUMN "guild_name", +DROP COLUMN "scope", +ADD COLUMN "email" TEXT; diff --git a/packages/database/prisma/migrations/20250215205521_/migration.sql b/packages/database/prisma/migrations/20250215205521_/migration.sql new file mode 100644 index 00000000..99af8131 --- /dev/null +++ b/packages/database/prisma/migrations/20250215205521_/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - Added the required column `global_name` to the `discord_accounts` table without a default value. This is not possible if the table is not empty. + - Added the required column `username` to the `discord_accounts` table without a default value. This is not possible if the table is not empty. + - Made the column `email` on table `discord_accounts` required. This step will fail if there are existing NULL values in that column. + +*/ +-- AlterTable +ALTER TABLE "discord_accounts" ADD COLUMN "avatar" TEXT, +ADD COLUMN "global_name" TEXT NOT NULL, +ADD COLUMN "username" TEXT NOT NULL, +ADD COLUMN "verified" BOOLEAN NOT NULL DEFAULT false, +ALTER COLUMN "email" SET NOT NULL; diff --git a/packages/database/prisma/migrations/20250215210609_/migration.sql b/packages/database/prisma/migrations/20250215210609_/migration.sql new file mode 100644 index 00000000..f0f935ab --- /dev/null +++ b/packages/database/prisma/migrations/20250215210609_/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - A unique constraint covering the columns `[discord_id]` on the table `discord_accounts` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX "discord_accounts_discord_id_key" ON "discord_accounts"("discord_id"); diff --git a/packages/database/prisma/migrations/20250215225203_/migration.sql b/packages/database/prisma/migrations/20250215225203_/migration.sql new file mode 100644 index 00000000..4f3675ef --- /dev/null +++ b/packages/database/prisma/migrations/20250215225203_/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "users" ADD COLUMN "vatsim_cid" INTEGER; diff --git a/packages/database/prisma/migrations/20250215233709_/migration.sql b/packages/database/prisma/migrations/20250215233709_/migration.sql new file mode 100644 index 00000000..a087d5c1 --- /dev/null +++ b/packages/database/prisma/migrations/20250215233709_/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "users" ALTER COLUMN "vatsim_cid" SET DATA TYPE TEXT; diff --git a/packages/database/prisma/migrations/20250215233857_/migration.sql b/packages/database/prisma/migrations/20250215233857_/migration.sql new file mode 100644 index 00000000..0bffdee9 --- /dev/null +++ b/packages/database/prisma/migrations/20250215233857_/migration.sql @@ -0,0 +1,9 @@ +/* + Warnings: + + - The `vatsim_cid` column on the `users` table would be dropped and recreated. This will lead to data loss if there is data in the column. + +*/ +-- AlterTable +ALTER TABLE "users" DROP COLUMN "vatsim_cid", +ADD COLUMN "vatsim_cid" INTEGER; diff --git a/packages/database/prisma/schema/auth.prisma b/packages/database/prisma/schema/auth.prisma index 1b748ab4..18445dda 100644 --- a/packages/database/prisma/schema/auth.prisma +++ b/packages/database/prisma/schema/auth.prisma @@ -1,3 +1,23 @@ +model Account { + id Int @id @default(autoincrement()) + compoundId String @unique @map(name: "compound_id") + userId Int @map(name: "user_id") + providerType String @map(name: "provider_type") + providerId String @map(name: "provider_id") + providerAccountId String @map(name: "provider_account_id") + refreshToken String? @map(name: "refresh_token") + accessToken String? @map(name: "access_token") + accessTokenExpires DateTime? @map(name: "access_token_expires") + createdAt DateTime @default(now()) @map(name: "created_at") + updatedAt DateTime @default(now()) @map(name: "updated_at") + + @@index([providerAccountId], name: "providerAccountId") + @@index([providerId], name: "providerId") + @@index([userId], name: "userId") + @@map(name: "accounts") +} + + model Session { id Int @id @default(autoincrement()) userId Int @map(name: "user_id") @@ -10,23 +30,6 @@ model Session { @@map(name: "sessions") } -model User { - id String @id @default(uuid()) - firstname String - lastname String - email String @unique - password String - emailVerified DateTime? @map(name: "email_verified") - image String? - createdAt DateTime @default(now()) @map(name: "created_at") - updatedAt DateTime @default(now()) @map(name: "updated_at") - - // relations: - oauthTokens OAuthToken[] - - @@map(name: "users") -} - model VerificationRequest { id Int @id @default(autoincrement()) identifier String diff --git a/packages/database/prisma/schema/user.prisma b/packages/database/prisma/schema/user.prisma index e652702e..84467cdd 100644 --- a/packages/database/prisma/schema/user.prisma +++ b/packages/database/prisma/schema/user.prisma @@ -1,18 +1,39 @@ -model Account { - id Int @id @default(autoincrement()) - compoundId String @unique @map(name: "compound_id") - userId Int @map(name: "user_id") - providerType String @map(name: "provider_type") - providerId String @map(name: "provider_id") - providerAccountId String @map(name: "provider_account_id") - refreshToken String? @map(name: "refresh_token") - accessToken String? @map(name: "access_token") - accessTokenExpires DateTime? @map(name: "access_token_expires") - createdAt DateTime @default(now()) @map(name: "created_at") - updatedAt DateTime @default(now()) @map(name: "updated_at") +model User { + id String @id @default(uuid()) + firstname String + lastname String + email String @unique + password String + vatsimCid Int? @map(name: "vatsim_cid") + emailVerified DateTime? @map(name: "email_verified") + image String? + createdAt DateTime @default(now()) @map(name: "created_at") + updatedAt DateTime @default(now()) @map(name: "updated_at") - @@index([providerAccountId], name: "providerAccountId") - @@index([providerId], name: "providerId") - @@index([userId], name: "userId") - @@map(name: "accounts") + // relations: + oauthTokens OAuthToken[] + discordAccounts DiscordAccount[] + + @@map(name: "users") +} + +model DiscordAccount { + id Int @id @default(autoincrement()) + discordId String @unique @map(name: "discord_id") + userId String @map(name: "user_id") + email String @map(name: "email") + username String @map(name: "username") + avatar String? @map(name: "avatar") + globalName String @map(name: "global_name") + verified Boolean @default(false) + accessToken String @map(name: "access_token") + refreshToken String @map(name: "refresh_token") + tokenType String @map(name: "token_type") + createdAt DateTime @default(now()) @map(name: "created_at") + updatedAt DateTime @default(now()) @map(name: "updated_at") + + // relations: + user User @relation(fields: [userId], references: [id]) // Beziehung zu User + + @@map(name: "discord_accounts") }