-
Notifications
You must be signed in to change notification settings - Fork 11
Express 임경민 미션 10 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
play-ancora-gyungmin
wants to merge
16
commits into
codeit-sprint-fullstack:express-임경민
Choose a base branch
from
play-ancora-gyungmin:express-임경민
base: express-임경민
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "express-\uC784\uACBD\uBBFC"
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7e7a6ec
fix: comment repository fix
play-ancora-gyungmin 33354a1
fix: update default pageSize to MAX_SAFE_INTEGER for pagination handling
play-ancora-gyungmin 9eca1b3
fix: refactor response structure to spread data
play-ancora-gyungmin 1d98b65
feat: add users and likes shema
play-ancora-gyungmin bb46781
feat: migrate about previous update
play-ancora-gyungmin ee8d04c
rename: unified file names in plural
play-ancora-gyungmin 7eb5c05
feat: cursor pagenaiton for comments api
play-ancora-gyungmin 8389960
feat: user auth apis
play-ancora-gyungmin 1db5e3c
feat: auth for article api
play-ancora-gyungmin 0905a6e
feat: auth for product api
play-ancora-gyungmin e36f28c
feat: suth for comments apis
play-ancora-gyungmin 3bce90a
feat: add image fild for product table
play-ancora-gyungmin 96b36bd
remove: delete unuse seeding code
play-ancora-gyungmin d0c94a7
chore: add multer dependencie
play-ancora-gyungmin 2248a8b
feat: create uploads api endpoint
play-ancora-gyungmin 9a6ca66
feat: add images for product post endpoint and validation
play-ancora-gyungmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ env/* | |
| build | ||
|
|
||
| # misc | ||
| .vscode | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - You are about to alter the column `price` on the `Product` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Integer`. | ||
| - Added the required column `authorId` to the `Article` table without a default value. This is not possible if the table is not empty. | ||
| - Added the required column `authorId` to the `Comment` table without a default value. This is not possible if the table is not empty. | ||
| - Added the required column `authorId` to the `Product` table without a default value. This is not possible if the table is not empty. | ||
|
|
||
| */ | ||
| -- AlterTable | ||
| ALTER TABLE "public"."Article" ADD COLUMN "authorId" TEXT NOT NULL; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."Comment" ADD COLUMN "authorId" TEXT NOT NULL; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."Product" ADD COLUMN "authorId" TEXT NOT NULL, | ||
| ALTER COLUMN "price" SET DATA TYPE INTEGER; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "public"."User" ( | ||
| "id" TEXT NOT NULL, | ||
| "email" TEXT NOT NULL, | ||
| "nickname" TEXT, | ||
| "password" TEXT NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
|
||
| CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "public"."LikeArticle" ( | ||
| "id" SERIAL NOT NULL, | ||
| "userId" TEXT NOT NULL, | ||
| "articleId" TEXT NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "LikeArticle_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "public"."LikeProduct" ( | ||
| "id" SERIAL NOT NULL, | ||
| "userId" TEXT NOT NULL, | ||
| "productId" TEXT NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "LikeProduct_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "User_email_key" ON "public"."User"("email"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "LikeArticle_userId_articleId_key" ON "public"."LikeArticle"("userId", "articleId"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "LikeProduct_userId_productId_key" ON "public"."LikeProduct"("userId", "productId"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "public"."Article" ADD CONSTRAINT "Article_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "public"."LikeArticle" ADD CONSTRAINT "LikeArticle_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "public"."LikeArticle" ADD CONSTRAINT "LikeArticle_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "public"."Article"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "public"."Product" ADD CONSTRAINT "Product_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "public"."LikeProduct" ADD CONSTRAINT "LikeProduct_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "public"."LikeProduct" ADD CONSTRAINT "LikeProduct_productId_fkey" FOREIGN KEY ("productId") REFERENCES "public"."Product"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "public"."Comment" ADD CONSTRAINT "Comment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20251124044324_add_refresh_token_for_user/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "public"."User" ADD COLUMN "refreshToken" TEXT; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20251125002246_add_product_image/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "public"."Product" ADD COLUMN "image" TEXT[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import jwt from 'jsonwebtoken'; | ||
| import usersRepository from '../repository/users.repository.js'; | ||
| import { UnauthorizedException } from '../err/unauthorizedException.js'; | ||
| import { config } from '../config/config.js'; | ||
|
|
||
| const verifyToken = (token) => { | ||
| try { | ||
| return jwt.verify(token, config.JWT_SECRET); | ||
| } catch (err) { | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| export const authMiddleware = async (req, res, next) => { | ||
| try { | ||
| const { authorization } = req.cookies; | ||
| if (!authorization) { | ||
| throw new UnauthorizedException('인증 정보가 없습니다.'); | ||
| } | ||
| const [tokenType, token] = authorization.split(' '); | ||
| if (tokenType !== 'Bearer' || !token) { | ||
| throw new UnauthorizedException('지원하지 않는 인증 방식입니다.'); | ||
| } | ||
|
|
||
| let decoded = verifyToken(token); | ||
|
|
||
| // Access Token이 만료된 경우 | ||
| if (!decoded) { | ||
| const { refreshToken: refreshTokenWithBearer } = req.cookies; | ||
| if (!refreshTokenWithBearer) { | ||
| throw new UnauthorizedException('인증 정보가 만료되었습니다.'); | ||
| } | ||
|
|
||
| const [refreshTokenType, refreshToken] = | ||
| refreshTokenWithBearer.split(' '); | ||
| if (refreshTokenType !== 'Bearer' || !refreshToken) { | ||
| throw new UnauthorizedException('지원하지 않는 인증 방식입니다.'); | ||
| } | ||
|
|
||
| const decodedRefreshToken = verifyToken(refreshToken); | ||
| if (!decodedRefreshToken) { | ||
| throw new UnauthorizedException('인증 정보가 만료되었습니다.'); | ||
| } | ||
|
|
||
| const user = await usersRepository.findUserById( | ||
| decodedRefreshToken.userId, | ||
| ); | ||
| if (!user || user.refreshToken !== refreshToken) { | ||
| throw new UnauthorizedException('인증 정보가 유효하지 않습니다.'); | ||
| } | ||
|
|
||
| // 새로운 Access Token 발급 | ||
| const newAccessToken = jwt.sign({ userId: user.id }, config.JWT_SECRET, { | ||
| expiresIn: '6h', | ||
| }); | ||
|
|
||
| res.cookie('authorization', `Bearer ${newAccessToken}`); | ||
| decoded = verifyToken(newAccessToken); | ||
| } | ||
|
|
||
| const user = await usersRepository.findUserById(decoded.userId); | ||
| if (!user) { | ||
| throw new UnauthorizedException( | ||
| '인증 정보와 일치하는 사용자가 없습니다.', | ||
| ); | ||
| } | ||
| req.user = user; | ||
| next(); | ||
| } catch (err) { | ||
| next(err); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export const parsePagination = (req, res, next) => { | ||
| const pageSize = parseInt(req.query.pageSize, 10) || 10; | ||
| const cursor = req.query.cursor; | ||
|
|
||
| req.pagination = { | ||
| take: pageSize, | ||
| cursor, | ||
| }; | ||
| next(); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍