mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-07-09 06:58:06 +00:00
refactor(Dashboard api): changed api to fetch potential match
api now asks only the userID and fetches everything itself
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
|||||||
EditablePreview,
|
EditablePreview,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormErrorMessage,
|
FormErrorMessage,
|
||||||
|
FormHelperText,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { Controller, ControllerProps } from "react-hook-form";
|
import { Controller, ControllerProps } from "react-hook-form";
|
||||||
@@ -11,6 +12,7 @@ import { Controller, ControllerProps } from "react-hook-form";
|
|||||||
type CustomEditableProps = {
|
type CustomEditableProps = {
|
||||||
label: string;
|
label: string;
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
|
helperText?: string;
|
||||||
} & Omit<ControllerProps, "render">;
|
} & Omit<ControllerProps, "render">;
|
||||||
|
|
||||||
export default function CustomEditable(props: CustomEditableProps) {
|
export default function CustomEditable(props: CustomEditableProps) {
|
||||||
@@ -18,6 +20,7 @@ export default function CustomEditable(props: CustomEditableProps) {
|
|||||||
defaultValue,
|
defaultValue,
|
||||||
label,
|
label,
|
||||||
name,
|
name,
|
||||||
|
helperText = "",
|
||||||
isDisabled = false,
|
isDisabled = false,
|
||||||
...controllerProps
|
...controllerProps
|
||||||
} = props;
|
} = props;
|
||||||
@@ -44,6 +47,7 @@ export default function CustomEditable(props: CustomEditableProps) {
|
|||||||
<EditablePreview />
|
<EditablePreview />
|
||||||
<EditableInput />
|
<EditableInput />
|
||||||
</Editable>
|
</Editable>
|
||||||
|
<FormHelperText>{helperText}</FormHelperText>
|
||||||
<FormErrorMessage as="b">{error?.message}</FormErrorMessage>
|
<FormErrorMessage as="b">{error?.message}</FormErrorMessage>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,39 +6,43 @@ const birthDateFromAge = (age) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const get = async (req, res) => {
|
const get = async (req, res) => {
|
||||||
const {
|
const { userID } = req.query;
|
||||||
preferences: preferencesList,
|
|
||||||
excludedId,
|
|
||||||
userLikes,
|
|
||||||
userDislikes,
|
|
||||||
} = req.query;
|
|
||||||
|
|
||||||
const preferences = preferencesList.split(",");
|
|
||||||
|
|
||||||
const prefGender = preferences[0];
|
|
||||||
const dateAgeMin = birthDateFromAge(preferences[1]);
|
|
||||||
const dateAgeMax = birthDateFromAge(preferences[2]);
|
|
||||||
|
|
||||||
// pas utilisé pour le moment
|
|
||||||
const distance = preferences[3];
|
|
||||||
|
|
||||||
let userLikesList = userLikes.split(",");
|
|
||||||
let userDislikesList = userDislikes.split(",");
|
|
||||||
if (userLikesList[0] === "") {
|
|
||||||
userLikesList = [];
|
|
||||||
}
|
|
||||||
if (userDislikesList[0] === "") {
|
|
||||||
userDislikesList = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const excludedIdArray = [excludedId, ...userLikesList, ...userDislikesList];
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
const userInfo = await prisma.user
|
||||||
|
.findUnique({
|
||||||
|
where: {
|
||||||
|
id: userID,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
UserLikesID: true,
|
||||||
|
UserDislikesID: true,
|
||||||
|
distance: true,
|
||||||
|
ageMax: true,
|
||||||
|
ageMin: true,
|
||||||
|
prefGender: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
const dateAgeMin = birthDateFromAge(userInfo.ageMin);
|
||||||
|
const dateAgeMax = birthDateFromAge(userInfo.ageMax);
|
||||||
|
|
||||||
|
const excludedIdArray = [
|
||||||
|
userID,
|
||||||
|
...userInfo.UserDislikesID,
|
||||||
|
...userInfo.UserLikesID,
|
||||||
|
];
|
||||||
|
|
||||||
// a terme mettre l'age, la distance
|
// a terme mettre l'age, la distance
|
||||||
const users = await prisma.user
|
const users = await prisma.user
|
||||||
.findMany({
|
.findMany({
|
||||||
where: {
|
where: {
|
||||||
AND: [
|
AND: [
|
||||||
{ gender: { equals: prefGender } },
|
{ gender: { equals: userInfo.prefGender } },
|
||||||
{
|
{
|
||||||
birthdate: {
|
birthdate: {
|
||||||
lte: dateAgeMin.toISOString(),
|
lte: dateAgeMin.toISOString(),
|
||||||
@@ -51,7 +55,7 @@ const get = async (req, res) => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
return [];
|
return null;
|
||||||
});
|
});
|
||||||
if (users.length === 0 || users === undefined || users === null) {
|
if (users.length === 0 || users === undefined || users === null) {
|
||||||
return res.status(500).send({ error: "Aucun profil trouvé" });
|
return res.status(500).send({ error: "Aucun profil trouvé" });
|
||||||
|
|||||||
+1
-10
@@ -58,16 +58,7 @@ export default function Dashboard() {
|
|||||||
queryKey: ["ListUsers"],
|
queryKey: ["ListUsers"],
|
||||||
enabled: status === "authenticated" && !isLoading,
|
enabled: status === "authenticated" && !isLoading,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
return fetch(
|
return fetch(`/api/user/userDashboard?userID=${loggedUser.id}`) //exclure les profils déjà like ou dislike
|
||||||
`/api/user/userDashboard?preferences=${[
|
|
||||||
loggedUser.prefGender,
|
|
||||||
loggedUser.ageMin,
|
|
||||||
loggedUser.ageMax,
|
|
||||||
loggedUser.distance,
|
|
||||||
]}&excludedId=${loggedUser.id}&userLikes=${
|
|
||||||
loggedUser.UserLikesID
|
|
||||||
}&userDislikes=${loggedUser.UserDislikesID}`
|
|
||||||
) //exclure les profils déjà like ou dislike
|
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
Container,
|
Container,
|
||||||
Divider,
|
Divider,
|
||||||
Flex,
|
Flex,
|
||||||
|
FormHelperText,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
Text,
|
Text,
|
||||||
useToast,
|
useToast,
|
||||||
@@ -232,6 +233,9 @@ export default function UserProfile() {
|
|||||||
}
|
}
|
||||||
control={control}
|
control={control}
|
||||||
label={"Ville :"}
|
label={"Ville :"}
|
||||||
|
helperText={
|
||||||
|
"Ce champ est modifié automatiquement depuis la carte"
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box>
|
<Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user