✅ add - ajout page mon compte
This commit is contained in:
1 parent
a73958e500
commit
6a10740307
4 files changed
+78
-32
No files matched your search
@@ -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 admin (pour les developpeurs)
|
||||||
|
//--> http://localhost:3000/api/superadmin/admin?pass=1234 (a effacer)
|
||||||
|
|
||||||
|
export default async function makeMeAdmin(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,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/super/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' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -72,12 +72,12 @@ model Gain {
|
|||||||
produitId Int?
|
produitId Int?
|
||||||
user User? @relation(fields: [userId], references: [id])
|
user User? @relation(fields: [userId], references: [id])
|
||||||
userId Int?
|
userId Int?
|
||||||
actif Boolean @default(true)
|
codeActif Boolean @default(true)
|
||||||
|
retrait Boolean @default(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
model Produit {
|
model Produit {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
actif Boolean?
|
|
||||||
nomProduit String?
|
nomProduit String?
|
||||||
prixTtc Int?
|
prixTtc Int?
|
||||||
image String?
|
image String?
|
||||||
@@ -86,6 +86,7 @@ model Produit {
|
|||||||
|
|
||||||
enum Role {
|
enum Role {
|
||||||
USER
|
USER
|
||||||
|
SELLER
|
||||||
ADMIN
|
ADMIN
|
||||||
SUPERADMIN
|
SUPERADMIN
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-30
@@ -4,44 +4,17 @@ export const userData: Prisma.UserCreateInput[] = [
|
|||||||
{
|
{
|
||||||
name: 'Alice',
|
name: 'Alice',
|
||||||
email: 'alice@prisma.io',
|
email: 'alice@prisma.io',
|
||||||
posts: {
|
|
||||||
create: [
|
|
||||||
{
|
|
||||||
title: 'Join the Prisma Slack',
|
|
||||||
content: 'https://slack.prisma.io',
|
|
||||||
published: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Nilu',
|
name: 'Nilu',
|
||||||
email: 'nilu@prisma.io',
|
email: 'nilu@prisma.io',
|
||||||
posts: {
|
|
||||||
create: [
|
|
||||||
{
|
|
||||||
title: 'Follow Prisma on Twitter',
|
|
||||||
content: 'https://www.twitter.com/prisma',
|
|
||||||
published: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Mahmoud',
|
name: 'Mahmoud',
|
||||||
email: 'mahmoud@prisma.io',
|
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',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
Reference in new issue
Block a user