2023-03-08 15:31:24 -06:00
|
|
|
import { prisma } from "@/lib/api/db";
|
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default async function getUser(
|
2023-05-22 23:08:16 -05:00
|
|
|
lookupEmail: string,
|
|
|
|
isSelf: boolean,
|
|
|
|
userEmail: string
|
|
|
|
) {
|
2023-04-26 15:40:48 -05:00
|
|
|
const user = await prisma.user.findUnique({
|
2023-03-08 15:31:24 -06:00
|
|
|
where: {
|
2023-07-03 15:43:53 -05:00
|
|
|
email: lookupEmail.toLowerCase(),
|
2023-03-08 15:31:24 -06:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-05-22 23:08:16 -05:00
|
|
|
if (!user) return { response: "User not found.", status: 404 };
|
|
|
|
|
|
|
|
if (
|
|
|
|
!isSelf &&
|
|
|
|
user?.isPrivate &&
|
2023-07-03 15:43:53 -05:00
|
|
|
!user.whitelistedUsers.includes(userEmail.toLowerCase())
|
2023-05-22 23:08:16 -05:00
|
|
|
) {
|
|
|
|
return { response: "This profile is private.", status: 401 };
|
|
|
|
}
|
2023-05-20 14:25:00 -05:00
|
|
|
|
|
|
|
const { password, ...unsensitiveInfo } = user;
|
|
|
|
|
2023-05-18 13:02:17 -05:00
|
|
|
const data = isSelf
|
2023-05-20 14:25:00 -05:00
|
|
|
? // If user is requesting its own data
|
|
|
|
unsensitiveInfo
|
2023-05-18 13:02:17 -05:00
|
|
|
: {
|
|
|
|
// If user is requesting someone elses data
|
2023-05-20 14:25:00 -05:00
|
|
|
id: unsensitiveInfo.id,
|
|
|
|
name: unsensitiveInfo.name,
|
|
|
|
email: unsensitiveInfo.email,
|
2023-05-18 13:02:17 -05:00
|
|
|
};
|
2023-04-26 15:40:48 -05:00
|
|
|
|
2023-05-20 14:25:00 -05:00
|
|
|
return { response: data || null, status: 200 };
|
2023-04-26 15:40:48 -05:00
|
|
|
}
|