From bff6880f73dbe2f8932bf3bb750ae66f3c261e0d Mon Sep 17 00:00:00 2001 From: dragontaek-lee Date: Sun, 18 Jun 2023 23:27:49 +0900 Subject: [PATCH] fix: request in register alarm #89 --- src/constants/responseMessage.ts | 1 + src/controller/alarmController.ts | 6 +++++- src/middlewares/auth.ts | 9 ++++++++- src/router/alarmRouter.ts | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/constants/responseMessage.ts b/src/constants/responseMessage.ts index 948e77b..e3566b8 100644 --- a/src/constants/responseMessage.ts +++ b/src/constants/responseMessage.ts @@ -98,5 +98,6 @@ export default { //alarm PUSH_NOTIFICATION_SUCCESS: "알람 전송 성공", PUSH_NOTIFICATION_FALED: "알람 전송 실패", + PUSH_NOTIFICATION_REGISTER_SUCCESS: "유저 구독 성공", PUSH_NOTIFICATION_REGISTER_FALED: "유저 구독 실패", }; diff --git a/src/controller/alarmController.ts b/src/controller/alarmController.ts index e820e8e..1c7194f 100644 --- a/src/controller/alarmController.ts +++ b/src/controller/alarmController.ts @@ -42,12 +42,16 @@ const register = async (req: Request, res: Response, next: NextFunction) => { return next(new PicmeException(sc.BAD_REQUEST, false, rm.BAD_REQUEST)); } + const userId = req.body.userId; + + if (!userId) return next(new PicmeException(sc.UNAUTHORIZED, false, rm.INVALID_TOKEN)); + const alarmRegisterDTO: AlarmRegisterDTO = req.body; try { await alarmService.register(alarmRegisterDTO); - return res.status(sc.OK).send(success(sc.OK, rm.PUSH_NOTIFICATION_SUCCESS)); + return res.status(sc.OK).send(success(sc.OK, rm.PUSH_NOTIFICATION_REGISTER_SUCCESS)); } catch (e) { return next(e); } diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index 9475569..cffefce 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -5,7 +5,14 @@ import { fail } from "../constants/response"; import tokenType from "../constants/tokenType"; import jwtHandler from "../modules/jwtHandler"; -const skipAuthPath = ["/sticker", "/auth", "/user/name", "/user/email", "/vote/common", "/alarm"]; +const skipAuthPath = [ + "/sticker", + "/auth", + "/user/name", + "/user/email", + "/vote/common", + "/alarm/push", +]; const uploadPath = "/vote"; export default async (req: Request, res: Response, next: NextFunction) => { diff --git a/src/router/alarmRouter.ts b/src/router/alarmRouter.ts index f30cebc..6ada14b 100644 --- a/src/router/alarmRouter.ts +++ b/src/router/alarmRouter.ts @@ -14,7 +14,7 @@ router.post( //register notification router.post( "/register", - [body("userId").notEmpty(), body("endpoint").notEmpty(), body("keys").notEmpty()], + [body("endpoint").notEmpty(), body("expirationTime"), body("keys").notEmpty()], alarmController.register );