diff --git a/Dockerfile b/Dockerfile index b3ad0e3..6c015fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,12 +6,17 @@ WORKDIR /sistema # Copy package.json and package-lock.json COPY package.json package-lock.json ./ +COPY prisma ./prisma/ # Install dependencies using npm RUN npm install -# Expose the port the app runs on +# Generate the Prisma client +RUN npx prisma generate + +# Expose the ports the app runs on EXPOSE 3000 +EXPOSE 5432 # Start the Next.js application in development mode CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/app/api/users/absences/route.ts b/app/api/users/absences/route.ts new file mode 100644 index 0000000..e416d28 --- /dev/null +++ b/app/api/users/absences/route.ts @@ -0,0 +1,30 @@ +import { PrismaClient } from '@prisma/client'; +import { NextRequest, NextResponse } from 'next/server'; + +const prisma = new PrismaClient(); + +export async function GET(req: NextRequest) { + const { searchParams } = new URL(req.url); + const encodedId = searchParams.get('id'); + console.log('ID: ' + encodedId); + + if (!encodedId) { + return new NextResponse('ID not provided', { status: 400 }); + } + + const id = Number(decodeURIComponent(encodedId)); + + if (Number.isNaN(id)) { + return new NextResponse('ID not a number', { status: 400 }); + } + + try { + const absences = await prisma.absence.findMany({ + where: { id: id }, + }); + + return new NextResponse(JSON.stringify(absences), { status: 200 }); + } catch (error) { + return new NextResponse('Internal server error', { status: 500 }); + } +} diff --git a/app/api/users/get-user-by-email/route.ts b/app/api/users/get-user-by-email/route.ts new file mode 100644 index 0000000..e21d60a --- /dev/null +++ b/app/api/users/get-user-by-email/route.ts @@ -0,0 +1,31 @@ +import { PrismaClient } from '@prisma/client'; +import { NextRequest, NextResponse } from 'next/server'; + +const prisma = new PrismaClient(); + +export async function GET(req: NextRequest) { + const { searchParams } = new URL(req.url); + const encodedEmail = searchParams.get('email'); + + if (!encodedEmail) { + return new NextResponse('Email not provided', { status: 400 }); + } + + // const email = decodeURIComponent(encodedEmail); + console.log('email: ' + decodeURIComponent(encodedEmail)); // proof + // choosing an email inside the db instead: + const email = 'Afton24@gmail.com'; + try { + const user = await prisma.user.findUnique({ + where: { email }, + }); + + if (!user) { + return new NextResponse('User not found', { status: 400 }); + } else { + return new NextResponse(JSON.stringify(user), { status: 200 }); + } + } catch (error) { + return new NextResponse('Internal server error', { status: 500 }); + } +} diff --git a/app/api/users/route.ts b/app/api/users/route.ts new file mode 100644 index 0000000..6054677 --- /dev/null +++ b/app/api/users/route.ts @@ -0,0 +1,10 @@ +import { PrismaClient } from '@prisma/client'; +import { NextRequest, NextResponse } from 'next/server'; + +const prisma = new PrismaClient(); + +export async function GET(req: NextRequest) { + const users = await prisma.user.findMany(); + console.log(users); + return NextResponse.json(users); +} diff --git a/package-lock.json b/package-lock.json index a130639..f9bafe8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,12 +11,13 @@ "@emotion/react": "^11.9.0", "@emotion/styled": "^11.9.0", "@faker-js/faker": "^8.4.1", - "@prisma/client": "^5.15.1", + "@prisma/client": "^5.16.2", "@snaplet/copycat": "^5.0.0", "@snaplet/seed": "^0.97.20", "framer-motion": "^6.3.0", "next": "^14.2.3", "next-auth": "^5.0.0-beta.19", + "pnpm": "^9.4.0", "postgres": "^3.4.4", "prisma": "^5.15.0", "react": "^18.2.0", @@ -33,8 +34,7 @@ "eslint-plugin-prettier": "^5.1.3", "husky": "^9.0.11", "prettier": "^3.3.2", - "prisma": "^5.15.1", - "typescript": "^4.9.5" + "prisma": "^5.15.1" } }, "node_modules/@auth/core": { @@ -2116,9 +2116,10 @@ } }, "node_modules/@prisma/client": { - "version": "5.16.0", + "version": "5.16.2", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.16.2.tgz", + "integrity": "sha512-+1lmkhR9gHWcTC5oghm2ZKpWljyWdzfazCVlLKUWXVmwHSf52g81aZ8qb6Km5Bs025yBi7puLp3qSLEvktoUtw==", "hasInstallScript": true, - "license": "Apache-2.0", "engines": { "node": ">=16.13" }, @@ -7036,6 +7037,21 @@ "node": ">=4" } }, + "node_modules/pnpm": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/pnpm/-/pnpm-9.5.0.tgz", + "integrity": "sha512-FAA2gwEkYY1iSiGHtQ0EKJ1aCH8ybJ7fwMzXM9dsT1LDoxPU/BSHlKKp2BVTAWAE5nQujPhQZwJopzh/wiDJAw==", + "bin": { + "pnpm": "bin/pnpm.cjs", + "pnpx": "bin/pnpx.cjs" + }, + "engines": { + "node": ">=18.12" + }, + "funding": { + "url": "https://opencollective.com/pnpm" + } + }, "node_modules/popmotion": { "version": "11.0.3", "license": "MIT", @@ -8949,6 +8965,49 @@ "node": ">= 6" } }, + "node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/yargs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -8960,6 +9019,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index d37d956..2bfb0fd 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@emotion/react": "^11.9.0", "@emotion/styled": "^11.9.0", "@faker-js/faker": "^8.4.1", - "@prisma/client": "^5.15.1", + "@prisma/client": "^5.16.2", "@snaplet/copycat": "^5.0.0", "@snaplet/seed": "^0.97.20", "framer-motion": "^6.3.0", diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx index 4f2b461..4f885e2 100644 --- a/src/pages/profile.tsx +++ b/src/pages/profile.tsx @@ -1,34 +1,87 @@ -import { useSession } from 'next-auth/react'; -import { SignInButton } from '../components/SignInButton'; -import { SignOutButton } from '../components/SignOutButton'; - -export default function AnotherPage() { - const { data: session, status } = useSession(); - - return ( -
Loading...
- ) : session && session.user ? ( -Name: {session.user.name}
-Email: {session.user.email}
-Image:
- {session.user.image && } - -Absences:
-Error: Signed out
- )} -Loading...
+ ) : session && session.user ? ( +Name: {session.user.name}
+Email: {session.user.email}
+Image:
+ {session.user.image && ( + + )} + ++ Absences: {usedAbsences} / {numAbsences}{' '} +
+Error: Signed out
+ )} +