@ -0,0 +1,25 @@
|
||||
SECRET=thetiptop123
|
||||
|
||||
NEXTAUTH_URL='http://localhost:3000'
|
||||
# GitHub oAuth
|
||||
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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
|
||||
|
||||
DATABASE_URL="postgres://postgres:postgrespwd@localhost:5432/thetiptop"
|
||||
|
||||
# Email (magic link)
|
||||
EMAIL_SERVER_USER=2bfdbee5372880
|
||||
EMAIL_SERVER_PASSWORD=af828174d7f2ad
|
||||
EMAIL_SERVER_HOST=smtp.mailtrap.io
|
||||
EMAIL_SERVER_PORT=2525
|
||||
EMAIL_FROM=thetiptop@test.com
|
||||
|
||||
DATABASE_URL="postgres://postgres:postgrespwd@127.0.0.1:5454/thetiptop"
|
||||
|
||||
API_KEY=1234
|
||||
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
.next/
|
||||
prisma/migrations
|
||||
@ -0,0 +1,32 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Next.js: debug server-side",
|
||||
"type": "node-terminal",
|
||||
"request": "launch",
|
||||
"command": "npm run dev"
|
||||
},
|
||||
{
|
||||
"name": "Next.js: debug client-side",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"url": "http://localhost:3000"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}\\pages\\moncompte.tsx",
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/**/*.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
import Image from 'next/image'
|
||||
import logo from '../public/images/logo.webp';
|
||||
import logoInstagram from '../public/images/logo instagram.webp';
|
||||
import logoLinkedin from '../public/images/logo linkedin.webp';
|
||||
import style from '../styles/Footer.module.css'
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
const Footer = () => {
|
||||
return (
|
||||
<footer className={`${style.footer}`}>
|
||||
<div className={`${style['footerContent']}`}>
|
||||
<div className="container p-3">
|
||||
<div className="row align-items-center">
|
||||
<div className="col-sm-6 col-md-3 d-flex justify-content-center">
|
||||
<Link href="/" passHref >
|
||||
<Image
|
||||
src={logo}
|
||||
alt="thetiptop navigation logo"
|
||||
width="110"
|
||||
height="110"
|
||||
/>
|
||||
</Link>
|
||||
</div>
|
||||
<div className="col-sm-6 col-md-3">
|
||||
|
||||
<ul className="nav flex-column justify-content-md-around align-content-center">
|
||||
<li className="nav-item px-2">
|
||||
<p>18 rue Léon Frot, 75 011 Paris</p>
|
||||
|
||||
</li>
|
||||
<li className="nav-item px-2">
|
||||
<p>01.65.38.94.23</p>
|
||||
</li>
|
||||
<li className="nav-item px-2">
|
||||
<p>contact@thetiptop.com</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div className="col-sm-6 col-md-3 d-flex justify-content-center align-items-md-baseline align-items-sm-center">
|
||||
|
||||
<ul className="nav flex-md-column">
|
||||
<li className="nav-item py-2 px-2">
|
||||
<Image src={logoInstagram} alt="lien instagram" width="40"
|
||||
height="40" />
|
||||
</li>
|
||||
<li className="nav-item py-2 px-2">
|
||||
<Image src={logoLinkedin} alt="lien linkedin" width="40"
|
||||
height="40" />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div className="col-sm-6 col-md-3">
|
||||
<ul className="nav flex-column justify-content-md-around justify-content-sm-center mx-5">
|
||||
<li className="nav-item">
|
||||
<Link href="/cgu" legacyBehavior >
|
||||
<a className='px-2'>CGU</a>
|
||||
</Link>
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<Link href="/mentions-legales" legacyBehavior >
|
||||
<a className='px-2'>Mentions légales</a>
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-center">Thé Tip Top © 2022 - projet fictif pour lequel aucun réel
|
||||
achat ou aucune réservation ne pourrait être effectué.</p>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
|
||||
export default Footer;
|
||||
@ -0,0 +1,17 @@
|
||||
import React, { ReactNode } from "react";
|
||||
import NavBar from "./NavBar";
|
||||
import Footer from "./Footer";
|
||||
|
||||
type Props = {
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
const Layout = ({ children }: Props) =>
|
||||
<div className="layout-container">
|
||||
<NavBar />
|
||||
{children}
|
||||
<Footer />
|
||||
</div>
|
||||
|
||||
export default Layout;
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
import React, { useRef } from "react";
|
||||
import logo from '../public/images/thetiptop_logo.webp';
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import style from '../styles/NavBar.module.css';
|
||||
import Image from 'next/image';
|
||||
|
||||
import { FiArrowRight } from 'react-icons/fi';
|
||||
|
||||
const NavBar = () => {
|
||||
const navRef = useRef<HTMLInputElement>();
|
||||
const router = useRouter();
|
||||
const { data: session, status } = useSession();
|
||||
console.log('role', session)
|
||||
|
||||
const closeNav = () => {
|
||||
navRef.current.style.height = "0%";
|
||||
}
|
||||
|
||||
const openNav = () => {
|
||||
navRef.current.style.height = "100%";
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
signOut()
|
||||
}
|
||||
|
||||
let visitor = (
|
||||
<nav className={`${style['navbar']}`}>
|
||||
|
||||
<div className="d-flex justify-content-center">
|
||||
<Image
|
||||
src={logo}
|
||||
alt="thetiptop navigation logo big"
|
||||
width={250}
|
||||
height={100}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className={`justify-content-center text-center ${style['hidden-mobile']}`}>
|
||||
<Link href="/" legacyBehavior><a className={style.link} >Accueil </a></Link><p>|</p>
|
||||
<Link href="/tout-savoir" legacyBehavior><a className={style.link} >Tout savoir</a></Link><p>|</p>
|
||||
<Link href="/contact" legacyBehavior><a className={style.link} >Contactez-nous</a></Link><p>|</p>
|
||||
{!session && <><Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link></>}
|
||||
{session && <><Link href="/mon-compte" legacyBehavior><a className={style.link} >Mon compte</a></Link><p>|</p></>}
|
||||
{session && <><Link href="#" legacyBehavior><a onClick={() => logout()} className={style.link} >Se déconnecter</a></Link></>}
|
||||
{session && <span className={`${style.connexion} badge rounded-pill bg-light text-dark`}>Vous-êtes connecté <FiArrowRight /> {session.user.email}</span>}
|
||||
|
||||
</div>
|
||||
<div className={`justify-content-center text-center ${style['show-mobile']}`}>
|
||||
<span className={`${style.burgerButton}`} onClick={openNav}>☰</span>
|
||||
</div>
|
||||
|
||||
<div className="d-flex justify-content-center">
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div ref={navRef} className={style.overlay} onClick={closeNav}>
|
||||
|
||||
<a className={style.closebtn} onClick={closeNav}>×</a>
|
||||
<div className="overlay-content">
|
||||
<Link href="/contact" legacyBehavior><a className={style.link} >Accueil</a></Link> |
|
||||
<Link href="/tout-savoir" legacyBehavior><a className={style.link} >Tout savoir</a></Link> |
|
||||
|
||||
|
||||
<Link href="/" legacyBehavior><a className={style.link} >Contactez-nous</a></Link> |
|
||||
<Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link>
|
||||
{session && <span className={`${style.connexion} badge rounded-pill bg-light text-dark`}><FiArrowRight />{session.user.email}</span>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
)
|
||||
|
||||
return (<>
|
||||
{visitor}
|
||||
</>)
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
export default NavBar;
|
||||
@ -0,0 +1,33 @@
|
||||
import React from "react";
|
||||
import Router from "next/router";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
|
||||
export type PostProps = {
|
||||
id: number;
|
||||
title: string;
|
||||
author: {
|
||||
name: string;
|
||||
email: string;
|
||||
} | null;
|
||||
content: string;
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
const Post = ( {post} : {post : PostProps}) => {
|
||||
const authorName = post.author ? post.author.name : "Unknown author";
|
||||
return (
|
||||
<div onClick={() => Router.push("/p/[id]", `/p/${post.id}`)}>
|
||||
<h2>{post.title}</h2>
|
||||
<small>By {authorName}</small>
|
||||
<ReactMarkdown children={post.content} />
|
||||
<style jsx>{`
|
||||
div {
|
||||
color: inherit;
|
||||
padding: 2rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Post;
|
||||
@ -0,0 +1,41 @@
|
||||
version: '3.5'
|
||||
|
||||
services:
|
||||
postgres:
|
||||
container_name: postgres_container
|
||||
image: postgres
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgrespwd}
|
||||
PGDATA: /data/postgres
|
||||
volumes:
|
||||
- postgres:/data/postgres
|
||||
ports:
|
||||
- "5454:5432"
|
||||
networks:
|
||||
- postgres
|
||||
restart: unless-stopped
|
||||
|
||||
pgadmin:
|
||||
container_name: pgadmin_container
|
||||
image: dpage/pgadmin4
|
||||
environment:
|
||||
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
|
||||
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
|
||||
PGADMIN_CONFIG_SERVER_MODE: 'False'
|
||||
volumes:
|
||||
- pgadmin:/var/lib/pgadmin
|
||||
|
||||
ports:
|
||||
- "${PGADMIN_PORT:-5050}:80"
|
||||
networks:
|
||||
- postgres
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
postgres:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
postgres:
|
||||
pgadmin:
|
||||
@ -0,0 +1,7 @@
|
||||
export enum Cadeaux {
|
||||
GrandCoffretDecouverte = 1,
|
||||
CoffretDecouverte = 2,
|
||||
TheSignature = 3,
|
||||
TheDetox = 4,
|
||||
Infuseur = 5,
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
export enum Role {
|
||||
USER = 'USER',
|
||||
ADMIN = 'ADMIN',
|
||||
SUPERADMIN = 'SUPERADMIN'
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
declare let global: { prisma: PrismaClient };
|
||||
|
||||
// PrismaClient is attached to the `global` object in development to prevent
|
||||
// exhausting your database connection limit.
|
||||
//
|
||||
// Learn more:
|
||||
// https://pris.ly/d/help/next-js-best-practices
|
||||
|
||||
let prisma: PrismaClient
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient()
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient()
|
||||
}
|
||||
prisma = global.prisma
|
||||
}
|
||||
export default prisma
|
||||
@ -0,0 +1,12 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import type { NextRequest } from 'next/server'
|
||||
|
||||
// This function can be marked `async` if using `await` inside
|
||||
export function middleware(request: NextRequest) {
|
||||
return NextResponse.redirect(new URL('/about-2', request.url))
|
||||
}
|
||||
|
||||
// See "Matching Paths" below to learn more
|
||||
export const config = {
|
||||
matcher: '/api/',
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
@ -0,0 +1,9 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
i18n: {
|
||||
locales: ["fr"],
|
||||
defaultLocale: "fr",
|
||||
},
|
||||
}
|
||||
|
||||
export default nextConfig;
|
||||
@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "hello-next",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"license": "MIT",
|
||||
"author": "",
|
||||
"scripts": {
|
||||
"dev": "next",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"db": "npx prisma migrate reset --force"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^2.9.10",
|
||||
"@next-auth/prisma-adapter": "1.0.5",
|
||||
"@prisma/client": "^4.6.1",
|
||||
"@types/nodemailer": "^6.4.6",
|
||||
"bootstrap": "^5.2.2",
|
||||
"chance": "^1.1.9",
|
||||
"crypto-random-string": "^3.0.0",
|
||||
"js-confetti": "^0.11.0",
|
||||
"next": "13.0.2",
|
||||
"next-auth": "4.16.4",
|
||||
"nodemailer": "^6.8.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"react-hook-form": "^7.39.2",
|
||||
"react-icons": "^4.6.0",
|
||||
"react-markdown": "8.0.3",
|
||||
"react-toastify": "^9.1.1",
|
||||
"yup": "^0.32.11",
|
||||
"yup-phone": "^1.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chance": "^1.1.3",
|
||||
"@types/next-auth": "3.13.0",
|
||||
"@types/node": "18.11.9",
|
||||
"@types/react": "18.0.25",
|
||||
"prisma": "^4.6.1",
|
||||
"ts-node": "10.9.1",
|
||||
"typescript": "4.8.4"
|
||||
},
|
||||
"prisma": {
|
||||
"seed": "ts-node prisma/seed.ts"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
import React from "react";
|
||||
import Head from "next/head";
|
||||
|
||||
const NotFound = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Page introuvable</title>
|
||||
<meta name="description" content="Page introuvable" />
|
||||
<meta name="robots" content="index, follow" />
|
||||
<meta name="googlebot" content="index, follow" />
|
||||
<meta name="googlebot-news" content="index, follow" />
|
||||
<meta name="slurp" content="index, follow" />
|
||||
<meta name="msnbot" content="index, follow" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
{/* backgroundImagePath={'/images/ugh.png'} */}
|
||||
<div className="body-content position-relative">
|
||||
<div className="position-absolute top-50 start-50 translate-middle">
|
||||
<h1 className="">Page introuvable</h1>
|
||||
<h4 className="fw-light">La page recherchée n'existe pas.</h4>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default NotFound;
|
||||
@ -0,0 +1,27 @@
|
||||
import { SessionProvider } from "next-auth/react";
|
||||
import { AppProps } from "next/app";
|
||||
import { useEffect } from "react";
|
||||
|
||||
import 'bootstrap/dist/css/bootstrap.css'
|
||||
import "../styles/globals.css";
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import Layout from "../components/Layout";
|
||||
|
||||
const App = ({ Component, pageProps }: AppProps) => {
|
||||
useEffect(() => {
|
||||
import("bootstrap/dist/js/bootstrap");
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<SessionProvider session={pageProps.session}>
|
||||
<Layout>
|
||||
<Component {...pageProps} />
|
||||
|
||||
</Layout>
|
||||
<ToastContainer />
|
||||
</SessionProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
@ -0,0 +1,26 @@
|
||||
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.`
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
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' })
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
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.`
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
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' })
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
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 (
|
||||
<Layout>
|
||||
<div>
|
||||
<form onSubmit={submitData}>
|
||||
<h1>New Draft</h1>
|
||||
<input
|
||||
autoFocus
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="Title"
|
||||
type="text"
|
||||
value={title}
|
||||
/>
|
||||
<textarea
|
||||
cols={50}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
placeholder="Content"
|
||||
rows={8}
|
||||
value={content}
|
||||
/>
|
||||
<input disabled={!content || !title} type="submit" value="Create" />
|
||||
<a className="back" href="#" onClick={() => Router.push("/")}>
|
||||
or Cancel
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
<style jsx>{`
|
||||
.page {
|
||||
background: white;
|
||||
padding: 3rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
margin: 0.5rem 0;
|
||||
border-radius: 0.25rem;
|
||||
border: 0.125rem solid rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
input[type="submit"] {
|
||||
background: #ececec;
|
||||
border: 0;
|
||||
padding: 1rem 2rem;
|
||||
}
|
||||
|
||||
.back {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Draft;
|
||||
@ -0,0 +1,78 @@
|
||||
import React from "react";
|
||||
import { GetServerSideProps } from "next";
|
||||
import Layout from "../../components/Layout";
|
||||
import Post, { PostProps } from "../../components/Post";
|
||||
import { useSession, getSession } from "next-auth/react";
|
||||
import prisma from '../../lib/prisma'
|
||||
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
|
||||
const session = await getSession({ req });
|
||||
if (!session) {
|
||||
res.statusCode = 403;
|
||||
return { props: { drafts: [] } };
|
||||
}
|
||||
|
||||
const drafts = await prisma.post.findMany({
|
||||
where: {
|
||||
author: { email: session.user.email },
|
||||
published: false,
|
||||
},
|
||||
include: {
|
||||
author: {
|
||||
select: { name: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
return {
|
||||
props: { drafts },
|
||||
};
|
||||
};
|
||||
|
||||
type Props = {
|
||||
drafts: PostProps[];
|
||||
};
|
||||
|
||||
const Drafts = (props: Props) => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
if (!session) {
|
||||
return (
|
||||
<Layout>
|
||||
<h1>My Drafts</h1>
|
||||
<div>You need to be authenticated to view this page.</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div className="page">
|
||||
<h1>My Drafts</h1>
|
||||
<main>
|
||||
{props.drafts.map((post) => (
|
||||
<div key={post.id} className="post">
|
||||
<Post post={post} />
|
||||
</div>
|
||||
))}
|
||||
</main>
|
||||
</div>
|
||||
<style jsx>{`
|
||||
.post {
|
||||
background: white;
|
||||
transition: box-shadow 0.1s ease-in;
|
||||
}
|
||||
|
||||
.post:hover {
|
||||
box-shadow: 1px 1px 3px #aaa;
|
||||
}
|
||||
|
||||
.post + .post {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Drafts;
|
||||
@ -0,0 +1,91 @@
|
||||
import React from "react";
|
||||
import { GetServerSideProps } from "next";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import Layout from "../../../components/Layout";
|
||||
import Router from "next/router";
|
||||
import { PostProps } from "../../../components/Post";
|
||||
import prisma from '../../../lib/prisma'
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async ({ params }) => {
|
||||
const post = await prisma.post.findUnique({
|
||||
where: {
|
||||
id: Number(params?.id) || -1,
|
||||
},
|
||||
include: {
|
||||
author: {
|
||||
select: { name: true, email: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
return {
|
||||
props: post,
|
||||
};
|
||||
};
|
||||
|
||||
async function publishPost(id: number): Promise<void> {
|
||||
await fetch(`/api/publish/${id}`, {
|
||||
method: "PUT",
|
||||
});
|
||||
await Router.push("/")
|
||||
}
|
||||
|
||||
async function deletePost(id: number): Promise<void> {
|
||||
await fetch(`/api/post/${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
await Router.push("/")
|
||||
}
|
||||
|
||||
const Post = (props: PostProps) => {
|
||||
const { data: session, status } = useSession();
|
||||
if (status === 'loading') {
|
||||
return <div>Authenticating ...</div>;
|
||||
}
|
||||
const userHasValidSession = Boolean(session);
|
||||
const postBelongsToUser = session?.user?.email === props.author?.email;
|
||||
let title = props.title;
|
||||
if (!props.published) {
|
||||
title = `${title} (Draft)`;
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div>
|
||||
<h2>{title}</h2>
|
||||
<p>By {props?.author?.name || "Unknown author"}</p>
|
||||
<ReactMarkdown children={props.content} />
|
||||
{!props.published && userHasValidSession && postBelongsToUser && (
|
||||
<button onClick={() => publishPost(props.id)}>Publish</button>
|
||||
)}
|
||||
{userHasValidSession && postBelongsToUser && (
|
||||
<button onClick={() => deletePost(props.id)}>Delete</button>
|
||||
)}
|
||||
</div>
|
||||
<style jsx>{`
|
||||
.page {
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #ececec;
|
||||
border: 0;
|
||||
border-radius: 0.125rem;
|
||||
padding: 1rem 2rem;
|
||||
}
|
||||
|
||||
button + button {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Post;
|
||||
@ -0,0 +1,171 @@
|
||||
import React, { useState } from "react";
|
||||
import { GetServerSideProps } from "next";
|
||||
import Layout from "../../components/Layout";
|
||||
import { useSession, getSession } from "next-auth/react";
|
||||
import prisma from '../../lib/prisma'
|
||||
import Router from "next/router";
|
||||
import { ProfileProps } from "../../types/profile";
|
||||
import { Resolver, SubmitHandler } from "react-hook-form";
|
||||
|
||||
|
||||
//https://www.bezkoder.com/react-hook-form-typescript/
|
||||
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import * as Yup from 'yup';
|
||||
|
||||
type UserSubmitForm = {
|
||||
bio: string;
|
||||
};
|
||||
|
||||
type Profil = {
|
||||
isUserProfile: any;
|
||||
}
|
||||
|
||||
interface ResponseData {
|
||||
result: string;
|
||||
message: string
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
|
||||
const session = await getSession({ req });
|
||||
|
||||
//pas de session ? on ne retourne un code erreur
|
||||
//voir pour rediriger vers la page de connection
|
||||
//ou afficher pop up "vous n'est pas connecter"
|
||||
if (!session) {
|
||||
res.statusCode = 403;
|
||||
return { props: { profile: null } };
|
||||
}
|
||||
|
||||
// si session ? on récupére le profil de l'utilisateur si il existe
|
||||
if (session) {
|
||||
const isUserProfile = await prisma.profile.findMany({
|
||||
where: {
|
||||
user: { email: session.user.email },
|
||||
}
|
||||
})
|
||||
console.log('profil utilisateur ?', isUserProfile);
|
||||
|
||||
|
||||
// il n'existe pas ? on le crée
|
||||
if (isUserProfile.length <= 0) {
|
||||
const newProfil = await prisma.profile.create({
|
||||
data: {
|
||||
bio: "",
|
||||
user: {
|
||||
connect: { email: session.user.email },
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log('newProfil', newProfil);
|
||||
|
||||
}
|
||||
|
||||
// on renvoi le profil
|
||||
return { props: { isUserProfile } };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const Profil = ({ isUserProfile }: Profil) => {
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
bio: Yup.string().trim().required("ce champ ne peux etre vide..."),
|
||||
});
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors }
|
||||
} = useForm<UserSubmitForm>({
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
|
||||
const [response, setResponse] = useState<ResponseData | undefined>();
|
||||
const { data: session } = useSession();
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log('user profil props', isUserProfile)
|
||||
}, [])
|
||||
|
||||
const onSubmit = async (data: UserSubmitForm) => {
|
||||
console.log(data);
|
||||
|
||||
try {
|
||||
const body = { bioValue: data.bio };
|
||||
await fetch(`/api/profile`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setResponse(data);
|
||||
console.log('response', data);
|
||||
})
|
||||
await Router.push("/profile");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
if (!session) {
|
||||
return (
|
||||
<Layout>
|
||||
<h1>Mon Compte</h1>
|
||||
<div>Vous devez être authentifié pour voir cette page.</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div className="page">
|
||||
<h1>Mon compte</h1>
|
||||
<main>
|
||||
|
||||
<div className="register-form">
|
||||
<p>Ma bio : {isUserProfile[0]?.bio}</p>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="form-group">
|
||||
<label>Ma bio :</label>
|
||||
<input
|
||||
placeholder="Ma bio..."
|
||||
defaultValue={isUserProfile[0]?.bio}
|
||||
type="text"
|
||||
{...register('bio')}
|
||||
className={`form-control ${errors.bio ? 'is-invalid' : ''}`}
|
||||
/>
|
||||
<div className="invalid-feedback">{errors.bio?.message}</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="form-group">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Valider les changements
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => reset()}
|
||||
className="btn btn-warning float-right"
|
||||
>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<p>Email : {session.user.email}</p>
|
||||
{response && <p>{response.message}</p>}
|
||||
</main>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
export default Profil;
|
||||
@ -0,0 +1,52 @@
|
||||
import { NextApiHandler } from "next";
|
||||
import NextAuth from "next-auth";
|
||||
import Providers from "next-auth/providers";
|
||||
import { PrismaAdapter } from '@next-auth/prisma-adapter'
|
||||
import GoogleProvider from "next-auth/providers/google";
|
||||
import EmailProvider from 'next-auth/providers/email'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
|
||||
const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options);
|
||||
export default authHandler;
|
||||
|
||||
const options = {
|
||||
providers: [
|
||||
GoogleProvider({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
authorization: 'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code',
|
||||
}),
|
||||
EmailProvider({
|
||||
server: {
|
||||
host: process.env.EMAIL_SERVER_HOST,
|
||||
port: parseInt(process.env.EMAIL_SERVER_PORT),
|
||||
auth: {
|
||||
user: process.env.EMAIL_SERVER_USER,
|
||||
pass: process.env.EMAIL_SERVER_PASSWORD
|
||||
}
|
||||
},
|
||||
from: process.env.EMAIL_FROM
|
||||
}),
|
||||
],
|
||||
adapter: PrismaAdapter(prisma),
|
||||
secret: process.env.SECRET,
|
||||
callbacks: {
|
||||
async session({ session, user }) {
|
||||
const getCurrentUser = await prisma.user.findMany({
|
||||
where: { email: session.user.email },
|
||||
})
|
||||
//récupération du role
|
||||
const { role } = getCurrentUser[0];
|
||||
session.user.role = role
|
||||
return session
|
||||
}
|
||||
},
|
||||
pages: {
|
||||
signIn: '/',
|
||||
signOut: '/mon-compte',
|
||||
error: '/auth/error', // Error code passed in query string as ?error=
|
||||
verifyRequest: '/verify-request', // (used for check email message)
|
||||
// newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,105 @@
|
||||
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';
|
||||
|
||||
|
||||
|
||||
//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 generationGain(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({ req })
|
||||
|
||||
//récuperation des tickets disponible
|
||||
const getTickets = await prisma.ticketsRestants.findFirst({
|
||||
where: {
|
||||
id: 1
|
||||
},
|
||||
})
|
||||
|
||||
const { total } = getTickets;
|
||||
const isTicketsAvaible = total > 0;
|
||||
|
||||
//récupération des informations de l'utilisateur connecté
|
||||
const getCurrentUser = await prisma.user.findMany({
|
||||
where: { email: session.user.email },
|
||||
})
|
||||
|
||||
//récupération du role
|
||||
const { role } = getCurrentUser[0];
|
||||
const isAdmin = role === Role.ADMIN;
|
||||
const isSuperAdmin = Role.SUPERADMIN;
|
||||
|
||||
if (session && isTicketsAvaible) {
|
||||
if (isAdmin || isSuperAdmin) {
|
||||
|
||||
//creation d'un numéro de gain aléatoire
|
||||
const gainNumber = cryptoRandomString({ length: 10, type: 'distinguishable' });
|
||||
|
||||
|
||||
//création d'un id de produit de façon pondérée
|
||||
let weightedRandomGainId = chance().weighted([
|
||||
Cadeaux.GrandCoffretDecouverte,
|
||||
Cadeaux.CoffretDecouverte,
|
||||
Cadeaux.TheSignature,
|
||||
Cadeaux.TheDetox,
|
||||
Cadeaux.Infuseur],
|
||||
[4, 6, 10, 20, 60]);
|
||||
|
||||
//création d'un gain
|
||||
const gainCreated = await prisma.gain.create({
|
||||
data: {
|
||||
codeCadeau: gainNumber,
|
||||
}
|
||||
})
|
||||
|
||||
//mise à jour du gain avec l'id de produit pondéré
|
||||
const gainResult = await prisma.gain.update({
|
||||
where: { id: gainCreated.id },
|
||||
data: {
|
||||
produitId: weightedRandomGainId,
|
||||
}
|
||||
})
|
||||
|
||||
//on retire 1 ticket
|
||||
await prisma.ticketsRestants.update({
|
||||
where: {
|
||||
id: getTickets.id
|
||||
},
|
||||
data: {
|
||||
total: {
|
||||
decrement: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
res.status(200).send({ message: 'Gain has been generated !', result: gainResult });
|
||||
}
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/react';
|
||||
import { Role } from '../../../enum/role.enum';
|
||||
import prisma from '../../../lib/prisma';
|
||||
|
||||
|
||||
//api qui va rendre un utilisateur super admin (pour les developpeurs)
|
||||
//--> http://localhost:3000/api/superadmin?pass=1234 (a effacer)
|
||||
|
||||
export default async function makeMeSuper(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { pass } = req.query;
|
||||
const session = await getSession({ req })
|
||||
const goodPassword = pass === '1234';
|
||||
|
||||
//si utilisateur connecté et que le parametre 'pass' est '1234'
|
||||
if (session && goodPassword) {
|
||||
|
||||
//MAJ de l'utilisateur en superadmin
|
||||
await prisma.user.update({
|
||||
where: { email: session.user.email },
|
||||
data: {
|
||||
role: Role.SUPERADMIN,
|
||||
},
|
||||
})
|
||||
return res.status(200).send({ message: 'Profiled updated welcome SUPERADMIN !' });
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,111 @@
|
||||
import prisma from '../../../lib/prisma';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/react';
|
||||
import { Cadeaux } from '../../../enum/cadeaux.enum';
|
||||
import { Role } from '../../../enum/role.enum';
|
||||
|
||||
|
||||
//API gain qui va tester le code cadeau
|
||||
|
||||
export default async function testCode(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({ req })
|
||||
const { codeCadeau } = req.body;
|
||||
const regex = /[A-Z0-9]{10}/;
|
||||
|
||||
// est-ce la méthode est un POST ?
|
||||
if (req.method !== "POST") {
|
||||
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: 'Connectez-vous pour tester votre code !' });
|
||||
return;
|
||||
}
|
||||
|
||||
//est-ce que le code tapé par l'utilisateur est valide ?
|
||||
const isValidCodeCadeau = codeCadeau.match(regex);
|
||||
if (!isValidCodeCadeau) {
|
||||
res.status(401).json({ err: 'Ce code est invalide' });
|
||||
return
|
||||
}
|
||||
|
||||
//si oui ? récupération des informations concernant le code
|
||||
const codeCadeauInfo = await prisma.gain.findUnique({
|
||||
where: { codeCadeau }
|
||||
})
|
||||
|
||||
//check si le code a déja été utilisé
|
||||
if (!codeCadeauInfo.actif) {
|
||||
res.status(401).json({ err: 'Ce code a déja été utilisé' });
|
||||
return;
|
||||
}
|
||||
|
||||
//CODE BON ? =>
|
||||
//récupération des informations de l'utilisateur connecté
|
||||
const getCurrentUser = await prisma.user.findMany({
|
||||
where: { email: session.user.email },
|
||||
})
|
||||
|
||||
//ajout du gain au profil de l'utilisateur
|
||||
const joinGain = await prisma.gain.update({
|
||||
where: { codeCadeau: codeCadeauInfo.codeCadeau },
|
||||
data: {
|
||||
userId: getCurrentUser[0].id
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
//mise à jour de la date ou le ticket est utilisé
|
||||
|
||||
//retire un ticket du total de ticket restant
|
||||
const ticketUpdate = await prisma.ticketsRestants.update({
|
||||
where: {
|
||||
id: 1
|
||||
},
|
||||
data: {
|
||||
total: {
|
||||
decrement: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
//passage du code en non-actif
|
||||
const codeUpdate = await prisma.gain.update({
|
||||
where: {
|
||||
id: codeCadeauInfo.id
|
||||
},
|
||||
data: {
|
||||
actif: false,
|
||||
}
|
||||
})
|
||||
|
||||
//retourne l'id du produit gagné
|
||||
const winProduct = await prisma.produit.findFirst({
|
||||
where: {
|
||||
id: codeCadeauInfo.produitId
|
||||
}
|
||||
})
|
||||
|
||||
res.status(200).send({ success: 'Vous avez gagner un gain !', winProduct });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
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';
|
||||
|
||||
|
||||
|
||||
//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 updateOrCreate(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({ req })
|
||||
const { address, name, phoneNumber, surname, zipCode } = 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 informations de l'utilisateur connecté
|
||||
const user = await prisma.user.findFirst({
|
||||
where: { email: session.user.email },
|
||||
})
|
||||
|
||||
//mise a jour ou création des données pour l'utilisateur
|
||||
const upsertUser = await prisma.user.upsert({
|
||||
where: {
|
||||
email: user.email,
|
||||
},
|
||||
update: {
|
||||
name,
|
||||
surname,
|
||||
address,
|
||||
phoneNumber,
|
||||
zipCode
|
||||
},
|
||||
create: {
|
||||
name,
|
||||
surname,
|
||||
address,
|
||||
phoneNumber,
|
||||
zipCode
|
||||
},
|
||||
})
|
||||
res.status(200).send({ message: 'Vos informations ont été mise à jours !', res: upsertUser });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
import React, { useEffect } from "react";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
|
||||
import Image from 'next/image';
|
||||
import * as Yup from 'yup';
|
||||
import Head from "next/head";
|
||||
import { getCsrfToken, signIn, useSession } from "next-auth/react";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { AiOutlineCheck } from 'react-icons/ai'
|
||||
|
||||
import Router from "next/router";
|
||||
|
||||
|
||||
import style from '../styles/Connexion.module.css';
|
||||
|
||||
import imageConnexion from '../public/images/connexion_image.png'
|
||||
|
||||
|
||||
import Link from "next/link";
|
||||
|
||||
import { GrValidate } from 'react-icons/gr'
|
||||
import { toast } from "react-toastify";
|
||||
import { Token } from "nodemailer/lib/xoauth2";
|
||||
import { isGeneratorFunction } from "util/types";
|
||||
|
||||
|
||||
|
||||
const AuthError = () => {
|
||||
|
||||
//va rediriger après 3 seconde
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
Router.push("/")
|
||||
}, 3000)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Page Confirmation email</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
|
||||
<div className={`${style['masthead']} d-flex justify-content-center align-items-center text-center`}>
|
||||
<div className="container align-items-center d-flex flex-column">
|
||||
|
||||
|
||||
<div className={`${style['bloc-content']} col-12 col-lg-6`}>
|
||||
<h1 className="fw-light">Un email a été envoyé</h1>
|
||||
<GrValidate size={100} />
|
||||
<div className="d-grid mt-4">
|
||||
<button onClick={() => Router.push("/")} type="button" className={`btn btn-primary`}>
|
||||
Cliquez ici si vous n'êtes pas rediriger à l'accueil
|
||||
</button>
|
||||
</div>
|
||||
</div >
|
||||
</div>
|
||||
</div>
|
||||
</>)
|
||||
};
|
||||
|
||||
export default AuthError;
|
||||
|
||||
|
||||
@ -0,0 +1,187 @@
|
||||
import React from "react";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
import Image from 'next/image';
|
||||
import * as Yup from 'yup';
|
||||
import Head from "next/head";
|
||||
import { getCsrfToken, signIn, useSession } from "next-auth/react";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { AiOutlineGoogle } from 'react-icons/ai'
|
||||
|
||||
import Router from "next/router";
|
||||
|
||||
|
||||
import style from '../styles/Connexion.module.css';
|
||||
|
||||
import imageConnexion from '../public/images/connexion_image.png'
|
||||
|
||||
|
||||
import Link from "next/link";
|
||||
|
||||
import { SiGnuprivacyguard } from 'react-icons/si'
|
||||
import { toast } from "react-toastify";
|
||||
import { Token } from "nodemailer/lib/xoauth2";
|
||||
import { isGeneratorFunction } from "util/types";
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const csrfToken = await getCsrfToken(context)
|
||||
return {
|
||||
props: { csrfToken },
|
||||
}
|
||||
}
|
||||
|
||||
type LoginSubmitForm = {
|
||||
email: string,
|
||||
acceptTerms: boolean
|
||||
};
|
||||
|
||||
type Props = {
|
||||
csrfToken: Token
|
||||
}
|
||||
|
||||
const MainPage = ({ csrfToken }: Props) => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
// email: Yup.string().email(
|
||||
// "Veuillez rentrer une adresse mail valide"
|
||||
// ),
|
||||
// acceptTerms: Yup.bool().oneOf(
|
||||
// [true],
|
||||
// "Vous devez accepter les conditions obligatoire"
|
||||
// )
|
||||
})
|
||||
|
||||
const {
|
||||
register,
|
||||
clearErrors,
|
||||
handleSubmit,
|
||||
watch,
|
||||
trigger,
|
||||
formState: { errors }
|
||||
} = useForm<LoginSubmitForm>({
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
|
||||
const acceptTermCheckBox = watch("acceptTerms")
|
||||
|
||||
const connexionWithGoogle = async () => {
|
||||
if (onCheckTerms()) {
|
||||
signIn("google", { callbackUrl: `${window.location.origin}/mon-compte` })
|
||||
}
|
||||
await trigger("acceptTerms");
|
||||
}
|
||||
|
||||
const onMailSubmit = async (data: LoginSubmitForm) => {
|
||||
if (onCheckTerms()) {
|
||||
signIn("email", { email: data.email, callbackUrl: `${window.location.origin}/create` })
|
||||
}
|
||||
await trigger("acceptTerms");
|
||||
await trigger("email");
|
||||
}
|
||||
|
||||
|
||||
|
||||
const onCheckTerms = () => {
|
||||
if (acceptTermCheckBox) {
|
||||
return true;
|
||||
} else {
|
||||
toast.error('Vous devez accepter les conditions obligatoires', {
|
||||
position: "top-center",
|
||||
autoClose: 2000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// try {
|
||||
// const body = { bioValue: data.bio };
|
||||
// await fetch(`/api/profile`, {
|
||||
// method: "POST",
|
||||
// headers: { "Content-Type": "application/json" },
|
||||
// body: JSON.stringify(body),
|
||||
// })
|
||||
// .then((res) => res.json())
|
||||
// .then((data) => {
|
||||
// setResponse(data);
|
||||
// console.log('response', data);
|
||||
// })
|
||||
// await Router.push("/profile");
|
||||
// } catch (error) {
|
||||
// console.error(error);
|
||||
// }
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Connexion</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
|
||||
<div className={`${style['masthead']} d-flex justify-content-center align-items-center text-center`}>
|
||||
<div className="container align-items-center d-flex flex-column">
|
||||
|
||||
|
||||
|
||||
<div className={`${style['bloc-content']} col-12 col-md-6`}>
|
||||
<h1 className="fw-light">Connexion</h1>
|
||||
|
||||
<SiGnuprivacyguard size={50} />
|
||||
<form onSubmit={handleSubmit(onMailSubmit)}>
|
||||
<div className="form-group mx-auto my-3 w-100">
|
||||
<input
|
||||
type="email" id="email" name="email"
|
||||
className={`mb-3 form-control ${errors.email ? 'is-invalid' : ''}`}
|
||||
placeholder="Email..."
|
||||
{...register("email")}
|
||||
/>
|
||||
<div className="d-grid">
|
||||
<button type="submit" className="btn d-grid btn-primary">
|
||||
Se connecter avec mon email
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div className="d-grid">
|
||||
<button onClick={connexionWithGoogle} type="button" className={`btn btn-primary ${style.loginButton}`} style={{ backgroundColor: "#dd4b39" }}>
|
||||
<span className={style.logo}><AiOutlineGoogle /></span>Se connecter avec google
|
||||
</button>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label
|
||||
htmlFor="acceptTerms"
|
||||
className="form-check-label"
|
||||
>
|
||||
J'ai lu et j'accepte les
|
||||
conditions
|
||||
</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
className={`form-check-input ${errors.acceptTerms ? 'is-invalid' : ''}`}
|
||||
{...register("acceptTerms")}
|
||||
name="acceptTerms"
|
||||
id="acceptTerms"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</div >
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</>)
|
||||
};
|
||||
|
||||
export default MainPage;
|
||||
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
import React from "react";
|
||||
import Head from "next/head";
|
||||
|
||||
|
||||
const Contact = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Contact</title>
|
||||
<meta name="description" content="Contact" />
|
||||
<meta name="robots" content="index, follow" />
|
||||
<meta name="googlebot" content="index, follow" />
|
||||
<meta name="googlebot-news" content="index, follow" />
|
||||
<meta name="slurp" content="index, follow" />
|
||||
<meta name="msnbot" content="index, follow" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
<div className="container">
|
||||
<h1 className="text-center py-2 py-md-3">Contactez nous</h1>
|
||||
<div className="row pt-2 pb-3">
|
||||
<div className="col-12 col-md-6">
|
||||
<h2 className="text-center pb-4">Nos coordonées</h2>
|
||||
<div className="px-2">
|
||||
<h2>Par téléphone</h2>
|
||||
<a href="tel:0165389423">01.65.38.94.23</a>
|
||||
<h2 className="mt-3">Par mail</h2>
|
||||
<a href="mailto:contact@thetiptop.com">contact@thetiptop.com</a>
|
||||
<h2 className="mt-3">Sur nos réseaux</h2>
|
||||
<div>Réseau 1</div>
|
||||
<div>Réseau 2</div>
|
||||
<div>Réseau 3</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12 col-md-6 text-center">
|
||||
<h2 className="text-center pb-3">Notre siège</h2>
|
||||
<iframe width="300" height="300" id="gmap_canvas" src="https://maps.google.com/maps?q=18%20rue%20L%C3%A9on%20Frot,%2075%20011%20Paris&t=&z=17&ie=UTF8&iwloc=&output=embed" frameBorder="0" scrolling="no" marginHeight={0} marginWidth={0}>
|
||||
</iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Contact;
|
||||
@ -0,0 +1,264 @@
|
||||
import React, { useState } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
import Image from 'next/image';
|
||||
import * as Yup from 'yup';
|
||||
import Head from "next/head";
|
||||
import { getSession, useSession } from "next-auth/react";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { useForm } from "react-hook-form";
|
||||
import Router from "next/router";
|
||||
|
||||
|
||||
import style from '../styles/Index.module.css';
|
||||
|
||||
import rotatingLeftImage from '../public/images/coffret-degustation.webp';
|
||||
import rotatingRightImage from '../public/images/coffret-degustation2.webp';
|
||||
import Link from "next/link";
|
||||
|
||||
import testerCodeCadeau from '../public/images/svg/testerlecode.svg'
|
||||
import feuilleGauche from '../public/images/feuilleGauche.webp'
|
||||
import feuilleDroite from '../public/images/feuilleBasDroite.webp'
|
||||
import unAnDeThe from '../public/images/unandethé.webp'
|
||||
import sablier from '../public/images/sablier.webp'
|
||||
import cadeau from '../public/images/cadeau.webp'
|
||||
import jeuConcours from '../public/images/jeuconcours.webp'
|
||||
import { GetServerSideProps } from "next";
|
||||
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
|
||||
|
||||
import arrowUp from '../public/images/png/arrowup.png'
|
||||
|
||||
import footerGrass from '../public/images/footer_image.webp'
|
||||
|
||||
|
||||
type CodeSubmitForm = {
|
||||
codeCadeau: string;
|
||||
};
|
||||
|
||||
type ResponseData = {
|
||||
success: string,
|
||||
winProduct: {
|
||||
actif: boolean,
|
||||
id: number,
|
||||
nomProduit: string,
|
||||
prixTtc: number
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const MainPage = () => {
|
||||
|
||||
const { data: session } = useSession();
|
||||
const [response, setResponse] = useState<ResponseData | null>(null)
|
||||
const [winAnimation, setWinAnimation] = useState(false)
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
// codeCadeau: Yup.string().trim().required("Veuillez rentrer un code cadeau !"),
|
||||
});
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors }
|
||||
} = useForm<CodeSubmitForm>({
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
|
||||
const mountedStyle = {
|
||||
animation: "inAnimation 250ms ease-in"
|
||||
};
|
||||
const unmountedStyle = {
|
||||
animation: "outAnimation 270ms ease-out",
|
||||
animationFillMode: "forwards"
|
||||
};
|
||||
|
||||
|
||||
const onSubmit = async (data: CodeSubmitForm) => {
|
||||
|
||||
if (!errors) {
|
||||
if (!session) {
|
||||
return <Layout>
|
||||
<p>Vous devez vous connecter pour tester votre code cadeau!</p>
|
||||
</Layout>
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const body = { codeCadeau: data.codeCadeau };
|
||||
await fetch(`/api/testcode`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then(async (data) => {
|
||||
setResponse(data);
|
||||
if (data.err) {
|
||||
console.log('ERR', data);
|
||||
toast.error(data.err, {
|
||||
position: "top-center",
|
||||
autoClose: 2000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
return;
|
||||
// await Router.push("/profile");
|
||||
}
|
||||
setWinAnimation(true)
|
||||
await confettiTime();
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('ERROR :', error);
|
||||
}
|
||||
};
|
||||
|
||||
const confettiTime = async (): Promise<void> => {
|
||||
const JSConfetti = (await import('js-confetti')).default
|
||||
const jsConfetti = new JSConfetti()
|
||||
jsConfetti.addConfetti()
|
||||
}
|
||||
|
||||
const getCadeau = () => {
|
||||
Router.push("/mon-compte")
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Thé Tip Top</title>
|
||||
<meta name="description" content="Participez au jeu concours Thé Tip Top ! Recevez un cadeau, et tentez votre chance pour gagner le gros lot final !" />
|
||||
<meta name="robots" content="index, follow" />
|
||||
<meta name="googlebot" content="index, follow" />
|
||||
<meta name="googlebot-news" content="index, follow" />
|
||||
<meta name="slurp" content="index, follow" />
|
||||
<meta name="msnbot" content="index, follow" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
|
||||
<div className={`${style['masthead']} body-content`}>
|
||||
<div className="d-flex flex-wrap justify-content-center align-items-center text-center">
|
||||
<div className={`${style['feuilleGauche']} ${style['imageContainer']}`}>
|
||||
<Image
|
||||
src={feuilleGauche}
|
||||
alt="thetiptop feuille Gauche"
|
||||
layout="responsive"
|
||||
className={`${style['rotatingSlow']}`}
|
||||
/>
|
||||
</div>
|
||||
<div className={`${style['jeuConcours']} ${style['imageContainer']}`}>
|
||||
<Image
|
||||
src={jeuConcours}
|
||||
alt="thetiptop jeu Concours"
|
||||
layout="responsive"
|
||||
className={`${style['zoomInOutCadeau']}`}
|
||||
/>
|
||||
</div>
|
||||
<div className={`${style['cadeau']} ${style['imageContainer']}`}>
|
||||
<Image
|
||||
src={cadeau}
|
||||
alt="thetiptop cadeau"
|
||||
layout="responsive"
|
||||
className={`${style['zoomInOutJeuConcours']}`}
|
||||
/>
|
||||
</div>
|
||||
<div className={`${style['feuilleDroite']} ${style['imageContainer']}`}>
|
||||
<Image
|
||||
src={feuilleDroite}
|
||||
alt="thetiptop feuille Droite"
|
||||
layout="responsive"
|
||||
className={`${style['rotatingSlow']}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!winAnimation && <div className="col-12 align-items-center d-flex flex-column">
|
||||
<div className={`${style['bloc-content']} col-12 col-md-6`}>
|
||||
<div className={`${style['imageWrapper']}`}>
|
||||
<Image
|
||||
src={testerCodeCadeau}
|
||||
alt="thetiptop navigation logo"
|
||||
layout="responsive"
|
||||
className={`${style['rotatingImage']}`}
|
||||
/>
|
||||
</div>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="form-group mx-auto my-3 w-100">
|
||||
<input type="text"
|
||||
id="codeInput" aria-describedby="codeHelp"
|
||||
placeholder="A293049430..."
|
||||
minLength={10}
|
||||
maxLength={10}
|
||||
{...register('codeCadeau')}
|
||||
className={`form-control ${errors.codeCadeau ? 'is-invalid' : ''}`}
|
||||
|
||||
/>
|
||||
<small id="codeHelp" className="form-text text-muted">Code à usage unique</small>
|
||||
<div className="invalid-feedback alert alert-danger">{errors.codeCadeau?.message}</div>
|
||||
</div>
|
||||
<div className="form-group mx-auto my-3 w-100">
|
||||
<button type="submit" className={`${style['aButton']} btn btn-primary`}>Découvrir mon cadeau !</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>}
|
||||
|
||||
|
||||
{winAnimation && <div className="col-12 align-items-center d-flex flex-column">
|
||||
|
||||
<div className={`${style['cadeau-bloc-content']} col-12 col-md-6`} onClick={() => setWinAnimation(false)}
|
||||
>
|
||||
<div className={`${style['cadeau-bloc']}`}>
|
||||
<h1>Vous avez gagnez : un {response.winProduct.nomProduit} !</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={`${style['imageWrapper']}`}>
|
||||
<Image
|
||||
src={arrowUp}
|
||||
alt="thetiptop flèche haute"
|
||||
|
||||
width={50}
|
||||
height={50}
|
||||
className={`${style['rotatingImage']}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div className="row">
|
||||
<button onClick={getCadeau} className={`${style['aButton']} btn btn-primary`}>Voir mes cadeaux !</button>
|
||||
<button onClick={() => setWinAnimation(false)} className={`${style['aButton']} btn btn-primary mt-2`}>Rejouer un ticket !</button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>}
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div className={`${style['footerGrass']} position-absolute`}>
|
||||
<Image
|
||||
src={footerGrass}
|
||||
alt="thetiptop feuille Gauche"
|
||||
layout="responsive"
|
||||
// className={`${style['footerGrass']}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default MainPage;
|
||||
@ -0,0 +1,294 @@
|
||||
import React, { useEffect, useState, useSyncExternalStore } from "react";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
|
||||
import Image from 'next/image';
|
||||
import * as Yup from 'yup';
|
||||
import Head from "next/head";
|
||||
import { getCsrfToken, getSession, signIn, useSession } from "next-auth/react";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import "yup-phone";
|
||||
import { SubmitHandler, useForm } from "react-hook-form";
|
||||
|
||||
import { AiOutlineCheck } from 'react-icons/ai'
|
||||
|
||||
import Router from "next/router";
|
||||
|
||||
|
||||
import style from '../styles/Connexion.module.css';
|
||||
|
||||
import imageConnexion from '../public/images/connexion_image.png'
|
||||
|
||||
|
||||
import Link from "next/link";
|
||||
|
||||
|
||||
|
||||
import { TfiInfoAlt } from 'react-icons/tfi'
|
||||
import { TfiGift } from 'react-icons/tfi'
|
||||
|
||||
|
||||
import { toast } from "react-toastify";
|
||||
import { Token } from "nodemailer/lib/xoauth2";
|
||||
import { isGeneratorFunction } from "util/types";
|
||||
import { UserProps } from "../types/user";
|
||||
import { UserGainProps } from "../types/userGain";
|
||||
import { Gain, Produit, User } from "@prisma/client";
|
||||
|
||||
|
||||
type FormData = {
|
||||
email: string;
|
||||
name: string;
|
||||
surname: string;
|
||||
address: string;
|
||||
zipCode: number;
|
||||
phoneNumber: number;
|
||||
};
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const session = await getSession(context)
|
||||
|
||||
if (!session) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/',
|
||||
permanent: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
email: session?.user.email
|
||||
}
|
||||
});
|
||||
|
||||
const userGains = await prisma.gain.findMany({
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
include: {
|
||||
produit: true
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
props: {
|
||||
user: JSON.parse(JSON.stringify(user)),
|
||||
userGains,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type Props = {
|
||||
user: User;
|
||||
userGains: any;
|
||||
}
|
||||
|
||||
const MonCompte = (props: Props) => {
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
const [response, setResponse] = useState(null)
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
name: Yup.string()
|
||||
.trim()
|
||||
.min(2, "le nom doit comporter au moins 2 caractères")
|
||||
.max(20, "le nom ne doit pas dépasser 20 caractères"),
|
||||
surname: Yup.string()
|
||||
.trim()
|
||||
.min(2, "le prenom doit comporter au moins 2 caractères")
|
||||
.max(20, "le prenom ne doit pas dépasser 20 caractères"),
|
||||
address: Yup.string()
|
||||
.trim()
|
||||
.max(50, "l'adresse ne doit pas dépasser 50 caractères"),
|
||||
zipCode: Yup.number()
|
||||
.typeError("le code postal est invalide"),
|
||||
phoneNumber: Yup.string()
|
||||
.phone("FR", true, "le numéro de téléphone est invalide")
|
||||
});
|
||||
|
||||
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
|
||||
const onSubmit = async ({
|
||||
email,
|
||||
name,
|
||||
surname,
|
||||
address,
|
||||
zipCode,
|
||||
phoneNumber }: FormData) => {
|
||||
try {
|
||||
const body = {
|
||||
email,
|
||||
name,
|
||||
surname,
|
||||
address,
|
||||
zipCode: Number(zipCode),
|
||||
phoneNumber: Number(phoneNumber),
|
||||
};
|
||||
await fetch(`/api/user/`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then(async (data) => {
|
||||
setResponse(data);
|
||||
if (data.err) {
|
||||
toast.error(data.err, {
|
||||
position: "top-center",
|
||||
autoClose: 2000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
return;
|
||||
}
|
||||
toast.success(data.message, {
|
||||
position: "top-center",
|
||||
autoClose: 5000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('ERROR :', error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Mon Compte</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
|
||||
<div className={`${style['masthead']} d-flex justify-content-center align-items-center text-center`}>
|
||||
<div className="container align-items-center d-flex flex-column">
|
||||
|
||||
<div className={`${style['bloc-content']} col-12 col-md-12`}>
|
||||
|
||||
<div className="row">
|
||||
<div className="col-md-6 col-sm-12">
|
||||
<hr />
|
||||
<h1 className="fw-light">Mes informations <TfiInfoAlt size={40} /></h1>
|
||||
<hr />
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="form-group">
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="staticEmail" className="col-sm-3 col-form-label">Email :</label>
|
||||
<div className="col-sm-9">
|
||||
<input type="text" readOnly className="form-control-plaintext text-sm-center" id="staticEmail" value={session?.user.email || ''} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="inputName" className="col-sm-3 col-form-label">Nom :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("name")} className={`form-control ${errors.name ? 'is-invalid' : ''}`} defaultValue={props.user.name} id="inputName" placeholder="John..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.name?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="surname" className="col-sm-3 col-form-label">Prenom :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("surname")} className={`form-control ${errors.surname ? 'is-invalid' : ''}`} defaultValue={props.user.surname} id="surname" placeholder="Doe..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.surname?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="address" className="col-sm-3 col-form-label">Adresse :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("address")} className={`form-control ${errors.address ? 'is-invalid' : ''}`} defaultValue={props.user.address} id="address" placeholder="1 rue de la paix..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.address?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="zipCode" className="col-sm-3 col-form-label">Code postale :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("zipCode")} className={`form-control ${errors.zipCode ? 'is-invalid' : ''}`} defaultValue={props.user.zipCode} id="zipCode" placeholder="95000..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.zipCode?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="phoneNumber" className="col-sm-3 col-form-label">Téléphone :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("phoneNumber")} className={`form-control ${errors.phoneNumber ? 'is-invalid' : ''}`} defaultValue={props.user.phoneNumber} id="phoneNumber" placeholder="0123456789..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.phoneNumber?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-primary mt-2"
|
||||
>
|
||||
Sauvegarder les changements
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<div className="col-md-6 col-sm-12">
|
||||
<hr />
|
||||
<h1 className="fw-light">Mes cadeaux <TfiGift size={40} /></h1>
|
||||
<hr />
|
||||
{props.userGains.length <= 0 && <p>Pas encore de cadeau gagné</p>}
|
||||
{props.userGains.length >= 1 &&
|
||||
<table className="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Mes codes joué</th>
|
||||
<th scope="col">Mes cadeaux</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{props.userGains.map((info: any) => {
|
||||
return <tr>
|
||||
<th scope="row"></th>
|
||||
<td>{info.codeCadeau}</td>
|
||||
<td>{info.produit.nomProduit}</td>
|
||||
</tr>
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div >
|
||||
|
||||
</div>
|
||||
</div >
|
||||
</>)
|
||||
};
|
||||
|
||||
export default MonCompte;
|
||||
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
{/* <div className={`${style['bloc-content']} col-12 col-md-10 d-flex row my-2 mx-0 py-2 py-md-2 px-0 px-md-3 `}>
|
||||
<h2 className="col-12 my-2">A gagner</h2>
|
||||
<div className="col d-flex justify-content-center">
|
||||
<div className={`${style['productToGain']}`}>
|
||||
<Image
|
||||
src={rotatingRightImage}
|
||||
alt="coffret de thé marron rempli de sachets de toutes couleurs"
|
||||
fill
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col d-flex justify-content-center">
|
||||
<div className={`${style['productToGain']}`}>
|
||||
<Image
|
||||
src={rotatingRightImage}
|
||||
alt="coffret de thé marron rempli de sachets de toutes couleurs"
|
||||
fill
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col d-flex justify-content-center">
|
||||
<div className={`${style['productToGain']}`}>
|
||||
<Image
|
||||
src={rotatingRightImage}
|
||||
alt="coffret de thé marron rempli de sachets de toutes couleurs"
|
||||
fill
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<div className='btn btn-primary my-2'>
|
||||
<Link href="shop">Et bien d'autres !</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div> */}
|
||||
|
||||
|
||||
|
||||
{/* <Section backgroundImagePath={'/images/three-cups-of-tea-steeping.png'}>
|
||||
<h2>Présentation du jeu concours</h2>
|
||||
<h4 className="fw-light">
|
||||
Gagnez de superbes cadeaux en achetant nos produits !
|
||||
<br />
|
||||
Pour participer, il vous suffit d'effectuer un achat en boutique d'une valeur supérieure à XXX euros. Retrouvez votre code sur la facture !
|
||||
<br />
|
||||
Saisissez votre code ... Félicitations ! Vous avez gagné un cadeau ! Il nous vous reste plus qu'à le récupérer en magasin.
|
||||
<br />
|
||||
Après la [XXX période], vous participerez au jeu concours final afin de gagner XXX. Un participation par personne est comptabilisée pour le concours final.
|
||||
</h4>
|
||||
</Section>
|
||||
<Section backgroundImagePath={'/images/top-view-of-a-tea-towel-and-container-holding-grain.png'}>
|
||||
<h2>Présentation de Thé Tip Top</h2>
|
||||
<h4 className="fw-light">
|
||||
Thé Tip Top est une entreprise de thé [XXX ajouter des spécifications en se basant sur le cahier des charges]
|
||||
</h4>
|
||||
</Section> */}
|
||||
@ -0,0 +1,108 @@
|
||||
import React from "react";
|
||||
import Image from 'next/image';
|
||||
import Head from "next/head";
|
||||
import style from '../styles/ToutSavoir.module.css'
|
||||
|
||||
|
||||
import test from '../public/images/tea-with-three-jars.webp';
|
||||
import prisma from "../lib/prisma";
|
||||
import Link from "next/link";
|
||||
|
||||
export async function getStaticProps() {
|
||||
const produits = await prisma.produit.findMany();
|
||||
|
||||
return {
|
||||
props: {
|
||||
produits,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type Props = {
|
||||
produits: Produit[];
|
||||
}
|
||||
|
||||
type Produit = {
|
||||
id: number;
|
||||
actif: boolean;
|
||||
nomProduit: string;
|
||||
prixTtc: number;
|
||||
image: string;
|
||||
}
|
||||
|
||||
const ToutSavoir = ({ produits }: Props) => {
|
||||
console.log('p', produits);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Tout savoir</title>
|
||||
<meta name="description" content="Tout savoir" />
|
||||
<meta name="robots" content="index, follow" />
|
||||
<meta name="googlebot" content="index, follow" />
|
||||
<meta name="googlebot-news" content="index, follow" />
|
||||
<meta name="slurp" content="index, follow" />
|
||||
<meta name="msnbot" content="index, follow" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
{/* backgroundImagePath={'/images/ugh.png'} */}
|
||||
<div className="body-content">
|
||||
<h1 className="text-center mt-3">Tout savoir sur le jeu concours</h1>
|
||||
<div className="container mt-3 ">
|
||||
<p className={`${style.explicationContainer} mt-lg-5`}>
|
||||
Le jeu concours vous est proposé à l'occasion de l'ouverture de notre 10e boutique à Nice !
|
||||
<br /> Pour participer, il vous suffit de faire un achat supérieur à 49€, un code vous sera fourni sur votre facture à saisir <Link href="/" legacyBehavior><a className={`link`}>ici</a></Link>
|
||||
<br />Le concours est effectif <b>du 12/12/2022 au 12/01/2023</b>. Vous pouvez récupérer votre lot dès la saisie de votre code.
|
||||
<br />A la fin du concours, vous pouvez encore récupérer votre cadeau pendant <b>1mois</b>, c'est à dire jusqu'au <b>12/02/2023</b>.
|
||||
</p>
|
||||
<div className={`${style.grosLot} row justify-content-between my-lg-5`}>
|
||||
<div className="col-12 col-lg-4">
|
||||
<Image
|
||||
className="card-img-top" src={test}
|
||||
width="286"
|
||||
height="180"
|
||||
alt="produit"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-12 col-lg-8 mt-3 mt-lg-0">
|
||||
<div className="px-5 h-100 d-flex flex-column">
|
||||
<h2 className="text-center">Le gros lot</h2>
|
||||
<div className="h-100 d-flex align-items-center">
|
||||
<div>
|
||||
En participant au moins une fois à notre jeu concours, vous vous qualifiez pour gagner le gros lot : <b>1 an de thé</b> d'une valeur de 360€ !
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row justify-content-center">
|
||||
{produits.map((produit: Produit) => {
|
||||
return <div className="col-12 col-lg-4 d-flex justify-content-center my-2 my-lg-3" key={produit.id}>
|
||||
<div className={`${style.aCard} card`}>
|
||||
<div className="d-flex justify-content-center p-0">
|
||||
<Image
|
||||
className="card-img-top" src={produit.image}
|
||||
width="286"
|
||||
height="180"
|
||||
alt="produit"
|
||||
/>
|
||||
</div>
|
||||
<div className="card-body d-flex flex-column h-100">
|
||||
<h5 className="card-title">{produit.nomProduit}</h5>
|
||||
<p className="card-text d-flex flex-column h-100">{produit.description}
|
||||
<br />
|
||||
<b className="mt-auto pt-2">Prix conseillé : {produit.prixTtc} €</b>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ToutSavoir;
|
||||
@ -0,0 +1,68 @@
|
||||
import React, { useEffect } from "react";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
|
||||
import Image from 'next/image';
|
||||
import * as Yup from 'yup';
|
||||
import Head from "next/head";
|
||||
import { getCsrfToken, signIn, useSession } from "next-auth/react";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { AiOutlineCheck } from 'react-icons/ai'
|
||||
|
||||
import Router from "next/router";
|
||||
|
||||
|
||||
import style from '../styles/Connexion.module.css';
|
||||
|
||||
import imageConnexion from '../public/images/connexion_image.png'
|
||||
|
||||
|
||||
import Link from "next/link";
|
||||
|
||||
import { GrValidate } from 'react-icons/gr'
|
||||
import { toast } from "react-toastify";
|
||||
import { Token } from "nodemailer/lib/xoauth2";
|
||||
import { isGeneratorFunction } from "util/types";
|
||||
|
||||
|
||||
|
||||
const VerifyRequest = () => {
|
||||
|
||||
//va rediriger après 3 seconde
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
Router.push("/")
|
||||
}, 3000)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Page Confirmation email</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
|
||||
<div className={`${style['masthead']} d-flex justify-content-center align-items-center text-center`}>
|
||||
<div className="container align-items-center d-flex flex-column">
|
||||
|
||||
|
||||
<div className={`${style['bloc-content']} col-12 col-md-6`}>
|
||||
<h1 className="fw-light">Un email a été envoyé</h1>
|
||||
<GrValidate size={100} />
|
||||
<div className="d-grid mt-4">
|
||||
<button onClick={() => Router.push("/")} type="button" className={`btn btn-primary`}>
|
||||
Cliquez ici si vous n'êtes pas redirigé à l'accueil
|
||||
</button>
|
||||
</div>
|
||||
</div >
|
||||
</div>
|
||||
</div>
|
||||
</>)
|
||||
};
|
||||
|
||||
export default VerifyRequest;
|
||||
|
||||
|
||||
@ -0,0 +1,101 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Account {
|
||||
id Int @id @default(autoincrement())
|
||||
userId Int @map("user_id")
|
||||
type String
|
||||
provider String
|
||||
providerAccountId String @map("provider_account_id")
|
||||
refresh_token String?
|
||||
access_token String?
|
||||
expires_at Int?
|
||||
token_type String?
|
||||
scope String?
|
||||
id_token String?
|
||||
session_state String?
|
||||
oauth_token_secret String?
|
||||
oauth_token String?
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([provider, providerAccountId])
|
||||
@@map("accounts")
|
||||
}
|
||||
|
||||
model Session {
|
||||
id Int @id @default(autoincrement())
|
||||
sessionToken String @unique @map("session_token")
|
||||
userId Int @map("user_id")
|
||||
expires DateTime
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("sessions")
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
name String?
|
||||
surname String?
|
||||
address String?
|
||||
zipCode Int?
|
||||
phoneNumber Int?
|
||||
email String? @unique
|
||||
emailVerified DateTime? @map("email_verified")
|
||||
image String?
|
||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||
updatedAt DateTime @updatedAt @map(name: "updated_at")
|
||||
accounts Account[]
|
||||
sessions Session[]
|
||||
gain Gain[]
|
||||
role Role @default(USER)
|
||||
|
||||
@@map(name: "users")
|
||||
}
|
||||
|
||||
model TicketsRestants {
|
||||
id Int @id @default(autoincrement())
|
||||
total Int
|
||||
}
|
||||
|
||||
model Gain {
|
||||
id Int @id @default(autoincrement())
|
||||
codeCadeau String @unique
|
||||
dateRetrait DateTime?
|
||||
produit Produit? @relation(fields: [produitId], references: [id])
|
||||
produitId Int?
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
userId Int?
|
||||
actif Boolean @default(true)
|
||||
}
|
||||
|
||||
model Produit {
|
||||
id Int @id @default(autoincrement())
|
||||
actif Boolean?
|
||||
nomProduit String?
|
||||
prixTtc Int?
|
||||
image String?
|
||||
description String?
|
||||
refGain Gain[]
|
||||
}
|
||||
|
||||
enum Role {
|
||||
USER
|
||||
ADMIN
|
||||
SUPERADMIN
|
||||
}
|
||||
|
||||
model VerificationToken {
|
||||
identifier String
|
||||
token String @unique
|
||||
expires DateTime
|
||||
|
||||
@@unique([identifier, token])
|
||||
@@map("verificationtokens")
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
// import prisma from '../lib/prisma'
|
||||
|
||||
import { generateGains } from './seed/gains'
|
||||
import { produitsData } from './seed/produits'
|
||||
// import { userData } from './seed/user'
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log(`Start seeding ...`)
|
||||
|
||||
//création des tickets restants
|
||||
const tickets = await prisma.ticketsRestants.create({
|
||||
data: {
|
||||
total: 1500000
|
||||
},
|
||||
})
|
||||
console.log(`Created ticket: ${tickets.total}`)
|
||||
|
||||
|
||||
//création des produits
|
||||
for (const p of produitsData) {
|
||||
const produit = await prisma.produit.create({
|
||||
data: p,
|
||||
})
|
||||
console.log(`Created produit: ${produit.nomProduit}`)
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
//création des utilisateurs
|
||||
// for (const u of userData) {
|
||||
// const user = await prisma.user.create({
|
||||
// data: u,
|
||||
// })
|
||||
// console.log(`Created user with id: ${user.id}`)
|
||||
// }
|
||||
|
||||
//création de 5 gains
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
await generateGains();
|
||||
}
|
||||
|
||||
console.log(`Seeding finished.`)
|
||||
}
|
||||
|
||||
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
.catch(async (e) => {
|
||||
console.error(e)
|
||||
await prisma.$disconnect()
|
||||
process.exit(1)
|
||||
})
|
||||
@ -0,0 +1,50 @@
|
||||
// import { produits } from './produits';
|
||||
import prisma from '../../lib/prisma'
|
||||
import { Chance } from 'chance'
|
||||
import { Cadeaux } from '../../enum/cadeaux.enum';
|
||||
import cryptoRandomString from 'crypto-random-string';
|
||||
let chance = new Chance();
|
||||
|
||||
export const generateGains = async () => {
|
||||
//génération d'un code cadeau
|
||||
const randomNoGain = cryptoRandomString({ length: 10, type: 'distinguishable' });
|
||||
|
||||
//création d'un gain
|
||||
const gainCreated = await prisma.gain.create({
|
||||
data: {
|
||||
codeCadeau: randomNoGain,
|
||||
}
|
||||
})
|
||||
|
||||
//crétion d'un id de produit de façon pondérée
|
||||
let weightedRandomGain = chance.weighted([
|
||||
Cadeaux.GrandCoffretDecouverte,
|
||||
Cadeaux.CoffretDecouverte,
|
||||
Cadeaux.TheSignature,
|
||||
Cadeaux.TheDetox,
|
||||
Cadeaux.Infuseur],
|
||||
[4, 6, 10, 20, 60]);
|
||||
|
||||
//mise à jour du gain avec l'id de produit pondéré
|
||||
const gainUpdated = await prisma.gain.update({
|
||||
where: { id: gainCreated.id },
|
||||
data: {
|
||||
produitId: weightedRandomGain,
|
||||
}
|
||||
})
|
||||
//on retire 1 ticket
|
||||
await prisma.ticketsRestants.update({
|
||||
where: {
|
||||
id: 1
|
||||
},
|
||||
data: {
|
||||
total: {
|
||||
decrement: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log(`Created gain ! : ${gainUpdated.codeCadeau}`)
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
export const userData: Prisma.UserCreateInput[] = [
|
||||
{
|
||||
name: 'Alice',
|
||||
email: 'alice@prisma.io',
|
||||
posts: {
|
||||
create: [
|
||||
{
|
||||
title: 'Join the Prisma Slack',
|
||||
content: 'https://slack.prisma.io',
|
||||
published: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Nilu',
|
||||
email: 'nilu@prisma.io',
|
||||
posts: {
|
||||
create: [
|
||||
{
|
||||
title: 'Follow Prisma on Twitter',
|
||||
content: 'https://www.twitter.com/prisma',
|
||||
published: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Mahmoud',
|
||||
email: 'mahmoud@prisma.io',
|
||||
posts: {
|
||||
create: [
|
||||
{
|
||||
title: 'Ask a question about Prisma on GitHub',
|
||||
content: 'https://www.github.com/prisma/prisma/discussions',
|
||||
published: true,
|
||||
},
|
||||
{
|
||||
title: 'Prisma on YouTube',
|
||||
content: 'https://pris.ly/youtube',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
After Width: | Height: | Size: 114 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 2.6 MiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 760 KiB |
|
After Width: | Height: | Size: 358 KiB |
|
After Width: | Height: | Size: 7.1 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 7.1 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 2.8 MiB |
|
After Width: | Height: | Size: 575 KiB |
|
After Width: | Height: | Size: 11 MiB |
|
After Width: | Height: | Size: 900 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 186 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 278 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 497 KiB |
|
After Width: | Height: | Size: 5.9 MiB |
|
After Width: | Height: | Size: 5.7 MiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 16 MiB |
|
After Width: | Height: | Size: 20 MiB |
|
After Width: | Height: | Size: 332 KiB |
|
After Width: | Height: | Size: 552 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 226 KiB |
|
After Width: | Height: | Size: 787 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 713 KiB |
|
After Width: | Height: | Size: 726 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 662 KiB |
|
After Width: | Height: | Size: 21 MiB |
|
After Width: | Height: | Size: 10 MiB |
|
After Width: | Height: | Size: 17 MiB |
|
After Width: | Height: | Size: 13 MiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 452 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 549 KiB |