From eb40c3f82cb9464ad37b74697aeb30ec82345f90 Mon Sep 17 00:00:00 2001 From: scarf Date: Wed, 6 Sep 2023 18:07:28 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix(build):=20typescript=EB=A5=BC=20depende?= =?UTF-8?q?ncies=EB=A1=9C=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 도커파일에서 빌드시 devdependencies를 무시하나 tsc는 빌드에 필요 --- package.json | 2 +- pnpm-lock.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 407bc0ec..d47d4b24 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "dev": "pnpm -r --parallel dev" }, "dependencies": { + "typescript": "5.1.6", "zod": "^3.22.2", "@ts-rest/core": "^3.28.0" }, "devDependencies": { - "typescript": "5.1.6", "@types/node": "18.16.1", "rome": "^12.1.3" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4d9db983..3abb761b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@ts-rest/core': specifier: ^3.28.0 version: 3.28.0(zod@3.22.2) + typescript: + specifier: 5.1.6 + version: 5.1.6 zod: specifier: ^3.22.2 version: 3.22.2 @@ -21,9 +24,6 @@ importers: rome: specifier: ^12.1.3 version: 12.1.3 - typescript: - specifier: 5.1.6 - version: 5.1.6 backend: dependencies: From 1ac5b231c13ddf24b47d75d3358539f0f7b391a8 Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 21 Sep 2023 17:05:16 +0900 Subject: [PATCH 2/8] feat: add mydata service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 토큰에서 id 정보 찾아서 유저 정보 반환하는 controller --- backend/src/v1/users/users.controller.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/src/v1/users/users.controller.ts b/backend/src/v1/users/users.controller.ts index 0b5ffda0..dd53380f 100644 --- a/backend/src/v1/users/users.controller.ts +++ b/backend/src/v1/users/users.controller.ts @@ -184,6 +184,23 @@ export const myupdate = async ( return 0; }; +export const mydata = async ( + req: Request, + res: Response, +) => { + console.log(req.user); + const { id: tokenId } = req.user as any; + try { + const user = await usersService.searchUserById(parseInt(tokenId, 10)); + console.log(user); + if (!user || !user.items || !user.items[0]) return res.status(404).send('Not Found'); + return res.status(200).json(user.items[0]); + } catch (error: any) { + logger.error(error); + return res.status(500).send('Internal Server Error'); + } +}; + export const getVersion = async ( req: Request, res: Response, From 70943316a3035b2ac04f14e517ec2a35bfaa6a08 Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 21 Sep 2023 17:05:44 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20search=20?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=20id=20=EA=B0=80=20undefined=20=20?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=ED=95=B8=EB=93=A4=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/v1/users/users.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/v1/users/users.service.ts b/backend/src/v1/users/users.service.ts index b641e6a9..4e280514 100644 --- a/backend/src/v1/users/users.service.ts +++ b/backend/src/v1/users/users.service.ts @@ -56,6 +56,7 @@ export default class UsersService { } async searchUserById(id: number) { + if (!id) return null; let items = (await this.usersRepository.searchUserBy({ id }, 0, 0))[0]; items = await this.withLendingInfo(items); return { items }; From 1c8b49be8ed2e44fd75522b13c9be42cf1c9e812 Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 21 Sep 2023 17:07:23 +0900 Subject: [PATCH 4/8] feat: add swagger && /me endpoint && apply authValidate --- backend/src/v1/routes/users.routes.ts | 52 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/backend/src/v1/routes/users.routes.ts b/backend/src/v1/routes/users.routes.ts index b5e4efa2..7930156e 100644 --- a/backend/src/v1/routes/users.routes.ts +++ b/backend/src/v1/routes/users.routes.ts @@ -2,7 +2,7 @@ import { Router } from 'express'; import { roleSet } from '~/v1/auth/auth.type'; import authValidate from '~/v1/auth/auth.validate'; import { - create, getVersion, myupdate, search, update, + create, getVersion, myupdate, search, update, mydata, } from '~/v1/users/users.controller'; export const path = '/users'; @@ -358,10 +358,60 @@ export const router = Router(); * type: string * example: gshim.v1 */ + /** + * @openapi + * /api/users/me: + * get: + * description: 내 정보를 가져온다. + * tags: + * - users + * responses: + * '200': + * description: 내 정보를 반환한다. + * content: + * application/json: + * schema: + * properties: + * nickname: + * description: 에러코드 + * type: string + * example: jimin + * intraId: + * description: 인트라 ID + * type: string + * example: 10035 + * slack: + * description: slack 맴버 변수 + * type: string + * example: "U02LNNDRC9F" + * role: + * description: 유저의 권한 + * type: string + * example: 2 + * penaltyEbdDate: + * description: 패널티가 끝나는 날 + * type: string + * example: 2022-06-18 + * overDueDay: + * description: 현재 연체된 날수 + * type: string + * format: number + * example: 0 + * reservations: + * description: 해당 유저의 예약 정보 + * type: array + * example: [] + * lendings: + * description: 해당 유저의 대출 정보 + * type: array + * example: [] + */ +// TODO: search 에 authValildate(roleSet.librarian) 추가 router.get('/search', search) .post('/create', create) .patch('/update/:id', authValidate(roleSet.librarian), update) .patch('/myupdate', authValidate(roleSet.all), myupdate) + .get('/me', authValidate(roleSet.all), mydata) .get('/EasterEgg', getVersion); // .delete('/delete/:id', authValidate(roleSet.librarian), deleteUser); \ No newline at end of file From 5754befd96e48f600d4b36de1874e030e49cc498 Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 21 Sep 2023 17:30:45 +0900 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20searchUsersById=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9D=84=20=EC=9D=B4=EC=A0=84=EA=B3=BC=20=EA=B0=99=EC=9D=B4=20?= =?UTF-8?q?=EB=A6=AC=ED=84=B4=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit searchUsersById 서비스 함수의 종속성이 생각보다 많음.controller 에서 items 의 length 를 확인하도록 --- backend/src/v1/users/users.controller.ts | 2 +- backend/src/v1/users/users.service.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/v1/users/users.controller.ts b/backend/src/v1/users/users.controller.ts index dd53380f..11374656 100644 --- a/backend/src/v1/users/users.controller.ts +++ b/backend/src/v1/users/users.controller.ts @@ -193,7 +193,7 @@ export const mydata = async ( try { const user = await usersService.searchUserById(parseInt(tokenId, 10)); console.log(user); - if (!user || !user.items || !user.items[0]) return res.status(404).send('Not Found'); + if (user.items.length === 0) return res.status(404).send('Not Found'); return res.status(200).json(user.items[0]); } catch (error: any) { logger.error(error); diff --git a/backend/src/v1/users/users.service.ts b/backend/src/v1/users/users.service.ts index 4e280514..b641e6a9 100644 --- a/backend/src/v1/users/users.service.ts +++ b/backend/src/v1/users/users.service.ts @@ -56,7 +56,6 @@ export default class UsersService { } async searchUserById(id: number) { - if (!id) return null; let items = (await this.usersRepository.searchUserBy({ id }, 0, 0))[0]; items = await this.withLendingInfo(items); return { items }; From 144902888603f1f23d401a0f6c10c9d4bbb27863 Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 21 Sep 2023 17:45:49 +0900 Subject: [PATCH 6/8] fix: add librarian validate in search endpoint --- backend/src/v1/routes/users.routes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/v1/routes/users.routes.ts b/backend/src/v1/routes/users.routes.ts index 000e6247..409d215a 100644 --- a/backend/src/v1/routes/users.routes.ts +++ b/backend/src/v1/routes/users.routes.ts @@ -406,7 +406,7 @@ export const router = Router(); * example: [] */ router - .get('/search', search) + .get('/search', authValidate(roleSet.librarian), search) .post('/create', create) .patch('/update/:id', authValidate(roleSet.librarian), update) .patch('/myupdate', authValidate(roleSet.all), myupdate) From cda9990ed026cf801135eb110b9cfdb73e87f8a3 Mon Sep 17 00:00:00 2001 From: jhmin95 Date: Tue, 26 Sep 2023 10:35:22 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=EC=9C=A0=EC=A0=80=EB=A7=8C=20=EB=B3=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=B0=BE=EC=9D=84=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20middleware=20=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EA=B6=8C=ED=95=9C=20=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/v1/routes/users.routes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/v1/routes/users.routes.ts b/backend/src/v1/routes/users.routes.ts index 409d215a..1ab9c82a 100644 --- a/backend/src/v1/routes/users.routes.ts +++ b/backend/src/v1/routes/users.routes.ts @@ -410,7 +410,7 @@ router .post('/create', create) .patch('/update/:id', authValidate(roleSet.librarian), update) .patch('/myupdate', authValidate(roleSet.all), myupdate) - .get('/me', authValidate(roleSet.all), mydata) + .get('/me', authValidate(roleSet.service), mydata) .get('/EasterEgg', getVersion); // .delete('/delete/:id', authValidate(roleSet.librarian), deleteUser); From 7b7ad82e8a1bdc38fed26297bd7836487849ec61 Mon Sep 17 00:00:00 2001 From: jhmin95 Date: Tue, 26 Sep 2023 10:35:45 +0900 Subject: [PATCH 8/8] =?UTF-8?q?chore:=20console.log=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/v1/users/users.controller.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/v1/users/users.controller.ts b/backend/src/v1/users/users.controller.ts index 64de4d4c..b7aec194 100644 --- a/backend/src/v1/users/users.controller.ts +++ b/backend/src/v1/users/users.controller.ts @@ -181,11 +181,9 @@ export const mydata = async ( req: Request, res: Response, ) => { - console.log(req.user); const { id: tokenId } = req.user as any; try { const user = await usersService.searchUserById(parseInt(tokenId, 10)); - console.log(user); if (user.items.length === 0) return res.status(404).send('Not Found'); return res.status(200).json(user.items[0]); } catch (error: any) {