mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Fix beer likes and db client
This commit is contained in:
@@ -9,10 +9,6 @@ const useUser = () => {
|
|||||||
error,
|
error,
|
||||||
isLoading,
|
isLoading,
|
||||||
} = useSWR('/api/users/current', async (url) => {
|
} = useSWR('/api/users/current', async (url) => {
|
||||||
if (!document.cookie) {
|
|
||||||
throw new Error('Not logged in.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
16
pages/account/index.tsx
Normal file
16
pages/account/index.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import Layout from '@/components/ui/Layout';
|
||||||
|
import { NextPage } from 'next';
|
||||||
|
|
||||||
|
interface AccountPageProps {}
|
||||||
|
|
||||||
|
const AccountPage: NextPage<AccountPageProps> = () => {
|
||||||
|
return (
|
||||||
|
<Layout>
|
||||||
|
<div>
|
||||||
|
<h1>Account Page</h1>
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AccountPage;
|
||||||
@@ -24,7 +24,7 @@ const sendLikeRequest = async (
|
|||||||
throw new ServerError('Could not find a beer post with that id', 404);
|
throw new ServerError('Could not find a beer post with that id', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
const alreadyLiked = await findBeerPostLikeById(id);
|
const alreadyLiked = await findBeerPostLikeById(beer.id, user.id);
|
||||||
|
|
||||||
const jsonResponse = {
|
const jsonResponse = {
|
||||||
success: true as const,
|
success: true as const,
|
||||||
@@ -50,11 +50,7 @@ const router = createRouter<
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
getCurrentUser,
|
getCurrentUser,
|
||||||
validateRequest({
|
validateRequest({ querySchema: z.object({ id: z.string().uuid() }) }),
|
||||||
querySchema: z.object({
|
|
||||||
id: z.string().uuid(),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
sendLikeRequest,
|
sendLikeRequest,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const LogoutPage: NextPage = () => {
|
|||||||
router.reload();
|
router.reload();
|
||||||
router.push('/');
|
router.push('/');
|
||||||
}, [router]);
|
}, [router]);
|
||||||
return <div />;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LogoutPage;
|
export default LogoutPage;
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
|
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||||
|
|
||||||
const DBClient = {
|
const DBClient = {
|
||||||
instance: new PrismaClient(),
|
instance:
|
||||||
|
globalForPrisma.prisma ||
|
||||||
|
new PrismaClient({
|
||||||
|
log: ['info', 'warn'],
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IDBClient = typeof DBClient;
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
globalForPrisma.prisma = DBClient.instance;
|
||||||
Object.freeze(DBClient);
|
}
|
||||||
|
|
||||||
export default DBClient;
|
export default DBClient;
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import DBClient from '@/prisma/DBClient';
|
import DBClient from '@/prisma/DBClient';
|
||||||
|
|
||||||
const findBeerPostLikeById = async (id: string) =>
|
const findBeerPostLikeById = async (beerPostId: string, userId: string) =>
|
||||||
DBClient.instance.beerPostLike.findUnique({ where: { id } });
|
DBClient.instance.beerPostLike.findFirst({
|
||||||
|
where: {
|
||||||
|
beerPostId,
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export default findBeerPostLikeById;
|
export default findBeerPostLikeById;
|
||||||
|
|||||||
Reference in New Issue
Block a user