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 };