mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-05-13 17:21:53 +00:00
fix(Using connect): Using connect on Passion and userLikes / dislikes
This commit is contained in:
@@ -38,14 +38,23 @@ export default function CardUser(props) {
|
|||||||
const likeMutation = useMutation({
|
const likeMutation = useMutation({
|
||||||
mutationKey: "like",
|
mutationKey: "like",
|
||||||
mutationFn: async (id) => {
|
mutationFn: async (id) => {
|
||||||
|
let jsonLikes = { UserLikes: { connect: [] } };
|
||||||
|
|
||||||
|
let newUserLikesList = [...userLikes, id];
|
||||||
|
|
||||||
|
newUserLikesList.forEach((id) => {
|
||||||
|
jsonLikes.UserLikes.connect.push({ id: id });
|
||||||
|
});
|
||||||
|
|
||||||
return fetch(`/api/users/${loggedUser.id}`, {
|
return fetch(`/api/users/${loggedUser.id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ UserLikesID: [...userLikes, id] }),
|
body: JSON.stringify(jsonLikes),
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
setListUsers(listUsers.slice(1));
|
||||||
setUserLikes([...userLikes, user.id]);
|
setUserLikes([...userLikes, user.id]);
|
||||||
toast({
|
toast({
|
||||||
title: "J'aime",
|
title: "J'aime",
|
||||||
@@ -77,14 +86,23 @@ export default function CardUser(props) {
|
|||||||
const dislikeMutation = useMutation({
|
const dislikeMutation = useMutation({
|
||||||
mutationKey: "dislike",
|
mutationKey: "dislike",
|
||||||
mutationFn: async (id) => {
|
mutationFn: async (id) => {
|
||||||
|
let jsonDislikes = { UserDislikes: { connect: [] } };
|
||||||
|
|
||||||
|
let newUserDislikesList = [...userDislikes, id];
|
||||||
|
|
||||||
|
newUserDislikesList.forEach((id) => {
|
||||||
|
jsonDislikes.UserDislikes.connect.push({ id: id });
|
||||||
|
});
|
||||||
|
|
||||||
return fetch(`/api/users/${loggedUser.id}`, {
|
return fetch(`/api/users/${loggedUser.id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ UserDislikesID: [...userDislikes, id] }),
|
body: JSON.stringify(jsonDislikes),
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
setListUsers(listUsers.slice(1));
|
||||||
setUserDislikes([...userDislikes, user.id]);
|
setUserDislikes([...userDislikes, user.id]);
|
||||||
toast({
|
toast({
|
||||||
title: "J'aime pas",
|
title: "J'aime pas",
|
||||||
@@ -165,7 +183,6 @@ export default function CardUser(props) {
|
|||||||
colorScheme={"purple"}
|
colorScheme={"purple"}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
likeMutation.mutate(listUsers[0].id);
|
likeMutation.mutate(listUsers[0].id);
|
||||||
setListUsers(listUsers.slice(1));
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<BiHeart />
|
<BiHeart />
|
||||||
@@ -176,7 +193,6 @@ export default function CardUser(props) {
|
|||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dislikeMutation.mutate(listUsers[0].id);
|
dislikeMutation.mutate(listUsers[0].id);
|
||||||
setListUsers(listUsers.slice(1));
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<RxCross1 />
|
<RxCross1 />
|
||||||
|
|||||||
@@ -28,13 +28,19 @@ export default function ModalChoosePassion(props) {
|
|||||||
defaultValue: user.PassionID,
|
defaultValue: user.PassionID,
|
||||||
});
|
});
|
||||||
|
|
||||||
const savePassions = (PassionID) => {
|
const savePassions = (idPassionList) => {
|
||||||
|
let jsonPassions = { Passion: { connect: [] } };
|
||||||
|
|
||||||
|
idPassionList.forEach((id) => {
|
||||||
|
jsonPassions.Passion.connect.push({ id: id });
|
||||||
|
});
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ PassionID }),
|
body: JSON.stringify(jsonPassions),
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(`/api/users/${user.id}`, options)
|
fetch(`/api/users/${user.id}`, options)
|
||||||
|
|||||||
Reference in New Issue
Block a user