Compare commits
No commits in common. 'master' and 'feature/custom-mail' have entirely different histories.
master
...
feature/cu
@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"env": {
|
|
||||||
"development": {
|
|
||||||
"presets": ["next/babel"]
|
|
||||||
},
|
|
||||||
"production": {
|
|
||||||
"presets": ["next/babel"]
|
|
||||||
},
|
|
||||||
"test": {
|
|
||||||
"presets": ["@babel/env", "@babel/react"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
FROM node:alpine
|
|
||||||
|
|
||||||
#copy source
|
|
||||||
COPY . /app
|
|
||||||
|
|
||||||
# Install deps
|
|
||||||
RUN cd /app && npm install
|
|
||||||
|
|
||||||
# Build
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
ENTRYPOINT [ "npm", "run", "start" ]
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
stages {
|
|
||||||
stage('Env reinit') {
|
|
||||||
steps {
|
|
||||||
sh '''echo "
|
|
||||||
NEXTAUTH_URL=\'https://devops.dsp-archiwebo21-ad-ec-cb-mt.fr\'
|
|
||||||
DATABASE_URL="postgres://postgres:dandanalaa@127.0.0.1:5454/thetiptop"
|
|
||||||
|
|
||||||
GITHUB_ID=YOUR_GITHUB_CLIENT_ID
|
|
||||||
GITHUB_SECRET=YOUR_GITHUB_CLIENT_SECRET
|
|
||||||
|
|
||||||
GOOGLE_CLIENT_ID=965228443747-049kq59pm43bd23aplfu9ja2333dpo5s.apps.googleusercontent.com
|
|
||||||
GOOGLE_CLIENT_SECRET=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
|
|
||||||
|
|
||||||
EMAIL_SERVER_USER=contact@dsp-archiwebo21-ad-ec-cb-mt.fr
|
|
||||||
EMAIL_SERVER_PASSWORD=Acem@2022a
|
|
||||||
EMAIL_SERVER_HOST=mail50.lwspanel.com
|
|
||||||
EMAIL_SERVER_PORT=587
|
|
||||||
EMAIL_FROM=contact@dsp-archiwebo21-ad-ec-cb-mt.fr
|
|
||||||
|
|
||||||
SECRET=thetiptop123
|
|
||||||
|
|
||||||
" > ./.env
|
|
||||||
cat ./.env'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build') {
|
|
||||||
steps {
|
|
||||||
sh '''npm install
|
|
||||||
npm run build
|
|
||||||
npm start & sleep 1'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Test') {
|
|
||||||
steps {
|
|
||||||
sh 'npm test & sleep 1'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Deliver') {
|
|
||||||
steps {
|
|
||||||
sh '''chmod +x ./scripts/deliver.sh
|
|
||||||
./scripts/deliver.sh'''
|
|
||||||
input 'Finished using the web site? (Click "Proceed")'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
tools {
|
|
||||||
nodejs 'Node 16.18'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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;
|
||||||
@ -1,14 +0,0 @@
|
|||||||
// 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')
|
|
||||||
})
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const nextJest = require('next/jest')
|
|
||||||
|
|
||||||
const createJestConfig = nextJest({
|
|
||||||
dir: './',
|
|
||||||
})
|
|
||||||
|
|
||||||
const customJestConfig = {
|
|
||||||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
|
||||||
moduleDirectories: ['node_modules', '<rootDir>/'],
|
|
||||||
testEnvironment: 'jest-environment-jsdom',
|
|
||||||
testRegex: '(/__tests__/.*|(\\.|/)(test))\\.[jt]sx?$'
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = createJestConfig(customJestConfig)
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
// Optional: configure or set up a testing framework before each test.
|
|
||||||
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`
|
|
||||||
|
|
||||||
// Used for __tests__/testing-library.js
|
|
||||||
// Learn more: https://github.com/testing-library/jest-dom
|
|
||||||
import '@testing-library/jest-dom/extend-expect'
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
/** @type {import('next-sitemap').IConfig} */
|
|
||||||
module.exports = {
|
|
||||||
siteUrl: process.env.NEXTAUTH_URL || 'https://dsp-archiwebo21-ad-ec-cb-mt.fr/',
|
|
||||||
generateRobotsTxt: true
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -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,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' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
import prisma from '../../../lib/prisma';
|
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
|
||||||
import { getSession } from 'next-auth/react';
|
|
||||||
import { Role } from '../../../enum/role.enum';
|
|
||||||
|
|
||||||
export default async function updateUser(req: NextApiRequest, res: NextApiResponse) {
|
|
||||||
const session = await getSession({ req })
|
|
||||||
const { selectedUserEmail } = req.body
|
|
||||||
|
|
||||||
|
|
||||||
// est-ce la méthode est un POST ou PUT?
|
|
||||||
if (!(['POST', 'PUT'].indexOf(req.method) > -1)) {
|
|
||||||
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 },
|
|
||||||
})
|
|
||||||
|
|
||||||
// est-ce que utilisateur est un client classique ? Donc interdit pour lui
|
|
||||||
// A ACTIVER EN PRODUCTION
|
|
||||||
if (user.role === 'USER') {
|
|
||||||
res.status(401).json({ err: "Vous n'avez pas l'autorisation" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//mise a jour des données de l'utilisateur séléctionné
|
|
||||||
const updatedUser = await prisma.user.update({
|
|
||||||
where: {
|
|
||||||
email: selectedUserEmail,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
isBigWinner: true
|
|
||||||
},
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
//renvoi la liste des users mis à jour
|
|
||||||
const users = await prisma.user.findMany({})
|
|
||||||
|
|
||||||
console.log(updatedUser);
|
|
||||||
return res.status(200).send({ message: `${selectedUserEmail} est le grand gagnant !`, res: users });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
import prisma from '../../../lib/prisma';
|
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
|
||||||
import { getSession } from 'next-auth/react';
|
|
||||||
|
|
||||||
export default async function updateOrCreate(req: NextApiRequest, res: NextApiResponse) {
|
|
||||||
const session = await getSession({ req })
|
|
||||||
const { targetUserMail } = req.body;
|
|
||||||
|
|
||||||
// est-ce la méthode est un POST ou PUT?
|
|
||||||
if (!(['POST'].indexOf(req.method) > -1)) {
|
|
||||||
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: targetUserMail },
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
res.status(200).send({ message: 'user :', res: user });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
import prisma from '../../../lib/prisma';
|
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
|
||||||
import { getSession } from 'next-auth/react';
|
|
||||||
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;
|
|
||||||
|
|
||||||
console.log(req.method);
|
|
||||||
|
|
||||||
|
|
||||||
// est-ce la méthode est un POST ou PUT?
|
|
||||||
if (!(['POST', 'PUT'].indexOf(req.method) > -1)) {
|
|
||||||
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 },
|
|
||||||
})
|
|
||||||
|
|
||||||
// est-ce que utilisateur est un client classique ? Donc interdit pour lui de faire des updates
|
|
||||||
if (user.role === 'USER') {
|
|
||||||
res.status(401).json({ err: "Vous n'avez pas l'autorisation" });
|
|
||||||
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 }
|
|
||||||
})
|
|
||||||
|
|
||||||
return res.status(200).send({ message: `Le gain a été mis à jour !`, res: updatedCurrentUser });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -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> */}
|
||||||
@ -1,77 +0,0 @@
|
|||||||
import { PlaywrightTestConfig, devices } from '@playwright/test'
|
|
||||||
import path from 'path'
|
|
||||||
|
|
||||||
// Use process.env.PORT by default and fallback to port 3000
|
|
||||||
const PORT = process.env.PORT || 3000
|
|
||||||
|
|
||||||
// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port
|
|
||||||
const baseURL = `http://localhost:${PORT}`
|
|
||||||
|
|
||||||
// Reference: https://playwright.dev/docs/test-configuration
|
|
||||||
const config: PlaywrightTestConfig = {
|
|
||||||
// Timeout per test
|
|
||||||
timeout: 30 * 1000,
|
|
||||||
// Test directory
|
|
||||||
testDir: path.join(__dirname, 'e2e'),
|
|
||||||
// If a test fails, retry it additional 2 times
|
|
||||||
retries: 2,
|
|
||||||
// Artifacts folder where screenshots, videos, and traces are stored.
|
|
||||||
outputDir: 'test-results/',
|
|
||||||
|
|
||||||
// Run your local dev server before starting the tests:
|
|
||||||
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests
|
|
||||||
webServer: {
|
|
||||||
command: 'npm run dev',
|
|
||||||
url: baseURL,
|
|
||||||
timeout: 120 * 1000,
|
|
||||||
reuseExistingServer: !process.env.CI,
|
|
||||||
},
|
|
||||||
|
|
||||||
use: {
|
|
||||||
// Use baseURL so to make navigations relative.
|
|
||||||
// More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url
|
|
||||||
baseURL,
|
|
||||||
|
|
||||||
// Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc.
|
|
||||||
// More information: https://playwright.dev/docs/trace-viewer
|
|
||||||
trace: 'retry-with-trace',
|
|
||||||
|
|
||||||
// All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context
|
|
||||||
// contextOptions: {
|
|
||||||
// ignoreHTTPSErrors: true,
|
|
||||||
// },
|
|
||||||
},
|
|
||||||
|
|
||||||
projects: [
|
|
||||||
{
|
|
||||||
name: 'Desktop Chrome',
|
|
||||||
use: {
|
|
||||||
...devices['Desktop Chrome'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// {
|
|
||||||
// name: 'Desktop Firefox',
|
|
||||||
// use: {
|
|
||||||
// ...devices['Desktop Firefox'],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: 'Desktop Safari',
|
|
||||||
// use: {
|
|
||||||
// ...devices['Desktop Safari'],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// Test against mobile viewports.
|
|
||||||
// {
|
|
||||||
// name: 'Mobile Chrome',
|
|
||||||
// use: {
|
|
||||||
// ...devices['Pixel 5'],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: 'Mobile Safari',
|
|
||||||
// use: devices['iPhone 12'],
|
|
||||||
// },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
export default config
|
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
// 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,
|
||||||
|
codeActif: true,
|
||||||
|
retrait: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//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}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@ -1,11 +0,0 @@
|
|||||||
# *
|
|
||||||
User-agent: *
|
|
||||||
Allow: /*
|
|
||||||
Disallow: /admin
|
|
||||||
Disallow: /mon-compte
|
|
||||||
|
|
||||||
# Host
|
|
||||||
Host: https://dsp-archiwebo21-ad-ec-cb-mt.fr
|
|
||||||
|
|
||||||
# Sitemaps
|
|
||||||
Sitemap: https://dsp-archiwebo21-ad-ec-cb-mt.fr/sitemap.xml
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/admin</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/auth-error</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/cgu</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/connexion</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/contact</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/mentions-legales</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/mon-compte</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/tout-savoir</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
<url><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/verify-request</loc><lastmod>2022-12-15T20:38:21.840Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
|
||||||
</urlset>
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<sitemap><loc>https://dsp-archiwebo21-ad-ec-cb-mt.fr/sitemap-0.xml</loc></sitemap>
|
|
||||||
</sitemapindex>
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
set -x
|
|
||||||
npm run build
|
|
||||||
set +x
|
|
||||||
|
|
||||||
|
|
||||||
set -x
|
|
||||||
npm start &
|
|
||||||
sleep 1
|
|
||||||
echo $! > .pidfile
|
|
||||||
set +x
|
|
||||||
|
|
||||||
echo 'Maintenant...'
|
|
||||||
echo 'Visiter https://devops.dsp-archiwebo21-ad-ec-cb-mt.fr/ '
|
|
||||||
echo 'L_application tourne sur le docker jenkins sur via le port 3000 voici un ip a'
|
|
||||||
ip a
|
|
||||||
echo 'Pour fermer l_application a appuyer sur le bouton proced'
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
echo 'The following command terminates the "npm start" process using its PID'
|
|
||||||
echo '(written to ".pidfile"), all of which were conducted when "deliver.sh"'
|
|
||||||
echo 'was executed.'
|
|
||||||
set -x
|
|
||||||
kill $(cat .pidfile)
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
echo 'The following "npm" command (if executed) installs the "cross-env"'
|
|
||||||
echo 'dependency into the local "node_modules" directory, which will ultimately'
|
|
||||||
echo 'be stored in the Jenkins home directory. As described in'
|
|
||||||
echo 'https://docs.npmjs.com/cli/install, the "--save-dev" flag causes the'
|
|
||||||
echo '"cross-env" dependency to be installed as "devDependencies". For the'
|
|
||||||
echo 'purposes of this tutorial, this flag is not important. However, when'
|
|
||||||
echo 'installing this dependency, it would typically be done so using this'
|
|
||||||
echo 'flag. For a comprehensive explanation about "devDependencies", see'
|
|
||||||
echo 'https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies.'
|
|
||||||
set -x
|
|
||||||
# npm install --save-dev cross-env
|
|
||||||
set +x
|
|
||||||
|
|
||||||
echo 'The following "npm" command tests that your simple Node.js/React'
|
|
||||||
echo 'application renders satisfactorily. This command actually invokes the test'
|
|
||||||
echo 'runner Jest (https://facebook.github.io/jest/).'
|
|
||||||
set -x
|
|
||||||
npm test
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
.footer-separator{
|
|
||||||
height:100px;
|
|
||||||
}
|
|
||||||
@media (min-width: 992px) {
|
|
||||||
.footer-separator{
|
|
||||||
height:50vh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
.bloc-content {
|
|
||||||
padding: 2vh;
|
|
||||||
border-radius: 10px;
|
|
||||||
background-position: 50% 50%;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-size: contain;
|
|
||||||
background-color: rgba(255, 255, 255, 0.329);
|
|
||||||
/* animation: zoomInOut 3s ease-in-out infinite; */
|
|
||||||
z-index: 8888
|
|
||||||
}
|
|
||||||
@media (min-width: 992px) {
|
|
||||||
.bloc-content {
|
|
||||||
padding: 10vh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.masthead {
|
|
||||||
padding-top: 5vh;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"jsx": "react"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue