From 0094d444eb70d19e659e2ec45cc64893be7d14b9 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Fri, 17 Jan 2025 16:20:57 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EC=98=88=EC=95=BD=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=B0=9C=EC=86=A1=20=EC=84=B1=EA=B3=B5=20=EC=8B=9C?= =?UTF-8?q?,=20=EC=96=B4=EB=93=9C=EB=AF=BC=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EB=8C=80=EC=83=81=20=EC=83=81=ED=83=9C=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=9B=B9=ED=9B=85=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 예약 알림 처리 요청(EventBridge 발 요청)에 대해 알림 발송 이후 "발송 완료" 상태로 업데이트 시키기 위한 웹훅 기능 - EventBridge 요청 Json 내 Header로부터 alarmId를 받아올 수 있도록 했습니다. --- src/lambda.ts | 4 +++- src/services/webHookService.ts | 33 ++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/lambda.ts b/src/lambda.ts index b3a789f..355122b 100644 --- a/src/lambda.ts +++ b/src/lambda.ts @@ -250,7 +250,7 @@ const eventBridgeHandler = async (event: EventBridgeEvent) => { return response(400, status.success(statusCode.BAD_REQUEST, responseMessage.INVALID_REQUEST)); } - const { action, transactionId, service } = header; + const { action, transactionId, service, alarmId } = header; try { switch (action) { @@ -266,6 +266,7 @@ const eventBridgeHandler = async (event: EventBridgeEvent) => { } await sendPush(dto); + await webHookService.scheduleSuccessWebHook(alarmId); return response(200, status.success(statusCode.OK, responseMessage.SEND_SUCCESS)); } case Actions.SEND_ALL: { @@ -280,6 +281,7 @@ const eventBridgeHandler = async (event: EventBridgeEvent) => { } await sendPushAll(dto); + await webHookService.scheduleSuccessWebHook(alarmId); return response(200, status.success(statusCode.OK, responseMessage.SEND_SUCCESS)); } default: { diff --git a/src/services/webHookService.ts b/src/services/webHookService.ts index 6fcd741..cbb756c 100644 --- a/src/services/webHookService.ts +++ b/src/services/webHookService.ts @@ -1,5 +1,6 @@ import { PushSuccessMessageDTO, Services, Category, WebHookType } from '../types'; import axios from 'axios'; +import dayjs from 'dayjs'; interface AppSuccessWebHookDTO { id: string; @@ -11,15 +12,8 @@ interface AppSuccessWebHookDTO { webLink?: string; userIds?: string[]; } - -interface OperationSuccessWebHookDTO { - id: string; - title: string; - content: string; - category: Category; - deepLink?: string; - webLink?: string; - userIds?: string[]; +interface OperationScheduleSuccessWebHookDTO { + sendAt: string; } const axiosInstance = axios.create({ @@ -38,13 +32,13 @@ async function appWebHook(appSuccessWebHookDTO: AppSuccessWebHookDTO): Promise { +async function operationScheduleSuccessWebHook(alarmId: number, dto: OperationScheduleSuccessWebHookDTO): Promise { try { if (process.env.MAKERS_OPERATION_SERVER_URL === undefined) { throw new Error('env not defined'); } - - await axiosInstance.post(process.env.MAKERS_OPERATION_SERVER_URL, JSON.stringify(operationSuccessWebHookDTO)); + const statusUpdateEndpoint = process.env.MAKERS_OPERATION_SERVER_URL + alarmId; + await axiosInstance.patch(statusUpdateEndpoint, JSON.stringify(dto)); } catch (e) { throw new Error('OPERATION SERVER webhook failed'); } @@ -80,4 +74,17 @@ const pushSuccessWebHook = async (dto: PushSuccessMessageDTO): Promise => } }; -export default { pushSuccessWebHook }; +const scheduleSuccessWebHook = async (alarmId: number): Promise => { + if (alarmId === undefined) { + throw new Error('schedule alarm id not defined'); + } + + const sendAt = dayjs().format('YYYY-MM-DD hh:mm'); + const updateStatusWebHookDTO: OperationScheduleSuccessWebHookDTO = { + sendAt + }; + + await operationScheduleSuccessWebHook(alarmId, updateStatusWebHookDTO); +} + +export default { pushSuccessWebHook, scheduleSuccessWebHook };