From 108193f2020344444a98f408e8239aa2d86b8d4d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Dec 2022 18:48:24 +0100 Subject: [PATCH 1/8] =?UTF-8?q?add=20-=20changement=20mail=20envoy=C3=A9?= =?UTF-8?q?=20lors=20de=20la=20connexion=20rapide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/api/auth/[...nextauth].ts | 7 +- pages/api/auth/signinemail.ts | 243 ++++++++++++++++++++++++++++++++ 2 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 pages/api/auth/signinemail.ts diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 2daf7dd..0834c54 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -6,7 +6,7 @@ import GoogleProvider from "next-auth/providers/google"; import EmailProvider from 'next-auth/providers/email' import prisma from '../../../lib/prisma' import { Session } from "@prisma/client"; - +import { CustomsendVerificationRequest } from "./signinemail" const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options); export default authHandler; @@ -27,7 +27,10 @@ const options = { pass: process.env.EMAIL_SERVER_PASSWORD } }, - from: process.env.EMAIL_FROM + from: process.env.EMAIL_FROM, + sendVerificationRequest({ identifier, url, provider }) { + CustomsendVerificationRequest({ identifier, url, provider }) + } }), ], adapter: PrismaAdapter(prisma), diff --git a/pages/api/auth/signinemail.ts b/pages/api/auth/signinemail.ts new file mode 100644 index 0000000..9f63511 --- /dev/null +++ b/pages/api/auth/signinemail.ts @@ -0,0 +1,243 @@ +// https://craftingemails.com/blog/nextauth-signin-custom-email +import { Theme } from "next-auth" +import { createTransport } from "nodemailer" + +export async function CustomsendVerificationRequest(params) { + const { identifier, url, provider, theme } = params + const { host } = new URL(url) + // NOTE: You are not required to use `nodemailer`, use whatever you want. + const transport = createTransport(provider.server) + const result = await transport.sendMail({ + to: identifier, + from: provider.from, + subject: `Sign in to ${host}`, + text: text({ url, host }), + html: html({ url, host, theme }), + }) + const failed = result.rejected.concat(result.pending).filter(Boolean) + if (failed.length) { + throw new Error(`Email(s) (${failed.join(", ")}) could not be sent`) + } +} + +function html(params: { url: string; host: string; theme: Theme }) { + const { url, host, theme } = params + + const escapedHost = host.replace(/\./g, "​.") + + return ` + + + + + + + + + + + Connection à Thé Tip Top + + + + + + +
+ Connexion à Thé Tip Top + ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ +
+
+ + + + +
+ +
+
+
+ + + + + + +
+
+ +` +} + +// Email Text body (fallback for email clients that don't render HTML) +function text({ url, host }: { url: string; host: string }) { + return `Connectez vous à ${host}\n${url}\n\n` +} \ No newline at end of file From 85ade3016b45b96aed9dca9c521451a036325a9a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Dec 2022 12:28:14 +0100 Subject: [PATCH 2/8] add - new oauth ids --- .env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env b/.env index e02a63f..cb95f97 100644 --- a/.env +++ b/.env @@ -6,8 +6,8 @@ GITHUB_ID=YOUR_GITHUB_CLIENT_ID GITHUB_SECRET=YOUR_GITHUB_CLIENT_SECRET # Google Auth Provider -GOOGLE_CLIENT_ID=5572607706-p6dftn0ss3m2qnvqbhk4khqte8lk7kt3.apps.googleusercontent.com -GOOGLE_CLIENT_SECRET=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 +GOOGLE_CLIENT_ID=965228443747-049kq59pm43bd23aplfu9ja2333dpo5s.apps.googleusercontent.com +GOOGLE_CLIENT_SECRET=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 DATABASE_URL="postgres://postgres:postgrespwd@localhost:5432/thetiptop" From 641df2cf51922b02c2a8bfdf526f1f96b1b6b0bf Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Dec 2022 12:36:28 +0100 Subject: [PATCH 3/8] add - background svg mais trop lourd --- public/images/svg/pageprincipale.svg | 48870 +++++++++++++++++++++++++ 1 file changed, 48870 insertions(+) create mode 100644 public/images/svg/pageprincipale.svg diff --git a/public/images/svg/pageprincipale.svg b/public/images/svg/pageprincipale.svg new file mode 100644 index 0000000..40e8b53 --- /dev/null +++ b/public/images/svg/pageprincipale.svg @@ -0,0 +1,48870 @@ + + + + From 0a50ebe9524a335cbf108f5f332b07aa56f4b328 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 8 Dec 2022 12:52:03 +0100 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=9A=A7=20boutton=20admin=20retrait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 28 ++++++++++ package.json | 2 + pages/admin.tsx | 42 ++++++++++++--- pages/api/superadmin/make-admin.ts | 4 +- pages/api/user/update-gift.ts | 84 ++++++++++++++++++++++++++++++ prisma/seed.ts | 4 +- styles/Index.module.css | 5 +- 7 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 pages/api/user/update-gift.ts diff --git a/package-lock.json b/package-lock.json index 29a3213..faac378 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,8 @@ "bootstrap": "^5.2.2", "chance": "^1.1.9", "crypto-random-string": "^3.0.0", + "date-format": "^4.0.14", + "dateformat": "^5.0.3", "js-confetti": "^0.11.0", "next": "13.0.2", "next-auth": "4.16.4", @@ -900,6 +902,22 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==" }, + "node_modules/date-format": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", + "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/dateformat": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz", + "integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==", + "engines": { + "node": ">=12.20" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -4339,6 +4357,16 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==" }, + "date-format": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", + "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==" + }, + "dateformat": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz", + "integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==" + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", diff --git a/package.json b/package.json index 53365ac..c896b3d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ "bootstrap": "^5.2.2", "chance": "^1.1.9", "crypto-random-string": "^3.0.0", + "date-format": "^4.0.14", + "dateformat": "^5.0.3", "js-confetti": "^0.11.0", "next": "13.0.2", "next-auth": "4.16.4", diff --git a/pages/admin.tsx b/pages/admin.tsx index 5141444..cfbaf3f 100644 --- a/pages/admin.tsx +++ b/pages/admin.tsx @@ -1,6 +1,8 @@ import React, { useEffect, useState, useSyncExternalStore } from "react"; import prisma from '../lib/prisma' +import dateFormat, { masks } from "dateformat"; + import Image from 'next/image'; import * as Yup from 'yup'; @@ -14,6 +16,8 @@ import { AiOutlineCheck } from 'react-icons/ai' import Router from "next/router"; +import { useRouter } from 'next/navigation'; + import style from '../styles/Connexion.module.css'; @@ -92,11 +96,14 @@ const Admin = (props: Props) => { const [response, setResponse] = useState(null) const [currentUser, setCurrentUser] = useState(null) const [users, setUsers] = useState(props.users) + const [currentUserGain, setCurrentUserGain] = useState(null) + const router = useRouter() + const { register, setValue, handleSubmit, formState: { errors } } = useForm({ }); - const fetcher = async (url, method, body = {}) => { + const fetcher = async (url, method, body = {}, callback?: any) => { try { await fetch(url, { method, @@ -106,7 +113,7 @@ const Admin = (props: Props) => { .then((res) => res.json()) .then(async (data) => { setResponse(data); - setUsers(data.res) + callback; if (data.err) { toast.error(data.err, { position: "top-center", @@ -178,8 +185,10 @@ const Admin = (props: Props) => { fetcher('/api/user/delete', 'DELETE', body) }; - const selectUser = (user: User) => { + const selectUser = (user: any) => { + console.log('d', user.gains) setCurrentUser(user); + setCurrentUserGain(user.gains) setValue("name", user.name) setValue("email", user.email) setValue("surname", user.surname) @@ -188,6 +197,26 @@ const Admin = (props: Props) => { setValue("phoneNumber", user.phoneNumber) } + const changeGiftStatus = async (gain: Gain) => { + const body = { gain } + fetcher('/api/user/update-gift', 'PUT', body) + console.log('g', gain); + + // setCurrentUserGain(gain) + // router.refresh(); + }; + + + + + + + + + + + + return ( <> @@ -217,6 +246,7 @@ const Admin = (props: Props) => { {users.map((info: User, index: number) => { + return selectUser(info)}> {++index} {info.surname} @@ -320,19 +350,19 @@ const Admin = (props: Props) => { Codes joués Cadeaux Retiré en magasin - Retrait Date Retrait - {currentUser?.gains.map((gain: Gain, index: number) => { + {currentUserGain.map((gain: Gain, index: number) => { return {++index} {gain?.codeCadeau} {props.produits[gain.produitId - 1].nomProduit} {gain?.retrait ? '❌ déja récupéré' : '✔️ disponible'} + {gain?.dateRetrait ? dateFormat(gain?.dateRetrait, "dd/mm/yyyy") : ''} - + })} diff --git a/pages/api/superadmin/make-admin.ts b/pages/api/superadmin/make-admin.ts index 2f189b6..048d4cc 100644 --- a/pages/api/superadmin/make-admin.ts +++ b/pages/api/superadmin/make-admin.ts @@ -6,7 +6,7 @@ import prisma from '../../../lib/prisma'; //api qui va rendre un utilisateur admin (pour les developpeurs) -//--> http://localhost:3000/api/superadmin/admin?pass=1234 (a effacer) +//--> http://localhost:3000/api/superadmin/make-admin?pass=1234 (a effacer) export default async function makeMeAdmin(req: NextApiRequest, res: NextApiResponse) { const { pass } = req.query; @@ -23,7 +23,7 @@ export default async function makeMeAdmin(req: NextApiRequest, res: NextApiRespo role: Role.SUPERADMIN, }, }) - return res.status(200).send({ message: 'Profiled updated welcome SUPERADMIN !' }); + return res.status(200).send({ message: 'Profiled updated welcome ADMIN !' }); } else { res.status(401).send({ message: 'Unauthorized' }) } diff --git a/pages/api/user/update-gift.ts b/pages/api/user/update-gift.ts new file mode 100644 index 0000000..55d219b --- /dev/null +++ b/pages/api/user/update-gift.ts @@ -0,0 +1,84 @@ +import prisma from '../../../lib/prisma'; +import chance from 'chance' +import cryptoRandomString from 'crypto-random-string'; + + +import { NextApiRequest, NextApiResponse } from 'next'; +import { getSession } from 'next-auth/react'; +import { Cadeaux } from '../../../enum/cadeaux.enum'; +import { Role } from '../../../enum/role.enum'; +import { Gain } from '.prisma/client'; + + + +//API gain qui va generer un code cadeau qui sera sur la facture du client +//On part du principe qu'une 'API caisse'(qu'on ne gere pas) déclenche l'appel à l'API gain + +export default async function updtateGift(req: NextApiRequest, res: NextApiResponse) { + + + + const session = await getSession({ req }) + + const { gain } = req.body; + + // est-ce la méthode est un POST ou PUT? + // if (req.method !== ("POST" || 'PUT')) { + // throw new Error( + // `The HTTP ${req.method} method is not supported at this route.` + // ); + // } + + // est-ce que utilisateur est connecté ? + if (!session) { + res.status(401).json({ err: "Vous devez être connecté" }); + return; + } + + //récupération des gain de l'utilisateur et mise à jour + const updatedGain: Gain = await prisma.gain.update({ + where: { id: gain.id }, + data: { + retrait: true, + dateRetrait: new Date() + }, + }) + + const updatedCurrentUser = await prisma.user.findFirst({ + where: { id: updatedGain.userId }, + include: { gains: true } + }) + + // est-ce que utilisateur est un client classique ? Donc interdit pour lui de faire des updates + // A ACTIVER EN PRODUCTION + // if (user.role === 'USER') { + // res.status(401).json({ err: "Vous n'avez pas l'autorisation" }); + // return; + // } + + //////////////////////////////////////////////// + + + + + res.status(200).send({ message: `Le gain a ont été mis à jour !`, res: updatedCurrentUser }); + +} + + + + + + + + + + + + + + + + + + diff --git a/prisma/seed.ts b/prisma/seed.ts index 117a53e..b885125 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -37,8 +37,8 @@ async function main() { console.log(`Created user with id: ${user.id}`) } - //création de 5 gains - for (let i = 1; i <= 5; i++) { + //création de gains + for (let i = 1; i <= (50); i++) { await generateGains(); } diff --git a/styles/Index.module.css b/styles/Index.module.css index 5653a74..cba96bf 100644 --- a/styles/Index.module.css +++ b/styles/Index.module.css @@ -91,6 +91,7 @@ } @keyframes blinking { + 0%, 50%, 100% { @@ -113,7 +114,7 @@ .aButton { position: relative; - z-index: 9992; + z-index: 9000; } .aButton:after { @@ -276,4 +277,4 @@ 50% { right: 0; } -} */ +} */ \ No newline at end of file From 13c7f8511098fee8eabdfd51a04b47936ded493d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Dec 2022 20:23:57 +0100 Subject: [PATCH 5/8] add - test with playwright --- README.md | 3 +++ package-lock.json | 45 +++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +++- tests/contact.test.ts | 14 ++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/contact.test.ts diff --git a/README.md b/README.md index a104524..ccbff10 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ pour upgrade votre compte en superadmin (vous devez être connecté) http://localhost:3000/api/gain pour générer un gain (vous devez être connecté en tant que superadmin ou admin) +**npm run test** +tests faits avec Playwright + *********************************** diff --git a/package-lock.json b/package-lock.json index faac378..5f56962 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "yup-phone": "^1.3.2" }, "devDependencies": { + "@playwright/test": "^1.28.1", "@types/chance": "^1.1.3", "@types/next-auth": "3.13.0", "@types/node": "18.11.9", @@ -324,6 +325,22 @@ "url": "https://github.com/sponsors/panva" } }, + "node_modules/@playwright/test": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.1.tgz", + "integrity": "sha512-xN6spdqrNlwSn9KabIhqfZR7IWjPpFK1835tFNgjrlysaSezuX8PYUwaz38V/yI8TJLG9PkAMEXoHRXYXlpTPQ==", + "dev": true, + "dependencies": { + "@types/node": "*", + "playwright-core": "1.28.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/@popperjs/core": { "version": "2.11.6", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", @@ -2618,6 +2635,18 @@ "node": ">=4" } }, + "node_modules/playwright-core": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.1.tgz", + "integrity": "sha512-3PixLnGPno0E8rSBJjtwqTwJe3Yw72QwBBBxNoukIj3lEeBNXwbNiKrNuB1oyQgTBw5QHUhNO3SteEtHaMK6ag==", + "dev": true, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/postcss": { "version": "8.4.14", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", @@ -3926,6 +3955,16 @@ "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.0.2.tgz", "integrity": "sha512-MSAs9t3Go7GUkMhpKC44T58DJ5KGk2vBo+h1cqQeqlMfdGkxaVB78ZWpv9gYi/g2fa4sopag9gJsNvS8XGgWJA==" }, + "@playwright/test": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.1.tgz", + "integrity": "sha512-xN6spdqrNlwSn9KabIhqfZR7IWjPpFK1835tFNgjrlysaSezuX8PYUwaz38V/yI8TJLG9PkAMEXoHRXYXlpTPQ==", + "dev": true, + "requires": { + "@types/node": "*", + "playwright-core": "1.28.1" + } + }, "@popperjs/core": { "version": "2.11.6", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", @@ -5469,6 +5508,12 @@ "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", "integrity": "sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==" }, + "playwright-core": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.1.tgz", + "integrity": "sha512-3PixLnGPno0E8rSBJjtwqTwJe3Yw72QwBBBxNoukIj3lEeBNXwbNiKrNuB1oyQgTBw5QHUhNO3SteEtHaMK6ag==", + "dev": true + }, "postcss": { "version": "8.4.14", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", diff --git a/package.json b/package.json index c896b3d..dc7a21a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dev": "next", "build": "next build", "start": "next start", - "db": "npx prisma migrate reset --force" + "db": "npx prisma migrate reset --force", + "test": "playwright test" }, "dependencies": { "@hookform/resolvers": "^2.9.10", @@ -36,6 +37,7 @@ "yup-phone": "^1.3.2" }, "devDependencies": { + "@playwright/test": "^1.28.1", "@types/chance": "^1.1.3", "@types/next-auth": "3.13.0", "@types/node": "18.11.9", diff --git a/tests/contact.test.ts b/tests/contact.test.ts new file mode 100644 index 0000000..b9ef075 --- /dev/null +++ b/tests/contact.test.ts @@ -0,0 +1,14 @@ +// e2e/example.spec.ts + +import { test, expect } from '@playwright/test' + +test('navigate to /contact and check if h1 contains "Contactez nous"', async ({ page }) => { + // Start from the index page (the baseURL is set via the webServer in the playwright.config.ts) + await page.goto('http://localhost:3000/') + // Find an element with the text 'About Page' and click on it + await page.click('text=Contactez-nous') + // The new URL should be "/about" (baseURL is used there) + await expect(page).toHaveURL('http://localhost:3000/contact') + // The new page should contain an h1 with "About Page" + await expect(page.locator('h1')).toContainText('Contactez nous') +}) \ No newline at end of file From b19d1c2efedba30e6834d2b1e5079be5c0d05da5 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 10 Dec 2022 09:30:07 +0100 Subject: [PATCH 6/8] suppression fichier d'exemple --- .vscode/settings.json | 5 + pages/_fichier_exemple_/api/post/[id].ts | 26 --- pages/_fichier_exemple_/api/post/index.ts | 25 --- pages/_fichier_exemple_/api/profile/index.ts | 34 ---- pages/_fichier_exemple_/api/publish/[id].ts | 19 --- pages/_fichier_exemple_/create.tsx | 81 --------- pages/_fichier_exemple_/drafts.tsx | 78 --------- pages/_fichier_exemple_/p/[id].tsx | 91 ---------- pages/_fichier_exemple_/profile.tsx | 171 ------------------- pages/admin.tsx | 2 +- 10 files changed, 6 insertions(+), 526 deletions(-) delete mode 100644 pages/_fichier_exemple_/api/post/[id].ts delete mode 100644 pages/_fichier_exemple_/api/post/index.ts delete mode 100644 pages/_fichier_exemple_/api/profile/index.ts delete mode 100644 pages/_fichier_exemple_/api/publish/[id].ts delete mode 100644 pages/_fichier_exemple_/create.tsx delete mode 100644 pages/_fichier_exemple_/drafts.tsx delete mode 100644 pages/_fichier_exemple_/p/[id].tsx delete mode 100644 pages/_fichier_exemple_/profile.tsx diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a73a41..297b8d0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,2 +1,7 @@ { + "workbench.colorCustomizations": { + "activityBar.background": "#4C1F25", + "titleBar.activeBackground": "#6A2C34", + "titleBar.activeForeground": "#FEFCFC" + } } \ No newline at end of file diff --git a/pages/_fichier_exemple_/api/post/[id].ts b/pages/_fichier_exemple_/api/post/[id].ts deleted file mode 100644 index c25f56c..0000000 --- a/pages/_fichier_exemple_/api/post/[id].ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import { getSession } from 'next-auth/react'; -import prisma from '../../../../lib/prisma' - - -// DELETE /api/post/:id -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const postId = req.query.id; - - const session = await getSession({ req }) - - if (req.method === "DELETE") { - if (session) { - const post = await prisma.post.delete({ - where: { id: Number(postId) }, - }); - res.json(post); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } - } else { - throw new Error( - `The HTTP ${req.method} method is not supported at this route.` - ); - } -} diff --git a/pages/_fichier_exemple_/api/post/index.ts b/pages/_fichier_exemple_/api/post/index.ts deleted file mode 100644 index 3f8b12e..0000000 --- a/pages/_fichier_exemple_/api/post/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import prisma from '../../../../lib/prisma' -import { getSession } from 'next-auth/react' - - -// POST /api/post -// Required fields in body: title -// Optional fields in body: content -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const { title, content } = req.body; - - const session = await getSession({ req }); - if (session) { - const result = await prisma.post.create({ - data: { - title: title, - content: content, - author: { connect: { email: session?.user?.email } }, - }, - }); - res.json(result); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } -} diff --git a/pages/_fichier_exemple_/api/profile/index.ts b/pages/_fichier_exemple_/api/profile/index.ts deleted file mode 100644 index 2d03ede..0000000 --- a/pages/_fichier_exemple_/api/profile/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import prisma from '../../../../lib/prisma' -import { getSession } from 'next-auth/react' - - -// UPDATE /api/profile -// Required fields in body: title -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const { bioValue } = req.body; - console.log('server biovalue:', bioValue) - const session = await getSession({ req }); - - if (req.method === "PUT") { - if (session) { - const updateUserProfil = await prisma.user.update({ - where: { email: session.user.email }, - data: { - profile: { - update: { - bio: bioValue, - }, - }, - } - }) - res.status(200).send({ result: updateUserProfil, message: 'Profiled updated !' }); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } - } else { - throw new Error( - `The HTTP ${req.method} method is not supported at this route.` - ); - } -} \ No newline at end of file diff --git a/pages/_fichier_exemple_/api/publish/[id].ts b/pages/_fichier_exemple_/api/publish/[id].ts deleted file mode 100644 index 3d1f064..0000000 --- a/pages/_fichier_exemple_/api/publish/[id].ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import { getSession } from 'next-auth/react'; -import prisma from '../../../../lib/prisma' - -// PUT /api/publish/:id -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const postId = req.query.id; - const session = await getSession({ req }) - - if (session) { - const post = await prisma.post.update({ - where: { id: Number(postId) }, - data: { published: true }, - }); - res.json(post); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } -} diff --git a/pages/_fichier_exemple_/create.tsx b/pages/_fichier_exemple_/create.tsx deleted file mode 100644 index d9f8b1a..0000000 --- a/pages/_fichier_exemple_/create.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import React, { useState } from "react"; -import Layout from "../../components/Layout"; -import Router from "next/router"; - -const Draft = () => { - const [title, setTitle] = useState(""); - const [content, setContent] = useState(""); - - const submitData = async (e: React.SyntheticEvent) => { - e.preventDefault(); - try { - const body = { title, content }; - await fetch(`/api/post`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(body), - }); - await Router.push("/drafts"); - } catch (error) { - console.error(error); - } - }; - - return ( - -
-
-

New Draft

- setTitle(e.target.value)} - placeholder="Title" - type="text" - value={title} - /> -