From db2bed09cedee1a02dd8a8fbf6b66a4804468166 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Fri, 19 Jan 2024 18:24:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FEAT]=20#236=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EC=8B=9C,=20=EC=8A=AC=EB=9E=99=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=EB=A1=9C=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/alarmController.ts | 55 +- src/controller/authController.ts | 280 ++++++---- src/controller/bookshelfController.ts | 365 +++++++------ src/controller/friendController.ts | 530 +++++++++++-------- src/controller/mypageController.ts | 287 +++++----- src/controller/pickController.ts | 128 +++-- src/controller/recommendController.ts | 61 ++- src/controller/userController.ts | 8 +- src/modules/jwtHandler.ts | 4 +- src/modules/{ => slack}/slackErrorMessage.ts | 0 src/modules/slack/slackSignUpMessage.ts | 7 + src/modules/slack/slackWebhook.ts | 26 + src/modules/slackWebhook.ts | 12 - src/service/userService.ts | 1 - 14 files changed, 1037 insertions(+), 727 deletions(-) rename src/modules/{ => slack}/slackErrorMessage.ts (100%) create mode 100644 src/modules/slack/slackSignUpMessage.ts create mode 100644 src/modules/slack/slackWebhook.ts delete mode 100644 src/modules/slackWebhook.ts diff --git a/src/controller/alarmController.ts b/src/controller/alarmController.ts index 3482718..3e19e26 100644 --- a/src/controller/alarmController.ts +++ b/src/controller/alarmController.ts @@ -2,35 +2,44 @@ import { Request, Response } from "express"; import { rm, sc } from "../constants"; import { fail, success } from "../constants/response"; import { alarmService } from "../service"; -import { slackErrorMessage } from "../modules/slackErrorMessage"; -import { sendWebhookMessage } from "../modules/slackWebhook"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; +import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook"; const getAlarm = async (req: Request, res: Response) => { - const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const userId = req.body.userId; + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + try { + const data = await alarmService.getAlarm(+userId); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_GET_ALARM)); } - try { - const data = await alarmService.getAlarm(+userId); - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_GET_ALARM)); - } + return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_ALARM, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_ALARM, data)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + sendWebhookErrorMessage(errorMessage); - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - -} + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; const alarmController = { - getAlarm, -} + getAlarm, +}; -export default alarmController; \ No newline at end of file +export default alarmController; diff --git a/src/controller/authController.ts b/src/controller/authController.ts index c80c227..a49f97f 100644 --- a/src/controller/authController.ts +++ b/src/controller/authController.ts @@ -1,54 +1,69 @@ - import { Request, Response } from "express"; import { validationResult } from "express-validator"; import { rm, sc, tokenType } from "../constants"; import { fail, success } from "../constants/response"; import { SignUpReqDTO } from "../interfaces/auth/SignUpReqDTO"; -import { slackErrorMessage } from "../modules/slackErrorMessage"; -import { sendWebhookMessage } from "../modules/slackWebhook"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; import { bookshelfService, userService } from "../service"; import authService from "../service/authService"; import jwtHandler from "../modules/jwtHandler"; - +import { slackSignUpMessage } from "../modules/slack/slackSignUpMessage"; +import { + sendWebhookErrorMessage, + sendWebhookSignUpMessage, +} from "../modules/slack/slackWebhook"; /** * @route POST /auth/singin * @desc 소셜 로그인 하기 **/ const signIn = async (req: Request, res: Response) => { - - const error = validationResult(req); - if (!error.isEmpty()) { - return res - .status(sc.UNAUTHORIZED) - .send(fail(sc.UNAUTHORIZED, rm.INVALID_SOCIAL_TOKEN)); - } + const error = validationResult(req); + if (!error.isEmpty()) { + return res + .status(sc.UNAUTHORIZED) + .send(fail(sc.UNAUTHORIZED, rm.INVALID_SOCIAL_TOKEN)); + } - // 소셜 로그인 access token - const socialToken = req.header('accessToken')?.split(" ").reverse()[0] as string; - const { socialPlatform } = req.body; + // 소셜 로그인 access token + const socialToken = req + .header("accessToken") + ?.split(" ") + .reverse()[0] as string; + const { socialPlatform } = req.body; - if (socialPlatform === null || socialPlatform === undefined) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); - } + if (socialPlatform === null || socialPlatform === undefined) { + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + } - try { - const data = await authService.signIn(socialToken, socialPlatform); + try { + const data = await authService.signIn(socialToken, socialPlatform); - if (data === rm.INVALID_SOCIAL_TOKEN) { - return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_SOCIAL_TOKEN)) - } + if (data === rm.INVALID_SOCIAL_TOKEN) { + return res + .status(sc.UNAUTHORIZED) + .send(fail(sc.UNAUTHORIZED, rm.INVALID_SOCIAL_TOKEN)); + } - return res.status(sc.OK).send(success(sc.OK, rm.SIGNIN_SUCCESS, data)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + return res.status(sc.OK).send(success(sc.OK, rm.SIGNIN_SUCCESS, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - sendWebhookMessage(errorMessage); + sendWebhookErrorMessage(errorMessage); - if (error == sc.UNAUTHORIZED) { - return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN)); - } - return res.status(sc.INTERNAL_SERVER_ERROR).send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + if (error == sc.UNAUTHORIZED) { + return res + .status(sc.UNAUTHORIZED) + .send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN)); + } + return res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); } }; @@ -56,116 +71,161 @@ const signIn = async (req: Request, res: Response) => { * @route PATCH /auth/signup * @desc 회원 가입 */ -const signUp = async (req: Request, res:Response) => { - const userId = req.body.userId; - const signUpdDto : SignUpReqDTO = req.body; - const image: Express.MulterS3.File|undefined = req.file as Express.MulterS3.File; +const signUp = async (req: Request, res: Response) => { + const userId = req.body.userId; + const signUpdDto: SignUpReqDTO = req.body; + const image: Express.MulterS3.File | undefined = + req.file as Express.MulterS3.File; - signUpdDto.profileImage = image ? image.location : null; + signUpdDto.profileImage = image ? image.location : null; - if (!signUpdDto.intro || !signUpdDto.nickname) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); - } + if (!signUpdDto.intro || !signUpdDto.nickname) { + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + } - const intro = signUpdDto.intro; - const refinedIntro = intro.replace(/\n/g, " "); - const nickname = signUpdDto.nickname; - const refinedNickname = nickname.replace(/ /g, ""); + const intro = signUpdDto.intro; + const refinedIntro = intro.replace(/\n/g, " "); + const nickname = signUpdDto.nickname; + const refinedNickname = nickname.replace(/ /g, ""); - signUpdDto.intro = refinedIntro; - signUpdDto.nickname = refinedNickname; + signUpdDto.intro = refinedIntro; + signUpdDto.nickname = refinedNickname; - try { - const data = await authService.signUp(+userId, signUpdDto); + try { + const data = await authService.signUp(+userId, signUpdDto); - return res.status(sc.OK).send(success(sc.OK, rm.SIGNUP_SUCCESS)); + const signUpMessage = slackSignUpMessage(userId, data.nickname, data.email); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + sendWebhookSignUpMessage(signUpMessage); - sendWebhookMessage(errorMessage); + return res.status(sc.OK).send(success(sc.OK, rm.SIGNUP_SUCCESS)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - return res.status(sc.INTERNAL_SERVER_ERROR).send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } -}; + sendWebhookErrorMessage(errorMessage); + return res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route GET /auth/token * @desc 만료된 토큰을 재발급 */ const getToken = async (req: Request, res: Response) => { - const accessToken = req.header("accessToken")?.split(" ").reverse()[0] as string; - const refreshToken = req.header("refreshToken")?.split(" ").reverse()[0] as string; + const accessToken = req + .header("accessToken") + ?.split(" ") + .reverse()[0] as string; + const refreshToken = req + .header("refreshToken") + ?.split(" ") + .reverse()[0] as string; + + if (!refreshToken || !accessToken) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.EMPTY_TOKEN)); + } - if (!refreshToken || !accessToken) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.EMPTY_TOKEN)); - } + try { + const decodedToken = jwtHandler.verify(accessToken); - try { - const decodedToken = jwtHandler.verify(accessToken); - - if (decodedToken == tokenType.TOKEN_INVALID) return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN)); - - if (decodedToken == tokenType.TOKEN_EXPIRED) { - const refresh = jwtHandler.verify(refreshToken); - - if (refresh == tokenType.TOKEN_INVALID) return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_REFRESH_TOKEN)); - if (refresh == tokenType.TOKEN_EXPIRED) return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.EXPIRED_ALL_TOKEN)); - - const user = await userService.getUserByRfToken(refreshToken); - - if (!user) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - const accessToken = jwtHandler.sign(user.id); - - const result = { - newAccessToken : accessToken, - refreshToken - } - - return res.status(sc.OK).send(success(sc.OK, rm.CREATE_TOKEN_SUCCESS, result)); - } - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NOT_EXPIRED_TOKEN)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - return res.status(sc.INTERNAL_SERVER_ERROR).send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } -} + if (decodedToken == tokenType.TOKEN_INVALID) + return res + .status(sc.UNAUTHORIZED) + .send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN)); + if (decodedToken == tokenType.TOKEN_EXPIRED) { + const refresh = jwtHandler.verify(refreshToken); -//* 나중에 삭제할 로직 !!! -const testSignin = async (req: Request, res:Response) => { + if (refresh == tokenType.TOKEN_INVALID) + return res + .status(sc.UNAUTHORIZED) + .send(fail(sc.UNAUTHORIZED, rm.INVALID_REFRESH_TOKEN)); + if (refresh == tokenType.TOKEN_EXPIRED) + return res + .status(sc.UNAUTHORIZED) + .send(fail(sc.UNAUTHORIZED, rm.EXPIRED_ALL_TOKEN)); - const auth = req.header("auth"); - if (!auth) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const user = await userService.getUserByRfToken(refreshToken); + + if (!user) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + const accessToken = jwtHandler.sign(user.id); + + const result = { + newAccessToken: accessToken, + refreshToken, + }; + + return res + .status(sc.OK) + .send(success(sc.OK, rm.CREATE_TOKEN_SUCCESS, result)); } + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.NOT_EXPIRED_TOKEN)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + return res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; - try { - - const data = await authService.testSignin(+auth); +//* 나중에 삭제할 로직 !!! +const testSignin = async (req: Request, res: Response) => { + const auth = req.header("auth"); + if (!auth) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } - return res.status(sc.OK).send(success(sc.OK, rm.SIGNIN_SUCCESS, data)); + try { + const data = await authService.testSignin(+auth); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + return res.status(sc.OK).send(success(sc.OK, rm.SIGNIN_SUCCESS, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - sendWebhookMessage(errorMessage); + sendWebhookErrorMessage(errorMessage); - return res.status(sc.INTERNAL_SERVER_ERROR).send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } + return res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } }; const AuthController = { - signIn, - signUp, - getToken, - testSignin + signIn, + signUp, + getToken, + testSignin, }; export default AuthController; diff --git a/src/controller/bookshelfController.ts b/src/controller/bookshelfController.ts index 1fb3950..1f440f8 100644 --- a/src/controller/bookshelfController.ts +++ b/src/controller/bookshelfController.ts @@ -3,8 +3,8 @@ import { rm, sc } from "../constants"; import { fail, success } from "../constants/response"; import { BookshelfCreateDTO } from "../interfaces/bookshelf/BookshelfCreateDTO"; import { BookshelfUpdateDTO } from "../interfaces/bookshelf/BookshelfUpdateDTO"; -import { slackErrorMessage } from "../modules/slackErrorMessage"; -import { sendWebhookMessage } from "../modules/slackWebhook"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; +import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook"; import { bookshelfService } from "../service"; /** @@ -12,37 +12,49 @@ import { bookshelfService } from "../service"; * @desc 내 책장에 책 등록하기 **/ const createMyBook = async (req: Request, res: Response) => { - const bookshelfCreateDto: BookshelfCreateDTO = req.body; - const auth = req.body.userId; - - const refinedDescription = bookshelfCreateDto.description.replace(/\n/g, " "); - const refinedMemo = bookshelfCreateDto.memo.replace(/\n/g, " "); - bookshelfCreateDto.description = refinedDescription; - bookshelfCreateDto.memo = refinedMemo; - - if (!bookshelfCreateDto.author || !bookshelfCreateDto.bookTitle) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.CREATE_MYBOOK_FAIL)); - } - - try { - const data = await bookshelfService.createMyBook(+auth, bookshelfCreateDto); - - const createMybookDTO = { - "id": data.id - } - - if (!data) { - return res.status(sc.INTERNAL_SERVER_ERROR).send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - return res.status(sc.CREATED).send(success(sc.CREATED, rm.CREATE_MYBOOK_SUCCESS, createMybookDTO)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + const bookshelfCreateDto: BookshelfCreateDTO = req.body; + const auth = req.body.userId; + + const refinedDescription = bookshelfCreateDto.description.replace(/\n/g, " "); + const refinedMemo = bookshelfCreateDto.memo.replace(/\n/g, " "); + bookshelfCreateDto.description = refinedDescription; + bookshelfCreateDto.memo = refinedMemo; + + if (!bookshelfCreateDto.author || !bookshelfCreateDto.bookTitle) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.CREATE_MYBOOK_FAIL)); + } + + try { + const data = await bookshelfService.createMyBook(+auth, bookshelfCreateDto); + + const createMybookDTO = { + id: data.id, + }; + + if (!data) { + return res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); } + return res + .status(sc.CREATED) + .send(success(sc.CREATED, rm.CREATE_MYBOOK_SUCCESS, createMybookDTO)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } }; /** @@ -50,164 +62,217 @@ const createMyBook = async (req: Request, res: Response) => { * @desc 등록한 책의 상세 정보 불러오기 */ const getBookById = async (req: Request, res: Response) => { - const { bookshelfId } = req.params; - - try { - if (!bookshelfId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } + const { bookshelfId } = req.params; - const data = await bookshelfService.getBookById(+bookshelfId); - - if (data === null || data === undefined) { - return res.status(sc.NOT_FOUND).send(fail(sc.NOT_FOUND, rm.READ_MYBOOK_FAIL)); - } - return res.status(sc.OK).send(success(sc.OK, rm.READ_MYBOOK_SUCCESS, data)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + try { + if (!bookshelfId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } - sendWebhookMessage(errorMessage); + const data = await bookshelfService.getBookById(+bookshelfId); - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + if (data === null || data === undefined) { + return res + .status(sc.NOT_FOUND) + .send(fail(sc.NOT_FOUND, rm.READ_MYBOOK_FAIL)); } -} + return res.status(sc.OK).send(success(sc.OK, rm.READ_MYBOOK_SUCCESS, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route DELETE /bookshelf/:bookshelfId * @desc 등록한 책 삭제하기 */ const deleteMyBook = async (req: Request, res: Response) => { - const { bookshelfId } = req.params; - - try { - if (!bookshelfId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } + const { bookshelfId } = req.params; - const data = await bookshelfService.deleteMyBook(+bookshelfId); - - if (data == sc.NOT_FOUND) { - return res.status(sc.NOT_FOUND).send(fail(sc.NOT_FOUND, rm.READ_MYBOOK_FAIL)); - } - return res.status(sc.OK).send(success(sc.OK, rm.DELETE_MYBOOK_SUCCESS)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + try { + if (!bookshelfId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } - sendWebhookMessage(errorMessage); + const data = await bookshelfService.deleteMyBook(+bookshelfId); - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + if (data == sc.NOT_FOUND) { + return res + .status(sc.NOT_FOUND) + .send(fail(sc.NOT_FOUND, rm.READ_MYBOOK_FAIL)); } -} + return res.status(sc.OK).send(success(sc.OK, rm.DELETE_MYBOOK_SUCCESS)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route PATCH /bookshelf/:bookshelfId * @desc 등록한 책 정보 수정하기 */ const updateMyBook = async (req: Request, res: Response) => { - const bookshelfUpdateDto: BookshelfUpdateDTO = req.body; - const { bookshelfId } = req.params; - const auth = req.body.userId; - - const refinedDescription = bookshelfUpdateDto.description?.replace(/\n/g, " "); - const refinedMemo = bookshelfUpdateDto.memo?.replace(/\n/g, " "); - bookshelfUpdateDto.description = refinedDescription; - bookshelfUpdateDto.memo = refinedMemo; - - try { - if(!bookshelfId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - - if (!bookshelfUpdateDto) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.UPDATE_MYBOOK_FAIL)); - } - - const data = await bookshelfService.updateMyBook(+bookshelfId, bookshelfUpdateDto); - - if (data == sc.NOT_FOUND) { - return res.status(sc.NOT_FOUND).send(fail(sc.NOT_FOUND, rm.READ_MYBOOK_FAIL)); - } - return res.status(sc.OK).send(success(sc.OK, rm.UPDATE_MYBOOK_SUCCESS)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + const bookshelfUpdateDto: BookshelfUpdateDTO = req.body; + const { bookshelfId } = req.params; + const auth = req.body.userId; + + const refinedDescription = bookshelfUpdateDto.description?.replace( + /\n/g, + " " + ); + const refinedMemo = bookshelfUpdateDto.memo?.replace(/\n/g, " "); + bookshelfUpdateDto.description = refinedDescription; + bookshelfUpdateDto.memo = refinedMemo; + + try { + if (!bookshelfId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); } -} + if (!bookshelfUpdateDto) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.UPDATE_MYBOOK_FAIL)); + } + + const data = await bookshelfService.updateMyBook( + +bookshelfId, + bookshelfUpdateDto + ); + + if (data == sc.NOT_FOUND) { + return res + .status(sc.NOT_FOUND) + .send(fail(sc.NOT_FOUND, rm.READ_MYBOOK_FAIL)); + } + return res.status(sc.OK).send(success(sc.OK, rm.UPDATE_MYBOOK_SUCCESS)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route GET /bookshelf * @desc 내 책장 (메인 뷰) 조회하기 */ const getMyBookshelf = async (req: Request, res: Response) => { - const auth = req.body.userId; + const auth = req.body.userId; - const data = await bookshelfService.getMyBookshelf(+auth); + const data = await bookshelfService.getMyBookshelf(+auth); - try { - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - return res.status(sc.OK).send(success(sc.OK, rm.READ_BOOKSHELF_SUCCESS, data)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + try { + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); } -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.READ_BOOKSHELF_SUCCESS, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route GET /bookshelf/friend/:friendId * @desc 친구 책장 조회하기 */ const getFriendBookshelf = async (req: Request, res: Response) => { - const { friendId } = req.params; - const auth = req.body.userId; - - if (!friendId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const { friendId } = req.params; + const auth = req.body.userId; + + if (!friendId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + const data = await bookshelfService.getFriendBookshelf(+auth, +friendId); + + try { + if (data == sc.NOT_FOUND) { + return res + .status(sc.NOT_FOUND) + .send(fail(sc.NOT_FOUND, rm.NOT_FOUND_FRIEND_ID)); } - const data = await bookshelfService.getFriendBookshelf(+auth, +friendId); - - try { - if (data == sc.NOT_FOUND) { - return res.status(sc.NOT_FOUND).send(fail(sc.NOT_FOUND, rm.NOT_FOUND_FRIEND_ID)); - } - - return res.status(sc.OK).send(success(sc.OK, rm.READ_FRIEND_BOOKSHELF_SUCCESS, data)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - - -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.READ_FRIEND_BOOKSHELF_SUCCESS, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; const bookshelfController = { - createMyBook, - getBookById, - deleteMyBook, - updateMyBook, - getMyBookshelf, - getFriendBookshelf + createMyBook, + getBookById, + deleteMyBook, + updateMyBook, + getMyBookshelf, + getFriendBookshelf, }; -export default bookshelfController; \ No newline at end of file +export default bookshelfController; diff --git a/src/controller/friendController.ts b/src/controller/friendController.ts index 30b886c..6238194 100644 --- a/src/controller/friendController.ts +++ b/src/controller/friendController.ts @@ -1,274 +1,354 @@ -import { FriendRecommendRequestDTO } from './../interfaces/friend/FriendRecommendRequestDTO'; +import { FriendRecommendRequestDTO } from "./../interfaces/friend/FriendRecommendRequestDTO"; import { Request, Response } from "express"; import { fail, success } from "../constants/response"; import { rm, sc } from "../constants"; -import { friendService } from '../service'; -import { slackErrorMessage } from '../modules/slackErrorMessage'; -import { sendWebhookMessage } from "../modules/slackWebhook"; -import { FriendReportRequestDTO } from '../interfaces/friend/FriendReportRequestDTO'; +import { friendService } from "../service"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; +import { FriendReportRequestDTO } from "../interfaces/friend/FriendReportRequestDTO"; import { mailSender } from "../modules/mail"; -import { ReportMailRequestDTO } from '../interfaces/friend/ReportMailRequestDTO'; -import { reportMessage } from '../modules/reportMessage'; -import { userService } from '../service'; -import { reportMailDTO } from '../interfaces/friend/reportMailDTO'; -import blockService from '../service/blockService'; - -//* 친구에게 책 추천하기 +import { ReportMailRequestDTO } from "../interfaces/friend/ReportMailRequestDTO"; +import { reportMessage } from "../modules/reportMessage"; +import { userService } from "../service"; +import { reportMailDTO } from "../interfaces/friend/reportMailDTO"; +import blockService from "../service/blockService"; +import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook"; + +//* 친구에게 책 추천하기 const recommendBookToFriend = async (req: Request, res: Response) => { - const { friendId } = req.params; - const friendRecommendRequestDTO: FriendRecommendRequestDTO = req.body; - const userId = req.body.userId; - - const refinedRecommendDesc = friendRecommendRequestDTO.recommendDesc.replace(/\n/g, " "); - friendRecommendRequestDTO.recommendDesc = refinedRecommendDesc; - - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const { friendId } = req.params; + const friendRecommendRequestDTO: FriendRecommendRequestDTO = req.body; + const userId = req.body.userId; + + const refinedRecommendDesc = friendRecommendRequestDTO.recommendDesc.replace( + /\n/g, + " " + ); + friendRecommendRequestDTO.recommendDesc = refinedRecommendDesc; + + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + if (!friendId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.NOT_FOUND_FRIEND_ID)); + } + try { + const data = await friendService.recommendBookToFriend( + friendRecommendRequestDTO, + +friendId, + +userId + ); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_RECOMMEND_BOOK)); } - if (!friendId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NOT_FOUND_FRIEND_ID)); + if (data == sc.NOT_FOUND) { + return res + .status(sc.NOT_FOUND) + .send(fail(sc.NOT_FOUND, rm.FAIL_NO_FRIEND)); } - try { - const data = await friendService.recommendBookToFriend(friendRecommendRequestDTO, +friendId, +userId); - - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_RECOMMEND_BOOK)); - } - if (data == sc.NOT_FOUND) { - return res.status(sc.NOT_FOUND).send(fail(sc.NOT_FOUND, rm.FAIL_NO_FRIEND)); - } - - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_RECOMMEND_BOOK, data)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.SUCCESS_RECOMMEND_BOOK, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; //* 사용자 검색하기 const searchUser = async (req: Request, res: Response) => { - const { nickname } = req.query; - const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - - if (!nickname) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NOT_FOUND_FRIEND_ID)); + const { nickname } = req.query; + const userId = req.body.userId; + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + if (!nickname) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.NOT_FOUND_FRIEND_ID)); + } + + try { + const data = await friendService.searchUser(nickname as string, +userId); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_NO_FRIEND_EXIST)); } - try { - const data = await friendService.searchUser(nickname as string, +userId); - - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_NO_FRIEND_EXIST)); - } + return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_USER, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_USER, data)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + sendWebhookErrorMessage(errorMessage); - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - -} + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; //* 사용자 팔로우 하기 const followFriend = async (req: Request, res: Response) => { - const { friendId } = req.params; - const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - - if (!friendId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NOT_FOUND_FRIEND_ID)); - } - try { - const data = await friendService.followFriend(+friendId, +userId); - - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_POST_FOLLOW)); - } - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_POST_FOLLOW, data)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + const { friendId } = req.params; + const userId = req.body.userId; + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + if (!friendId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.NOT_FOUND_FRIEND_ID)); + } + try { + const data = await friendService.followFriend(+friendId, +userId); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_POST_FOLLOW)); } - -} + return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_POST_FOLLOW, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route DELETE /friend/:friendId * @desc 팔로우 취소하기 **/ const deleteFollowFriend = async (req: Request, res: Response) => { - const { friendId } = req.params; - const auth = req.body.userId; - - if (!friendId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const { friendId } = req.params; + const auth = req.body.userId; + + if (!friendId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + try { + const data = await friendService.deleteFollowFriend(+friendId, +auth); + + if (data === sc.NOT_FOUND) { + return res + .status(sc.NOT_FOUND) + .send(fail(sc.NOT_FOUND, rm.NOT_FOUND_FRIEND_ID)); } - try { - const data = await friendService.deleteFollowFriend(+friendId, +auth); - - if (data === sc.NOT_FOUND) { - return res.status(sc.NOT_FOUND).send(fail(sc.NOT_FOUND, rm.NOT_FOUND_FRIEND_ID)); - } - - return res.status(sc.OK).send(success(sc.OK, rm.DELETE_FRIEND_SUCCESS)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + return res.status(sc.OK).send(success(sc.OK, rm.DELETE_FRIEND_SUCCESS)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - sendWebhookMessage(errorMessage); + sendWebhookErrorMessage(errorMessage); - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - -} + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; //* 친구 신고하기 const postReport = async (req: Request, res: Response) => { - const { friendId } = req.params; - const friendReportRequestDto: FriendReportRequestDTO = req.body; - const userId = req.body.userId; - - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const { friendId } = req.params; + const friendReportRequestDto: FriendReportRequestDTO = req.body; + const userId = req.body.userId; + + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + if (!friendId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_FOUND_FRIEND_ID)); + } + + if (!friendReportRequestDto.reasonIndex) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_REPORT_POST)); + } + + try { + const data = await friendService.postReport( + +userId, + +friendId, + friendReportRequestDto + ); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_REPORT_POST)); } - if (!friendId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_FOUND_FRIEND_ID)); + if (data == sc.NOT_FOUND) { + return res + .status(sc.NOT_FOUND) + .send(fail(sc.NOT_FOUND, rm.REPORT_NO_USER)); } - if (!friendReportRequestDto.reasonIndex) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_REPORT_POST)); - } - - try { - const data = await friendService.postReport(+userId, +friendId, friendReportRequestDto); - - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_REPORT_POST)); - } - - if (data == sc.NOT_FOUND) { - return res.status(sc.NOT_FOUND).send(fail(sc.NOT_FOUND, rm.REPORT_NO_USER)); - } - - postMail(friendReportRequestDto, +friendId, +userId); - - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_REPORT_POST)); - - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - -} - -const postMail = async (friendReportRequestDto: FriendReportRequestDTO, friendId: number, userId: number) => { - const userName = await userService.getUserIntro(userId); - const friendName = await userService.getUserIntro(friendId); - let reasonString = "reason"; - switch (friendReportRequestDto.reasonIndex) { - case 1: - reasonString = rm.REASON_ONE; - break; - case 2: - reasonString = rm.REASON_TWO; - break; - case 3: - reasonString = rm.REASON_THREE; - break; - case 4: - reasonString = rm.REASON_FOUR; - break; - default: - reasonString = rm.REASON_FIVE; - break; - } - - if (friendReportRequestDto.etc == null) { - friendReportRequestDto.etc = "구체적 사유 없습니다." - } - const reportMailDTO: reportMailDTO = { - userNickname: userName.nickname, - userId: userId, - friendNickname: friendName.nickname, - friendId: friendId, - reasonString: reasonString, - etc: friendReportRequestDto.etc - } - - const message = reportMessage(reportMailDTO); - - const reportMailRequest: ReportMailRequestDTO = { - mailTitle: rm.MAIL_TITLE, - text: message, - } - - mailSender.sendGmail(reportMailRequest); -} + postMail(friendReportRequestDto, +friendId, +userId); + + return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_REPORT_POST)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; + +const postMail = async ( + friendReportRequestDto: FriendReportRequestDTO, + friendId: number, + userId: number +) => { + const userName = await userService.getUserIntro(userId); + const friendName = await userService.getUserIntro(friendId); + let reasonString = "reason"; + switch (friendReportRequestDto.reasonIndex) { + case 1: + reasonString = rm.REASON_ONE; + break; + case 2: + reasonString = rm.REASON_TWO; + break; + case 3: + reasonString = rm.REASON_THREE; + break; + case 4: + reasonString = rm.REASON_FOUR; + break; + default: + reasonString = rm.REASON_FIVE; + break; + } + + if (friendReportRequestDto.etc == null) { + friendReportRequestDto.etc = "구체적 사유 없습니다."; + } + const reportMailDTO: reportMailDTO = { + userNickname: userName.nickname, + userId: userId, + friendNickname: friendName.nickname, + friendId: friendId, + reasonString: reasonString, + etc: friendReportRequestDto.etc, + }; + + const message = reportMessage(reportMailDTO); + + const reportMailRequest: ReportMailRequestDTO = { + mailTitle: rm.MAIL_TITLE, + text: message, + }; + + mailSender.sendGmail(reportMailRequest); +}; /** * @route POST /friend/block/:friendId * @desc 친구 차단하기 **/ const blockFriend = async (req: Request, res: Response) => { - const { friendId } = req.params; - //* middleware로 auth 받기 - const userId = req.body.userId; - - if (!friendId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); - } + const { friendId } = req.params; + //* middleware로 auth 받기 + const userId = req.body.userId; - try { - const data = await blockService.blockFriend(+userId, +friendId); + if (!friendId) { + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + } - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_BLOCK_FRIEND)); + try { + const data = await blockService.blockFriend(+userId, +friendId); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - sendWebhookMessage(errorMessage); - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); } -} + return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_BLOCK_FRIEND)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + sendWebhookErrorMessage(errorMessage); + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; const friendController = { - recommendBookToFriend, - searchUser, - followFriend, - deleteFollowFriend, - postReport, - blockFriend -} - -export default friendController; \ No newline at end of file + recommendBookToFriend, + searchUser, + followFriend, + deleteFollowFriend, + postReport, + blockFriend, +}; + +export default friendController; diff --git a/src/controller/mypageController.ts b/src/controller/mypageController.ts index 3a4543e..be50693 100644 --- a/src/controller/mypageController.ts +++ b/src/controller/mypageController.ts @@ -1,169 +1,212 @@ -import { FriendRecommendRequestDTO } from './../interfaces/friend/FriendRecommendRequestDTO'; +import { FriendRecommendRequestDTO } from "./../interfaces/friend/FriendRecommendRequestDTO"; import { Request, Response } from "express"; import { fail, success } from "../constants/response"; import { rm, sc } from "../constants"; -import { slackErrorMessage } from '../modules/slackErrorMessage'; -import { sendWebhookMessage } from "../modules/slackWebhook"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; + import { friendService, mypageService, userService } from "../service"; import { userTokenCheck } from "../constants/userTokenCheck"; -import { patchUserRequestDTO } from '../interfaces/mypage/patchUserRequestDTO'; -import blockService from '../service/blockService'; +import { patchUserRequestDTO } from "../interfaces/mypage/patchUserRequestDTO"; +import blockService from "../service/blockService"; +import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook"; //* 유저 탈퇴하기 const deleteUser = async (req: Request, res: Response) => { - const userId = req.body.userId; + const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); - } + if (!userId) { + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + } - try { - const data = await mypageService.deleteUser(+userId); + try { + const data = await mypageService.deleteUser(+userId); - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.DELETE_USER_FAIL)) - } + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.DELETE_USER_FAIL)); + } - return res.status(sc.OK).send(success(sc.OK, rm.DELETE_USER_SUCCESS)); + return res.status(sc.OK).send(success(sc.OK, rm.DELETE_USER_SUCCESS)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); + sendWebhookErrorMessage(errorMessage); - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } -} + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; //* 사용자 정보 수정하기 const patchUser = async (req: Request, res: Response) => { - const userId = req.body.userId; - const patchUserRequestDTO: patchUserRequestDTO = req.body - const image: Express.MulterS3.File|undefined = req.file as Express.MulterS3.File; - - patchUserRequestDTO.profileImage = image ? image.location : null; - - - const intro = patchUserRequestDTO.intro; - const refinedIntro = intro?.replace(/\n/g, " "); - const nickname = patchUserRequestDTO.nickname; - const refinedNickname = nickname.replace(/ /g, ""); - - patchUserRequestDTO.intro = refinedIntro; - patchUserRequestDTO.nickname = refinedNickname; - - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + const userId = req.body.userId; + const patchUserRequestDTO: patchUserRequestDTO = req.body; + const image: Express.MulterS3.File | undefined = + req.file as Express.MulterS3.File; + + patchUserRequestDTO.profileImage = image ? image.location : null; + + const intro = patchUserRequestDTO.intro; + const refinedIntro = intro?.replace(/\n/g, " "); + const nickname = patchUserRequestDTO.nickname; + const refinedNickname = nickname.replace(/ /g, ""); + + patchUserRequestDTO.intro = refinedIntro; + patchUserRequestDTO.nickname = refinedNickname; + + if (!userId) { + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + } + + if (!patchUserRequestDTO.nickname) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.NULL_NICKNAME)); + } + + try { + const data = await mypageService.patchUser(+userId, patchUserRequestDTO); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.CREATE_IMAGE_FAIL)); } - if (!patchUserRequestDTO.nickname) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_NICKNAME)); - } - - try { - - const data = await mypageService.patchUser(+userId, patchUserRequestDTO); - - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.CREATE_IMAGE_FAIL)) - } - - return res.status(sc.OK).send(success(sc.OK, rm.UPDATE_USER_PRIFILE_SUCCESS)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.UPDATE_USER_PRIFILE_SUCCESS)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; //* 사용자 정보 조회하기 const getUserData = async (req: Request, res: Response) => { - const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + const userId = req.body.userId; + if (!userId) { + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + } + + try { + const data = await userService.getUserIntro(+userId); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.READ_USER_FAIL)); } - try { - const data = await userService.getUserIntro(+userId); - - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.READ_USER_FAIL)) - } + return res.status(sc.OK).send(success(sc.OK, rm.READ_USER_SUCCESS, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - return res.status(sc.OK).send(success(sc.OK, rm.READ_USER_SUCCESS, data)); + sendWebhookErrorMessage(errorMessage); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } -} + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route DELETE /mypage/blocklist/:friendId * @desc 친구 차단 해제하기 **/ const cancleBlock = async (req: Request, res: Response) => { - const { friendId } = req.params; - const userId = req.body.userId; + const { friendId } = req.params; + const userId = req.body.userId; - if (!friendId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); - } - - try { - const data = await blockService.cancleBlockedFriend(+userId, +friendId); + if (!friendId) { + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE)); + } - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_CANCLE_BLOCK_FIREND)); + try { + const data = await blockService.cancleBlockedFriend(+userId, +friendId); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - sendWebhookMessage(errorMessage); - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); } -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.SUCCESS_CANCLE_BLOCK_FIREND)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + sendWebhookErrorMessage(errorMessage); + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; /** * @route GET /mypage/blocklist * @desc 친구 차단 리스트 조회하기 **/ const getBlockList = async (req: Request, res: Response) => { - const userId = req.body.userId; - - try { - const data = await blockService.getBlockList(+userId); + const userId = req.body.userId; - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_BLOCK_LIST, data)); + try { + const data = await blockService.getBlockList(+userId); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - sendWebhookMessage(errorMessage); - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); } -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.SUCCESS_GET_BLOCK_LIST, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + sendWebhookErrorMessage(errorMessage); + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; const mypageController = { - deleteUser, - patchUser, - getUserData, - cancleBlock, - getBlockList -} - -export default mypageController; \ No newline at end of file + deleteUser, + patchUser, + getUserData, + cancleBlock, + getBlockList, +}; + +export default mypageController; diff --git a/src/controller/pickController.ts b/src/controller/pickController.ts index 4dc075f..35e5f14 100644 --- a/src/controller/pickController.ts +++ b/src/controller/pickController.ts @@ -3,73 +3,95 @@ import { fail, success } from "../constants/response"; import { rm, sc } from "../constants"; import { pickService } from "../service"; import { PickPatchRequestDTO } from "../interfaces/pick/PickPatchRequestDTO"; -import { slackErrorMessage } from "../modules/slackErrorMessage"; -import { sendWebhookMessage } from "../modules/slackWebhook"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; +import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook"; //* Pick한 책 수정 const patchPick = async (req: Request, res: Response) => { - const pickPatchRequestDTO: PickPatchRequestDTO = req.body; - const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const pickPatchRequestDTO: PickPatchRequestDTO = req.body; + const userId = req.body.userId; + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + if ( + pickPatchRequestDTO.firstPick == null || + pickPatchRequestDTO.secondPick == null || + pickPatchRequestDTO.thirdPick == null + ) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_PATCH_PICK)); + } + + try { + // 슬랙 메시지 에러 확인을 하기 위함 + // let pickData = JSON.parse(req.body); + const data = await pickService.patchPick(pickPatchRequestDTO, +userId); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_PATCH_PICK)); } - if (pickPatchRequestDTO.firstPick == null || pickPatchRequestDTO.secondPick == null || pickPatchRequestDTO.thirdPick == null) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_PATCH_PICK)); - } - - try { - // 슬랙 메시지 에러 확인을 하기 위함 - // let pickData = JSON.parse(req.body); - const data = await pickService.patchPick(pickPatchRequestDTO, +userId); - - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_PATCH_PICK)); - } - - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_PATCH_PICK)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } + return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_PATCH_PICK)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + sendWebhookErrorMessage(errorMessage); -} + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; //* 책 전체 조회 const getBook = async (req: Request, res: Response) => { - const userId = req.body.userId; - - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const userId = req.body.userId; + + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + const data = await pickService.getBook(+userId); + + try { + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_GET_BOOK)); } - const data = await pickService.getBook(+userId); - try { - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_GET_BOOK)); - } + return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_BOOK, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_BOOK, data)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } + sendWebhookErrorMessage(errorMessage); -} + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; const pickController = { - patchPick, - getBook, -} + patchPick, + getBook, +}; -export default pickController; \ No newline at end of file +export default pickController; diff --git a/src/controller/recommendController.ts b/src/controller/recommendController.ts index 428ba3c..e651fca 100644 --- a/src/controller/recommendController.ts +++ b/src/controller/recommendController.ts @@ -2,36 +2,47 @@ import { Request, Response } from "express"; import { fail, success } from "../constants/response"; import { rm, sc } from "../constants"; import { recommendService } from "../service"; -import { sendWebhookMessage } from './../modules/slackWebhook'; -import { slackErrorMessage } from "../modules/slackErrorMessage"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; +import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook"; //* 추천 책 조회하기 const getRecommend = async (req: Request, res: Response) => { - const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + const userId = req.body.userId; + if (!userId) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); + } + + try { + const data = await recommendService.getRecommend(+userId); + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_GET_RECOMMEND)); } - try { - const data = await recommendService.getRecommend(+userId); - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_GET_RECOMMEND)); - } - - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_GET_RECOMMEND, data)); - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); - } - -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.SUCCESS_GET_RECOMMEND, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookErrorMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; const recommendController = { - getRecommend, -} + getRecommend, +}; -export default recommendController; \ No newline at end of file +export default recommendController; diff --git a/src/controller/userController.ts b/src/controller/userController.ts index c79aedb..54b4704 100644 --- a/src/controller/userController.ts +++ b/src/controller/userController.ts @@ -1,10 +1,10 @@ import { Request, Response } from "express"; import { fail, success } from "../constants/response"; import { rm, sc } from "../constants"; -import { slackErrorMessage } from "../modules/slackErrorMessage"; -import { sendWebhookMessage } from "../modules/slackWebhook"; +import { slackErrorMessage } from "../modules/slack/slackErrorMessage"; import { userService } from "../service"; import { userTokenCheck } from "../constants/userTokenCheck"; +import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook"; //* 유저닉네임 중복 검사 const postDuplicateNickname = async (req: Request, res: Response) => { @@ -41,7 +41,7 @@ const postDuplicateNickname = async (req: Request, res: Response) => { req.statusCode ); - sendWebhookMessage(errorMessage); + sendWebhookErrorMessage(errorMessage); res .status(sc.INTERNAL_SERVER_ERROR) @@ -70,7 +70,7 @@ const getUserVersion = async (req: Request, res: Response) => { req.statusCode ); - sendWebhookMessage(errorMessage); + sendWebhookErrorMessage(errorMessage); res .status(sc.INTERNAL_SERVER_ERROR) diff --git a/src/modules/jwtHandler.ts b/src/modules/jwtHandler.ts index 8441b37..4cde544 100644 --- a/src/modules/jwtHandler.ts +++ b/src/modules/jwtHandler.ts @@ -9,8 +9,8 @@ const sign = (userId: number) => { userId, //피카북 서버 userId }; - const accessToken = jwt.sign(payload, privateKey, {expiresIn: "3d"}); - + const accessToken = jwt.sign(payload, privateKey, { expiresIn: "30s" }); + return accessToken; }; diff --git a/src/modules/slackErrorMessage.ts b/src/modules/slack/slackErrorMessage.ts similarity index 100% rename from src/modules/slackErrorMessage.ts rename to src/modules/slack/slackErrorMessage.ts diff --git a/src/modules/slack/slackSignUpMessage.ts b/src/modules/slack/slackSignUpMessage.ts new file mode 100644 index 0000000..b73e6e8 --- /dev/null +++ b/src/modules/slack/slackSignUpMessage.ts @@ -0,0 +1,7 @@ +export const slackSignUpMessage = ( + userId: number, + nickname: string | null, + email: string | null +) => { + return `[회원가입✨] \n ${userId}번 유저가 새로 가입을 했습니다 ! \n 닉네임 : ${nickname} \n 이메일 : ${email}`; +}; diff --git a/src/modules/slack/slackWebhook.ts b/src/modules/slack/slackWebhook.ts new file mode 100644 index 0000000..4ff554d --- /dev/null +++ b/src/modules/slack/slackWebhook.ts @@ -0,0 +1,26 @@ +import axios from "axios"; + +const webhookErrorUrl = process.env.WEBHOOK_URL_ERROR as string; +const webhookSignUpUrl = process.env.WEBHOOK_URL_SIGNUP as string; + +export const sendWebhookErrorMessage = async ( + message: string +): Promise => { + try { + await axios.post(webhookErrorUrl, { text: message }); + } catch (error) { + console.log(error); + throw error; + } +}; + +export const sendWebhookSignUpMessage = async ( + message: string +): Promise => { + try { + await axios.post(webhookSignUpUrl, { text: message }); + } catch (error) { + console.log(error); + throw error; + } +}; diff --git a/src/modules/slackWebhook.ts b/src/modules/slackWebhook.ts deleted file mode 100644 index 967ba20..0000000 --- a/src/modules/slackWebhook.ts +++ /dev/null @@ -1,12 +0,0 @@ -import axios from 'axios'; - -const webhook = process.env.WEBHOOK_URL as string; - -export const sendWebhookMessage = async (message: string): Promise => { - try { - await axios.post(webhook, { text: message }); - } catch (error) { - console.log(error); - throw error; - } -}; \ No newline at end of file diff --git a/src/service/userService.ts b/src/service/userService.ts index f935573..6ff54d6 100644 --- a/src/service/userService.ts +++ b/src/service/userService.ts @@ -1,7 +1,6 @@ import { PrismaClient } from "@prisma/client"; import { IntroDTO } from "../interfaces/user/IntroDTO"; import { UserDTO } from "../interfaces/user/UserDTO"; -import { UserDuplicateDTO } from "../interfaces/user/UserDuplicateDTO"; import { UserVersionDTO } from "../interfaces/user/UserVersionDTO"; const prisma = new PrismaClient(); From 91202201fa39f503311502e0f785ead7fd3bd79c Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Fri, 19 Jan 2024 18:57:50 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[CHORE]=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=EC=8B=9C=EA=B0=84=20=EA=B4=80=EB=A0=A8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/jwtHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/jwtHandler.ts b/src/modules/jwtHandler.ts index 4cde544..1b19e89 100644 --- a/src/modules/jwtHandler.ts +++ b/src/modules/jwtHandler.ts @@ -9,7 +9,7 @@ const sign = (userId: number) => { userId, //피카북 서버 userId }; - const accessToken = jwt.sign(payload, privateKey, { expiresIn: "30s" }); + const accessToken = jwt.sign(payload, privateKey, { expiresIn: "3d" }); return accessToken; };