diff --git a/src/controller/alarmController.ts b/src/controller/alarmController.ts index 8469eed..f0805b4 100644 --- a/src/controller/alarmController.ts +++ b/src/controller/alarmController.ts @@ -8,8 +8,9 @@ import { alarm, rm, sc } from "../constants"; import { fail, success } from "../constants/response"; import statusCode from "../constants/statusCode" -const setFinishedAlarm = async(req: Request, res: Response, next: NextFunction) => { - try{ + +const setFinishedAlarm = async (req: Request, res: Response, next: NextFunction) => { + try { const { templateId, userId } = req.body; const user = await userService.getUserById(userId); @@ -18,22 +19,22 @@ const setFinishedAlarm = async(req: Request, res: Response, next: NextFunction) const title = alarm.FINISHED_ALARM_TITLE; let msg = `${userName}님은 `; - if (templateId == 1){ + if (templateId == 1) { msg += alarm.FINISHED_ALARM_1 } - if (templateId == 2){ + if (templateId == 2) { msg += alarm.FINISHED_ALARM_2 } - if (templateId == 3){ + if (templateId == 3) { msg += alarm.FINISHED_ALARM_3 } - if (templateId == 4){ + if (templateId == 4) { msg += alarm.FINISHED_ALARM_4 } - if (templateId == 5){ + if (templateId == 5) { msg += alarm.FINISHED_ALARM_5 } - if (templateId == 6){ + if (templateId == 6) { msg += alarm.FINISHED_ALARM_6 } @@ -43,22 +44,22 @@ const setFinishedAlarm = async(req: Request, res: Response, next: NextFunction) "deviceToken": token } - pushAlarm(data,next); + pushAlarm(data, next); - }catch (error) { + } catch (error) { next(error); } } -const setOnDeadlineAlarm = async() => { - try{ +const setOnDeadlineAlarm = async () => { + try { const today = moment().format('YYYY-MM-DD'); const user = await alarmService.getUserListByDeadline(new Date(today)); - if(!user){ + if (!user) { return; } - for(var i =0;i { pushAlarmWithPayload(data); } - }catch (error) { + } catch (error) { console.log(error) } } - -const setBeforeDeadlineAlarm = async() => { - try{ - const deadline = moment().add(3,"days").format('YYYY-MM-DD'); +const setBeforeDeadlineAlarm = async () => { + try { + const deadline = moment().add(3, "days").format('YYYY-MM-DD'); const user = await alarmService.getUserListByDeadline(new Date(deadline)); - if(!user){ + if (!user) { return; } - for(var i =0;i { pushAlarmWithPayload(data); } - }catch (error) { + } catch (error) { console.log(error) } } -const setNoDeadlineAlarm = async() => { - try{ - const createdAt = moment().subtract(30,"days").format('YYYY-MM-DD'); - const user = await alarmService.getUserListWithNoDeadline(createdAt); - if(!user){ +const setNoDeadlineAlarm = async () => { + try { + const createdAt = moment().subtract(30, "days").format('YYYY-MM-DD'); + const user = await alarmService.getUserListWithNoDeadline(createdAt); + if (!user) { return; } - for(var i =0;i { pushAlarmWithPayload(data); } - }catch (error) { + } catch (error) { console.log(error) } } - const pushAlarm = (data: any, next: NextFunction) => { - try{ + try { const { deviceToken, title, contents } = data; let message = { @@ -136,24 +135,24 @@ const pushAlarm = (data: any, next: NextFunction) => { admin .messaging() .send(message) - .then(function (response:Response) { - console.log('Successfully sent message: : ', response) - // return res.status(200).json({success : true}) + .then(function (response: Response) { + console.log('Successfully sent message: : ', response) + // return res.status(200).json({success : true}) }) - .catch(function (err:Error) { + .catch(function (err: Error) { console.log('Error Sending message!!! : ', err) // return res.status(400).json({success : false}) }); } catch (error) { - next(error) + next(error) } } const pushAlarmWithPayload = (data: any) => { - try{ + try { const { payload, deviceToken, title, contents } = data; - + // data must only contain string values let message = { token: deviceToken, @@ -169,41 +168,40 @@ const pushAlarmWithPayload = (data: any) => { admin .messaging() .send(message) - .then(function (response:Response) { - console.log('Successfully sent message: : ', response) - // return res.status(200).json({success : true}) + .then(function (response: Response) { + console.log('Successfully sent message: : ', response) + // return res.status(200).json({success : true}) }) - .catch(function (err:Error) { + .catch(function (err: Error) { console.log('Error Sending message!!! : ', err) // return res.status(400).json({success : false}) }); } catch (error) { - console.log(error) + console.log(error) } } const pushAlarmToMany = async (data: any) => { - try{ + try { const { deviceTokens, title, contents } = data; - let message = { notification: { - title: title, - body: contents, + title: title, + body: contents, }, tokens: deviceTokens, }; await admin - .messaging() - .sendMulticast(message) - .then(function (response:Response) { - console.log('Successfully sent messages'); - // return res.status(200).json({success : true}) + .messaging() + .sendMulticast(message) + .then(function (response: Response) { + console.log('Successfully sent messages'); + // return res.status(200).json({success : true}) }) - .catch(function (err:Error) { + .catch(function (err: Error) { console.log('Error Sending message!!! : ', err) // return res.status(400).json({success : false}) }); @@ -220,33 +218,32 @@ const settingAlarm = async (req: Request, res: Response, next: NextFunction) => const data = await tokenService.getDeviceToken(userId) // 알람 비활성화 상태에서 알람 비활성화하려 할 때 - if(data == "" && +isTrue == 0){ + if (data == "" && +isTrue == 0) { return res.status(sc.OK).send(success(statusCode.OK, rm.ALARM_DISABLE_SUCCESS)) } // 알람 활성화 상태에서 알람 활성화하려 할 때 - if(data != "" && +isTrue == 1){ + if (data != "" && +isTrue == 1) { return res.status(sc.OK).send(success(statusCode.OK, rm.ALARM_ENABLE_SUCCESS)); } - if(+isTrue == 1){ + if (+isTrue == 1) { await tokenService.setDeviceToken(userId, deviceToken) return res.status(sc.OK).send(success(statusCode.OK, rm.ALARM_ENABLE_SUCCESS)); } - if(+isTrue == 0){ + if (+isTrue == 0) { await tokenService.disableDeviceToken(userId, deviceToken) return res.status(sc.OK).send(success(statusCode.OK, rm.ALARM_DISABLE_SUCCESS)); } - - + + } catch (error) { next(error); } } - -export default{ +export default { setFinishedAlarm, setOnDeadlineAlarm, setBeforeDeadlineAlarm, diff --git a/src/controller/authController.ts b/src/controller/authController.ts index 2d9b3b7..c2fca5a 100644 --- a/src/controller/authController.ts +++ b/src/controller/authController.ts @@ -7,205 +7,165 @@ import qs from "qs"; import authService from "../service/authService"; - // 서버에서 테스트용 카카오 토큰을 받기 위해 쓰일, 인가코드를 받기 위한 함수 const kakaoLogin_getAuthorizedCode = async (req: Request, res: Response, next: NextFunction) => { - try{ - //인가코드 받기 - const baseUrl = "https://kauth.kakao.com/oauth/authorize"; - const config = { - client_id: process.env.KAKAO_CLIENT_ID!, - redirect_uri: process.env.KAKAO_REDIRECT_URI!, - response_type: "code", - }; - const params = new URLSearchParams(config).toString(); - - const finalUrl = `${baseUrl}?${params}`; - return res.redirect(finalUrl); - - }catch (error) { - next(error); + try { + //인가코드 받기 + const baseUrl = "https://kauth.kakao.com/oauth/authorize"; + const config = { + client_id: process.env.KAKAO_CLIENT_ID!, + redirect_uri: process.env.KAKAO_REDIRECT_URI!, + response_type: "code", + }; + const params = new URLSearchParams(config).toString(); + + const finalUrl = `${baseUrl}?${params}`; + return res.redirect(finalUrl); + + } catch (error) { + next(error); + } + +}; + +// 서버에서 테스트용 카카오 토큰을 받기 위한 함수 +const kakaoLogin_getToken = async (req: Request, res: Response, next: NextFunction) => { + try { + + if (req.query.error) { + res.status(sc.BAD_REQUEST).send(fail(statusCode.BAD_REQUEST, rm.READ_KAKAO_TOKEN_FAIL)); } - - }; - - // 서버에서 테스트용 카카오 토큰을 받기 위한 함수 - const kakaoLogin_getToken = async (req: Request, res: Response, next: NextFunction) => { - try{ - - if(req.query.error){ - res.status(sc.BAD_REQUEST).send(fail(statusCode.BAD_REQUEST, rm.READ_KAKAO_TOKEN_FAIL)); - } - - //토큰 받기 - const response = await axios({ - method: 'POST', - url: 'https://kauth.kakao.com/oauth/token', - headers:{ - 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8' - }, - data:qs.stringify({//객체를 string 으로 변환 - grant_type: 'authorization_code', //해당 값으로 고정 - client_id:process.env.KAKAO_CLIENT_ID, - client_secret:process.env.KAKAO_SECRET_KEY, //보안 강화를 위함 (필수값은 아님) - redirectUri:process.env.KAKAO_REDIRECT_URI, - code:req.query.code, //kakaoLogin_getAuthorizeCode 를 통해 query string 으로 받은 인가 코드 - }) + + //토큰 받기 + const response = await axios({ + method: 'POST', + url: 'https://kauth.kakao.com/oauth/token', + headers: { + 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8' + }, + data: qs.stringify({//객체를 string 으로 변환 + grant_type: 'authorization_code', //해당 값으로 고정 + client_id: process.env.KAKAO_CLIENT_ID, + client_secret: process.env.KAKAO_SECRET_KEY, //보안 강화를 위함 (필수값은 아님) + redirectUri: process.env.KAKAO_REDIRECT_URI, + code: req.query.code, //kakaoLogin_getAuthorizeCode 를 통해 query string 으로 받은 인가 코드 }) - - return res.status(sc.OK).send(success(statusCode.OK, rm.READ_KAKAO_TOKEN_SUCCESS, response.data)); - - //발급받은 토큰을 사용해서 카카오 유저 정보 가져오기 - // const user = await kakaoLogin_getUserKakaoInfo(token); - // if(!user) - // return res.redirect('/kakao/login'); - - // return await serviceLogin(req,res,next,user); - - // // return res.status(sc.OK).send(success(statusCode.OK, rm.KAKAO_LOGIN_SUCCESS, response.data)); - - - } catch (error) { - next(error); - } + }) + + return res.status(sc.OK).send(success(statusCode.OK, rm.READ_KAKAO_TOKEN_SUCCESS, response.data)); + + } catch (error) { + next(error); } - - - const kakaoLogin =async (req: Request, res:Response, next:NextFunction) => { - try{ - const { accessToken, deviceToken } = req.body; - - // get user kakao info - const response = await axios({ - method: 'GET', - url: 'https://kapi.kakao.com/v2/user/me', - headers:{ - 'Authorization': `Bearer ${accessToken}`, - 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8' - }, - }) +} + +const kakaoLogin = async (req: Request, res: Response, next: NextFunction) => { + try { + const { accessToken, deviceToken } = req.body; + + // get user kakao info + const response = await axios({ + method: 'GET', + url: 'https://kapi.kakao.com/v2/user/me', + headers: { + 'Authorization': `Bearer ${accessToken}`, + 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8' + }, + }) + + const DTO = { + user: response.data, + deviceToken: deviceToken + } + + + const data = await authService.serviceLogin("kakao", DTO); + - const DTO = { - user: response.data, - deviceToken: deviceToken - } - - - const data = await authService.serviceLogin("kakao", DTO); - - - // 경우에 따라 다른 response message 출력 - // - 회원가입한 경우 - if(data.isNew){ - return res.status(sc.OK).send(success(sc.OK, rm.SIGNUP_SUCCESS, data.result)); - } - - // - 기존회원이 로그인한 경우 - return res.status(sc.OK).send(success(sc.OK, rm.LOGIN_SUCCESS, data.result)); - - }catch(error:any){ - console.log(error) - - //토큰이 유효하지 않은 경우 - if(error.response.data.msg == "this access token does not exist"){ - return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN)); - } - return res.status(error.response.status).send(fail(error.response.status, error.response.data.msg)); - + // 경우에 따라 다른 response message 출력 + // - 회원가입한 경우 + if (data.isNew) { + return res.status(sc.OK).send(success(sc.OK, rm.SIGNUP_SUCCESS, data.result)); } - - } - const appleLogin =async (req: Request, res:Response, next:NextFunction) => { - try { - const { identityToken, user, fullName, email, deviceToken } = req.body - const DTO = { - identityToken: identityToken, - id: user, - fullName: fullName, - email: email, - deviceToken: deviceToken - } - const data = await authService.serviceLogin("apple", DTO); - - - // - 회원가입한 경우 - if(data.isNew){ - return res.status(sc.OK).send(success(sc.OK, rm.SIGNUP_SUCCESS, data.result)); - } - - // - 기존회원이 로그인한 경우 - return res.status(sc.OK).send(success(sc.OK, rm.LOGIN_SUCCESS, data.result)); - - } catch (error) { - next(error) + // - 기존회원이 로그인한 경우 + return res.status(sc.OK).send(success(sc.OK, rm.LOGIN_SUCCESS, data.result)); + + } catch (error: any) { + console.log(error) + + //토큰이 유효하지 않은 경우 + if (error.response.data.msg == "this access token does not exist") { + return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN)); } + return res.status(error.response.status).send(fail(error.response.status, error.response.data.msg)); + } - const serviceLogout =async (req: Request, res:Response, next:NextFunction) => { - try{ - const { userId } = req.body; - await authService.serviceLogout(userId); - +} + +const appleLogin = async (req: Request, res: Response, next: NextFunction) => { + try { + const { identityToken, user, fullName, email, deviceToken } = req.body + const DTO = { + identityToken: identityToken, + id: user, + fullName: fullName, + email: email, + deviceToken: deviceToken + } + const data = await authService.serviceLogin("apple", DTO); - return res.status(sc.OK).send(success(sc.OK, rm.LOGOUT_SUCCESS)); - }catch(error){ - next(error); + // - 회원가입한 경우 + if (data.isNew) { + return res.status(sc.OK).send(success(sc.OK, rm.SIGNUP_SUCCESS, data.result)); } + + // - 기존회원이 로그인한 경우 + return res.status(sc.OK).send(success(sc.OK, rm.LOGIN_SUCCESS, data.result)); + + } catch (error) { + next(error) } +} - const serviceUnregister =async (req: Request, res:Response, next:NextFunction) => { - try{ - const { userId } = req.body; - if(userId == 11){ - return res.status(sc.BAD_REQUEST).send(success(sc.BAD_REQUEST, rm.DEV_USER_UNREGISTER_IMPOSSIBLE)); - } - await authService.serviceUnregister(userId); - +const serviceLogout = async (req: Request, res: Response, next: NextFunction) => { + try { + const { userId } = req.body; + await authService.serviceLogout(userId); - return res.status(sc.OK).send(success(sc.OK, rm.UNREGISTER_SUCCESS)); - }catch(error){ - next(error); + return res.status(sc.OK).send(success(sc.OK, rm.LOGOUT_SUCCESS)); + + } catch (error) { + next(error); + } +} + +const serviceUnregister = async (req: Request, res: Response, next: NextFunction) => { + try { + const { userId } = req.body; + if (userId == 11) { + return res.status(sc.BAD_REQUEST).send(success(sc.BAD_REQUEST, rm.DEV_USER_UNREGISTER_IMPOSSIBLE)); } + await authService.serviceUnregister(userId); + + + return res.status(sc.OK).send(success(sc.OK, rm.UNREGISTER_SUCCESS)); + + } catch (error) { + next(error); } +} - // const kakaoLogout =async (req: Request, res:Response, next:NextFunction) => { - // try{ - // const { accessToken } = req.body; - - // const response = await axios({ - // method: 'POST', - // url: 'https://kapi.kakao.com/v1/user/logout', - // headers:{ - // 'Authorization': `Bearer ${accessToken}`, - // } - // }) - - // return res.status(sc.OK).send(success(statusCode.OK, rm.KAKAO_LOGOUT_SUCCESS, response.data.msg)); - - // }catch(error:any){ - - // //토큰이 유효하지 않은 경우 - // if(error.response.data.msg == "this access token does not exist"){ - // return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN)); - // } - // console.log(error) - - // return res.status(error.response.status).send(fail(error.response.status, error.response.data.msg)); - - // } - - // } - -export default{ - kakaoLogin_getAuthorizedCode, - kakaoLogin_getToken, - kakaoLogin, - appleLogin, - serviceLogout, - serviceUnregister +export default { + kakaoLogin_getAuthorizedCode, + kakaoLogin_getToken, + kakaoLogin, + appleLogin, + serviceLogout, + serviceUnregister } \ No newline at end of file diff --git a/src/controller/index.ts b/src/controller/index.ts index 2bb7871..ac6b266 100644 --- a/src/controller/index.ts +++ b/src/controller/index.ts @@ -1,7 +1,9 @@ import userController from './userController'; import tokenController from './tokenController'; import authController from './authController'; -export{ + + +export { userController, tokenController, authController diff --git a/src/controller/reviewController.ts b/src/controller/reviewController.ts index 1355328..6ed27fb 100644 --- a/src/controller/reviewController.ts +++ b/src/controller/reviewController.ts @@ -5,13 +5,14 @@ import statusCode from "../constants/statusCode"; import { reviewDTO } from "../interfaces/DTO/reviewDTO" import reviewService from "../service/reviewService"; + const patchReview = async (req: Request, res: Response, next: NextFunction) => { try { const reviewDTO: reviewDTO = req.body; const data = await reviewService.patchReview(reviewDTO); - + let message; - if(data.isNew) + if (data.isNew) message = rm.CREATE_REVIEW_SUCCESS else message = rm.UPDATE_REVIEW_SUCCESS @@ -22,8 +23,9 @@ const patchReview = async (req: Request, res: Response, next: NextFunction) => { } catch (error) { next(error); } -}; +} + -export default{ +export default { patchReview } \ No newline at end of file diff --git a/src/controller/templateController.ts b/src/controller/templateController.ts index c3b5d27..a593f10 100644 --- a/src/controller/templateController.ts +++ b/src/controller/templateController.ts @@ -16,12 +16,12 @@ const getTemplateById = async (req: Request, res: Response, next: NextFunction) } catch (error) { next(error); } -}; +} -const getAllTemplate =async (req: Request, res: Response, next: NextFunction) => { +const getAllTemplate = async (req: Request, res: Response, next: NextFunction) => { try { - const {userId} = req.body; - + const { userId } = req.body; + const data = await templateService.getAllTemplate(userId); return res.status(sc.OK).send(success(statusCode.OK, rm.READ_ALL_TEMPLATES_SUCCESS, data)); @@ -31,7 +31,8 @@ const getAllTemplate =async (req: Request, res: Response, next: NextFunction) => } } -export default{ + +export default { getTemplateById, getAllTemplate, } \ No newline at end of file diff --git a/src/controller/tokenController.ts b/src/controller/tokenController.ts index 4ee7739..cb60db9 100644 --- a/src/controller/tokenController.ts +++ b/src/controller/tokenController.ts @@ -7,45 +7,44 @@ import tokenService from "../service/tokenService"; import jwt, { JwtPayload } from "jsonwebtoken"; - const refreshToken = async (req: Request, res: Response, next: NextFunction) => { - try{ - const { accessToken, refreshToken} = req.body; - const access_decoded = jwtHandler.accessVerify(accessToken); - const refresh_decoded = jwtHandler.refreshVerify(refreshToken); - const access_decoded_without_verification = jwt.decode(accessToken); - const userId: number = (access_decoded_without_verification as JwtPayload).userId - - - // 잘못된 accessToken or refreshToken 일 경우 - if ((access_decoded === tokenType.ACCESS_TOKEN_INVALID) || (refresh_decoded === tokenType.REFRESH_TOKEN_INVALID)) - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.INVALID_TOKEN)); - - // 기간이 만료된 경우 -> refreshToken을 이용하여 accessToken 재발급 - if (access_decoded === tokenType.ACCESS_TOKEN_EXPIRED){ - // refresh token도 만료된 경우 (access,refresh 모두 만료) - if (refresh_decoded === tokenType.REFRESH_TOKEN_EXPIRED) - return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.EXPIRED_ALL_TOKEN)); - - const new_access_token = await tokenService.refreshAccessToken(userId, refreshToken); - return res.status(sc.OK).send(success(statusCode.OK, rm.REFRESH_TOKEN_SUCCESS, new_access_token)); - - } - - // 기간이 만료되지 않은 경우 -> 기존 accessToken 다시 반환 - const data = { - "accessToken": accessToken - } - - return res.status(sc.OK).send(success(statusCode.OK, "유효한 토큰입니다. 재발급이 불필요합니다.",data)); - - }catch(error){ - next(error) + try { + const { accessToken, refreshToken } = req.body; + const access_decoded = jwtHandler.accessVerify(accessToken); + const refresh_decoded = jwtHandler.refreshVerify(refreshToken); + const access_decoded_without_verification = jwt.decode(accessToken); + const userId: number = (access_decoded_without_verification as JwtPayload).userId + + + // 잘못된 accessToken or refreshToken 일 경우 + if ((access_decoded === tokenType.ACCESS_TOKEN_INVALID) || (refresh_decoded === tokenType.REFRESH_TOKEN_INVALID)) + return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.INVALID_TOKEN)); + + // 기간이 만료된 경우 -> refreshToken을 이용하여 accessToken 재발급 + if (access_decoded === tokenType.ACCESS_TOKEN_EXPIRED) { + // refresh token도 만료된 경우 (access,refresh 모두 만료) + if (refresh_decoded === tokenType.REFRESH_TOKEN_EXPIRED) + return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.EXPIRED_ALL_TOKEN)); + + const new_access_token = await tokenService.refreshAccessToken(userId, refreshToken); + return res.status(sc.OK).send(success(statusCode.OK, rm.REFRESH_TOKEN_SUCCESS, new_access_token)); + } - + + // 기간이 만료되지 않은 경우 -> 기존 accessToken 다시 반환 + const data = { + "accessToken": accessToken + } + + return res.status(sc.OK).send(success(statusCode.OK, "유효한 토큰입니다. 재발급이 불필요합니다.", data)); + + } catch (error) { + next(error) } +} + - export default{ - refreshToken +export default { + refreshToken } diff --git a/src/controller/userController.ts b/src/controller/userController.ts index 1c55b9d..07e065b 100644 --- a/src/controller/userController.ts +++ b/src/controller/userController.ts @@ -1,28 +1,24 @@ import { NextFunction, Request, Response } from "express"; import { fail, success } from "../constants/response"; -import { rm, sc, tokenType } from "../constants"; +import { rm, sc } from "../constants"; import { userService } from "../service"; import statusCode from "../constants/statusCode"; -const getUserById = async (req: Request, res: Response, next: NextFunction) => { - try { - const { userId } = req.params; - // if (!userId) { - // throw new ClientException("필요한 Param 값이 없습니다."); - // } - const foundUser = await userService.getUserById(+userId); +const getUserById = async (req: Request, res: Response, next: NextFunction) => { + try { + const { userId } = req.params; - return res.status(sc.OK).send(success(statusCode.OK, rm.READ_USER_SUCCESS, foundUser)); + const foundUser = await userService.getUserById(+userId); + return res.status(sc.OK).send(success(statusCode.OK, rm.READ_USER_SUCCESS, foundUser)); - } catch (error) { - next(error); - } + } catch (error) { + next(error); + } }; - -export default{ +export default { getUserById, } \ No newline at end of file diff --git a/src/controller/worryController.ts b/src/controller/worryController.ts index ab0021e..fbb03c9 100644 --- a/src/controller/worryController.ts +++ b/src/controller/worryController.ts @@ -1,5 +1,5 @@ import { NextFunction, Request, Response } from "express"; -import { rm , sc} from "../constants"; +import { rm, sc } from "../constants"; import { success } from "../constants/response"; import statusCode from "../constants/statusCode"; import worryService from "../service/worryService"; @@ -7,11 +7,10 @@ import { finalAnswerCreateDTO, worryCreateDTO, worryUpdateDTO, deadlineUpdateDTO import { ClientException } from "../common/error/exceptions/customExceptions"; - const postWorry = async (req: Request, res: Response, next: NextFunction) => { try { - const worryCreateDTO: worryCreateDTO = req.body; + const worryCreateDTO: worryCreateDTO = req.body; // console.log(worryCreateDTO) const data = await worryService.postWorry(worryCreateDTO); @@ -38,9 +37,9 @@ const patchWorry = async (req: Request, res: Response, next: NextFunction) => { const deleteWorry = async (req: Request, res: Response, next: NextFunction) => { try { const { worryId } = req.params; - const { userId }= req.body; + const { userId } = req.body; - await worryService.deleteWorry(+worryId,userId); + await worryService.deleteWorry(+worryId, userId); return res.status(sc.OK).send(success(statusCode.OK, rm.DELETE_WORRY_SUCCESS)); @@ -52,11 +51,11 @@ const deleteWorry = async (req: Request, res: Response, next: NextFunction) => { const getWorryDetail = async (req: Request, res: Response, next: NextFunction) => { try { const { worryId } = req.params; - const { userId }= req.body; + const { userId } = req.body; - const data = await worryService.getWorryDetail(+worryId,userId); + const data = await worryService.getWorryDetail(+worryId, userId); - return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_DETAIL_SUCCESS,data)); + return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_DETAIL_SUCCESS, data)); } catch (error) { next(error); @@ -72,8 +71,8 @@ const patchFinalAnswer = async (req: Request, res: Response, next: NextFunction) req.body.templateId = data.alarm_data.templateId; next(); - - return res.status(sc.OK).send(success(statusCode.OK, rm.MAKE_FINAL_ANSWER_SUCCESS,data.quote_data)); + + return res.status(sc.OK).send(success(statusCode.OK, rm.MAKE_FINAL_ANSWER_SUCCESS, data.quote_data)); } catch (error) { next(error); @@ -84,10 +83,8 @@ const patchDeadline = async (req: Request, res: Response, next: NextFunction) => try { const deadlineUpdateDTO: deadlineUpdateDTO = req.body; - const data = await worryService.patchDeadline(deadlineUpdateDTO); - - return res.status(sc.OK).send(success(statusCode.OK, rm.UPDATE_DEADLINE_SUCCESS,data)); + return res.status(sc.OK).send(success(statusCode.OK, rm.UPDATE_DEADLINE_SUCCESS, data)); } catch (error) { next(error); @@ -98,11 +95,11 @@ const getWorryList = async (req: Request, res: Response, next: NextFunction) => try { const { isSolved } = req.params; const { page, limit } = req.query; - const { userId }= req.body; + const { userId } = req.body; const data = await worryService.getWorryList(+isSolved, +page!, +limit!, userId); - return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_LIST_SUCCESS,data)); + return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_LIST_SUCCESS, data)); } catch (error) { next(error); @@ -112,12 +109,12 @@ const getWorryList = async (req: Request, res: Response, next: NextFunction) => const getWorryListByTemplate = async (req: Request, res: Response, next: NextFunction) => { try { const { templateId } = req.query; - if(!templateId) + if (!templateId) throw new ClientException("templateId 값이 존재하지 않습니다."); - const { userId }= req.body; - const data = await worryService.getWorryListByTemplate(+templateId,userId); + const { userId } = req.body; + const data = await worryService.getWorryListByTemplate(+templateId, userId); - return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_LIST_BY_TEMPLATE_SUCCESS,data)); + return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_LIST_BY_TEMPLATE_SUCCESS, data)); } catch (error) { next(error); @@ -125,7 +122,7 @@ const getWorryListByTemplate = async (req: Request, res: Response, next: NextFun }; -export default{ +export default { postWorry, patchWorry, deleteWorry, diff --git a/src/interfaces/DAO/worryDAO.ts b/src/interfaces/DAO/worryDAO.ts index 3572c4b..4f108d8 100644 --- a/src/interfaces/DAO/worryDAO.ts +++ b/src/interfaces/DAO/worryDAO.ts @@ -6,7 +6,6 @@ interface worryCreateDAO extends worryCreateDTO{ updatedAt: Date; } - interface deadlineUpdateDAO{ worryId: number; deadline: Date | null; diff --git a/src/interfaces/DTO/reviewDTO.ts b/src/interfaces/DTO/reviewDTO.ts index 4a922c5..bf80b7a 100644 --- a/src/interfaces/DTO/reviewDTO.ts +++ b/src/interfaces/DTO/reviewDTO.ts @@ -1,4 +1,4 @@ -import { IsDefined, IsNumber, IsString, isString } from "class-validator"; +import { IsDefined, IsNumber, IsString } from "class-validator"; class reviewDTO { @IsDefined() diff --git a/src/interfaces/DTO/worryDTO.ts b/src/interfaces/DTO/worryDTO.ts index e9db922..be7fb72 100644 --- a/src/interfaces/DTO/worryDTO.ts +++ b/src/interfaces/DTO/worryDTO.ts @@ -1,4 +1,4 @@ -import { IsString, IsDefined, IsNumber, IsArray, IsNotEmpty, isNumber, ArrayNotEmpty} from 'class-validator'; +import { IsString, IsDefined, IsNumber, IsArray, ArrayNotEmpty } from 'class-validator'; class worryCreateDTO { @@ -24,7 +24,7 @@ class worryCreateDTO { deadline!: number; } -class worryUpdateDTO{ +class worryUpdateDTO { @IsDefined() @IsNumber() worryId!: number; @@ -46,7 +46,7 @@ class worryUpdateDTO{ answers!: Array; } -class finalAnswerCreateDTO{ +class finalAnswerCreateDTO { @IsDefined() @IsNumber() worryId!: number; @@ -60,7 +60,7 @@ class finalAnswerCreateDTO{ finalAnswer!: string; } -class deadlineUpdateDTO{ +class deadlineUpdateDTO { @IsDefined() @IsNumber() worryId!: number; @@ -74,6 +74,7 @@ class deadlineUpdateDTO{ dayCount!: number; } + export { worryCreateDTO, worryUpdateDTO,