mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-07-09 15:08:06 +00:00
feat(Like / dislike API ): more efficient api + checks and returns if match
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
const { PrismaClient } = require("@prisma/client");
|
||||
|
||||
const post = async (req, res) => {
|
||||
const { idUser, idUserDisliked } = req.body;
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
try {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: idUser,
|
||||
},
|
||||
data: {
|
||||
UserDislikes: {
|
||||
connect: {
|
||||
id: idUserDisliked,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "disliked",
|
||||
userDisliked: idUserDisliked,
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: err,
|
||||
message: "Error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default (req, res) => {
|
||||
req.method === "POST"
|
||||
? post(req, res)
|
||||
: res.status(404).send({ message: "Wrong method, please use POST" });
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
const { PrismaClient } = require("@prisma/client");
|
||||
import { NotificationType } from "@prisma/client";
|
||||
|
||||
const post = async (req, res) => {
|
||||
const { idUser, idUserLiked } = req.body;
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
try {
|
||||
const likedByList = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: idUser,
|
||||
},
|
||||
select: {
|
||||
OtherUserLikesID: true,
|
||||
},
|
||||
});
|
||||
|
||||
const match = likedByList.OtherUserLikesID.includes(idUserLiked);
|
||||
|
||||
//faire une notification mais faut qu'on regarde un meilleur moyen dans la BD
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: idUser,
|
||||
},
|
||||
data: {
|
||||
UserLikes: {
|
||||
connect: {
|
||||
id: idUserLiked,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Liked",
|
||||
match: match,
|
||||
userLiked: idUserLiked,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: err,
|
||||
message: "Error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default (req, res) => {
|
||||
req.method === "POST"
|
||||
? post(req, res)
|
||||
: res.status(404).send({ message: "Wrong method, please use POST" });
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Center,
|
||||
Container,
|
||||
Divider,
|
||||
Editable,
|
||||
Flex,
|
||||
FormHelperText,
|
||||
FormLabel,
|
||||
@@ -22,6 +23,7 @@ import ModalChoosePassion from "@/components/layout/user_profile/ModalChoosePass
|
||||
import ProfileTagList from "@/components/layout/user_profile/ProfileTagList";
|
||||
import LoadingPage from "@/components/LoadingPage";
|
||||
import CustomEditable from "@/components/layout/user_profile/CustomEditable";
|
||||
import CustomFalseEditable from "@/components/layout/user_profile/CustomFalseEditable";
|
||||
import CustomEditableArea from "@/components/layout/user_profile/CustomEditableArea";
|
||||
import CustomRadioGender from "@/components/layout/user_profile/CustomRadioGender";
|
||||
import CustomRangeSlider from "@/components/layout/user_profile/CustomRangeSlider";
|
||||
@@ -206,16 +208,14 @@ export default function UserProfile() {
|
||||
/>
|
||||
</Box>
|
||||
<Box>
|
||||
<CustomEditable
|
||||
name="birthdate"
|
||||
isDisabled={true}
|
||||
<CustomFalseEditable
|
||||
id="birthdate"
|
||||
defaultValue={
|
||||
userData.birthdate === undefined ||
|
||||
userData.birthdate === null
|
||||
? "Non renseigné"
|
||||
: formateDate(userData.birthdate.toString())
|
||||
}
|
||||
control={control}
|
||||
label={"Date de naissance :"}
|
||||
/>
|
||||
</Box>
|
||||
@@ -223,15 +223,14 @@ export default function UserProfile() {
|
||||
<Divider colorScheme={"purple"} />
|
||||
<Flex justify={"space-between"} my={"1rem"}>
|
||||
<Box>
|
||||
<CustomEditable
|
||||
name="location"
|
||||
<CustomFalseEditable
|
||||
id="location"
|
||||
isDisabled={true}
|
||||
defaultValue={
|
||||
userData.location === null || userData.location === ""
|
||||
? "Rendez vous sur la carte"
|
||||
: userData.location
|
||||
}
|
||||
control={control}
|
||||
label={"Ville :"}
|
||||
helperText={
|
||||
"Ce champ est modifié automatiquement depuis la carte"
|
||||
@@ -239,11 +238,10 @@ export default function UserProfile() {
|
||||
/>
|
||||
</Box>
|
||||
<Box>
|
||||
<CustomEditable
|
||||
name="email"
|
||||
<CustomFalseEditable
|
||||
id="email"
|
||||
isDisabled={true}
|
||||
defaultValue={userData.email}
|
||||
control={control}
|
||||
label={"Adresse mail :"}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user