Skip to content

Commit

Permalink
[MERGE] feat/#30 -> develop
Browse files Browse the repository at this point in the history
[FEAT] 예약 알림 발송 성공 시, 어드민 서버 대상 상태 업데이트 웹훅 기능 구현
  • Loading branch information
yummygyudon authored Jan 18, 2025
2 parents 2506dcd + 0094d44 commit a757807
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const eventBridgeHandler = async (event: EventBridgeEvent<string, any>) => {
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) {
Expand All @@ -266,6 +266,7 @@ const eventBridgeHandler = async (event: EventBridgeEvent<string, any>) => {
}

await sendPush(dto);
await webHookService.scheduleSuccessWebHook(alarmId);
return response(200, status.success(statusCode.OK, responseMessage.SEND_SUCCESS));
}
case Actions.SEND_ALL: {
Expand All @@ -280,6 +281,7 @@ const eventBridgeHandler = async (event: EventBridgeEvent<string, any>) => {
}

await sendPushAll(dto);
await webHookService.scheduleSuccessWebHook(alarmId);
return response(200, status.success(statusCode.OK, responseMessage.SEND_SUCCESS));
}
default: {
Expand Down
33 changes: 20 additions & 13 deletions src/services/webHookService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PushSuccessMessageDTO, Services, Category, WebHookType } from '../types';
import axios from 'axios';
import dayjs from 'dayjs';

interface AppSuccessWebHookDTO {
id: string;
Expand All @@ -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({
Expand All @@ -38,13 +32,13 @@ async function appWebHook(appSuccessWebHookDTO: AppSuccessWebHookDTO): Promise<v
}
}

async function operationWebHook(operationSuccessWebHookDTO: OperationSuccessWebHookDTO): Promise<void> {
async function operationScheduleSuccessWebHook(alarmId: number, dto: OperationScheduleSuccessWebHookDTO): Promise<void> {
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');
}
Expand Down Expand Up @@ -80,4 +74,17 @@ const pushSuccessWebHook = async (dto: PushSuccessMessageDTO): Promise<void> =>
}
};

export default { pushSuccessWebHook };
const scheduleSuccessWebHook = async (alarmId: number): Promise<void> => {
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 };

0 comments on commit a757807

Please sign in to comment.