mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-05-13 17:21:53 +00:00
Add Notification and Match to DB
Took 42 minutes
This commit is contained in:
+38
-12
@@ -10,18 +10,20 @@ datasource db {
|
|||||||
|
|
||||||
// Models
|
// Models
|
||||||
model User {
|
model User {
|
||||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||||
email String @unique
|
email String @unique
|
||||||
password String
|
password String
|
||||||
firstName String?
|
firstName String?
|
||||||
lastName String?
|
lastName String?
|
||||||
bio String?
|
bio String?
|
||||||
location String?
|
location String?
|
||||||
images String[]
|
images String[]
|
||||||
birthdate DateTime?
|
birthdate DateTime?
|
||||||
gender Gender @default(UNKNOWN)
|
gender Gender @default(UNKNOWN)
|
||||||
role Role @default(USER)
|
role Role @default(USER)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @default(now())
|
||||||
|
lastConnexion DateTime @default(now())
|
||||||
|
|
||||||
// Liste des chats de l'utilisateur
|
// Liste des chats de l'utilisateur
|
||||||
ChatID String[] @db.ObjectId
|
ChatID String[] @db.ObjectId
|
||||||
@@ -41,6 +43,24 @@ model User {
|
|||||||
// Les personnes qui aiment l'utilisateur
|
// Les personnes qui aiment l'utilisateur
|
||||||
OtherUserLikesID String[] @db.ObjectId
|
OtherUserLikesID String[] @db.ObjectId
|
||||||
OtherUserLikes User[] @relation("Likes", fields: [OtherUserLikesID], references: [id])
|
OtherUserLikes User[] @relation("Likes", fields: [OtherUserLikesID], references: [id])
|
||||||
|
|
||||||
|
MatchId String[] @db.ObjectId
|
||||||
|
Match Match[] @relation(fields: [MatchId], references: [id])
|
||||||
|
|
||||||
|
Notification Notification[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model Notification {
|
||||||
|
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||||
|
type NotificationType
|
||||||
|
UserId String @db.ObjectId
|
||||||
|
User User @relation(fields: [UserId], references: [id])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Match {
|
||||||
|
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||||
|
UserId String[] @db.ObjectId
|
||||||
|
User User[] @relation(fields: [UserId], references: [id])
|
||||||
}
|
}
|
||||||
|
|
||||||
model Passion {
|
model Passion {
|
||||||
@@ -82,6 +102,12 @@ enum Gender {
|
|||||||
UNKNOWN
|
UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum NotificationType {
|
||||||
|
NEW_MATCH
|
||||||
|
NEW_LIKE
|
||||||
|
NEW_MESSAGE
|
||||||
|
}
|
||||||
|
|
||||||
enum Role {
|
enum Role {
|
||||||
USER
|
USER
|
||||||
ADMIN
|
ADMIN
|
||||||
|
|||||||
@@ -3,13 +3,6 @@ import prismaClient from '@/lib/prismaClient';
|
|||||||
import {NextApiRequest, NextApiResponse} from 'next';
|
import {NextApiRequest, NextApiResponse} from 'next';
|
||||||
import {hashPassword} from '@/lib/PasswordTools';
|
import {hashPassword} from '@/lib/PasswordTools';
|
||||||
|
|
||||||
type CreateUserQuery = {
|
|
||||||
email: string
|
|
||||||
password: string
|
|
||||||
firstName: string
|
|
||||||
lastName: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse
|
res: NextApiResponse
|
||||||
@@ -19,16 +12,14 @@ export default async function handler(
|
|||||||
adapter: new PrismaAdapter({prismaClient: prismaClient}),
|
adapter: new PrismaAdapter({prismaClient: prismaClient}),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hash le mot de passe quand on crée un utilisateur
|
await onUserCreate(req);
|
||||||
if (req.url === "/api/users" && req.method === "POST") {
|
|
||||||
const {email, password, firstName, lastName} = req.body as CreateUserQuery;
|
|
||||||
|
|
||||||
if (!email || !password || !firstName || !lastName)
|
|
||||||
return res.status(400).send({message: req.body});
|
|
||||||
|
|
||||||
const hashedPassword: string = await hashPassword(password);
|
|
||||||
req.body = {...req.body, password: hashedPassword}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nextCrudHandler(req, res);
|
return nextCrudHandler(req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onUserCreate(req: NextApiRequest) {
|
||||||
|
if (req.url === "/api/users" && req.method === "POST") {
|
||||||
|
const password: string = await hashPassword(req.body.password);
|
||||||
|
req.body = {...req.body, password}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user