mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Rename "user" column in beerPostLikes, add ERD gen
This commit is contained in:
@@ -10,7 +10,7 @@ const useUser = () => {
|
||||
isLoading,
|
||||
} = useSWR('/api/users/current', async (url) => {
|
||||
if (!document.cookie.includes('token')) {
|
||||
return null;
|
||||
return undefined;
|
||||
}
|
||||
const response = await fetch(url);
|
||||
|
||||
|
||||
2856
package-lock.json
generated
2856
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^7.6.0",
|
||||
"@mermaid-js/mermaid-cli": "^9.3.0",
|
||||
"@types/cookie": "^0.5.1",
|
||||
"@types/multer": "^1.4.7",
|
||||
"@types/node": "^18.13.0",
|
||||
@@ -59,6 +60,7 @@
|
||||
"prettier-plugin-jsdoc": "^0.4.2",
|
||||
"prettier-plugin-tailwindcss": "^0.2.2",
|
||||
"prisma": "^4.9.0",
|
||||
"prisma-erd-generator": "^1.2.5",
|
||||
"tailwindcss": "^3.2.4",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.9.5"
|
||||
|
||||
@@ -18,7 +18,7 @@ const checkIfLiked = async (
|
||||
const alreadyLiked = await DBClient.instance.beerPostLike.findFirst({
|
||||
where: {
|
||||
beerPostId: id,
|
||||
userId: user.id,
|
||||
likedById: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ const RegisterUserPage: NextPage<RegisterUserProps> = () => {
|
||||
const onSubmit = async (data: z.infer<typeof CreateUserValidationSchema>) => {
|
||||
try {
|
||||
await sendRegisterUserRequest(data);
|
||||
reset();
|
||||
router.push('/', undefined, { shallow: true });
|
||||
} catch (error) {
|
||||
setServerResponseError(
|
||||
|
||||
1
prisma/ERD.svg
Normal file
1
prisma/ERD.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 104 KiB |
16
prisma/migrations/20230213214022_/migration.sql
Normal file
16
prisma/migrations/20230213214022_/migration.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `userId` on the `BeerPostLike` table. All the data in the column will be lost.
|
||||
- Added the required column `likedById` to the `BeerPostLike` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "BeerPostLike" DROP CONSTRAINT "BeerPostLike_userId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "BeerPostLike" DROP COLUMN "userId",
|
||||
ADD COLUMN "likedById" TEXT NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerPostLike" ADD CONSTRAINT "BeerPostLike_likedById_fkey" FOREIGN KEY ("likedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -5,6 +5,13 @@ generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
generator erdSVG {
|
||||
provider = "prisma-erd-generator"
|
||||
output = "./ERD.svg"
|
||||
includeRelationFromFields = true
|
||||
theme = "neutral"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
@@ -53,8 +60,8 @@ model BeerPostLike {
|
||||
id String @id @default(uuid())
|
||||
beerPost BeerPost @relation(fields: [beerPostId], references: [id], onDelete: Cascade)
|
||||
beerPostId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId String
|
||||
likedBy User @relation(fields: [likedById], references: [id], onDelete: Cascade)
|
||||
likedById String
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const createNewBeerPostLikes = async ({
|
||||
DBClient.instance.beerPostLike.create({
|
||||
data: {
|
||||
beerPost: { connect: { id: beerPost.id } },
|
||||
user: { connect: { id: user.id } },
|
||||
likedBy: { connect: { id: user.id } },
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ const createBeerPostLike = async ({
|
||||
return DBClient.instance.beerPostLike.create({
|
||||
data: {
|
||||
beerPost: { connect: { id } },
|
||||
user: { connect: { id: user.id } },
|
||||
likedBy: { connect: { id: user.id } },
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
|
||||
const findBeerPostLikeById = async (beerPostId: string, userId: string) =>
|
||||
DBClient.instance.beerPostLike.findFirst({
|
||||
where: {
|
||||
beerPostId,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
const findBeerPostLikeById = async (beerPostId: string, likedById: string) =>
|
||||
DBClient.instance.beerPostLike.findFirst({ where: { beerPostId, likedById } });
|
||||
|
||||
export default findBeerPostLikeById;
|
||||
|
||||
Reference in New Issue
Block a user