Skip to content

Commit

Permalink
알람 삭제 API
Browse files Browse the repository at this point in the history
  • Loading branch information
wook-hyung committed Dec 16, 2023
1 parent a7f2bc1 commit 7de9b9c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
6 changes: 4 additions & 2 deletions controllers/alarmController.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ const alarmController = {
}
},
approveAlarm: async (req, res) => {
const { challengeCertificationId } = req.body;
const { alarmId, challengeCertificationId } = req.body;

try {
await alarmService.approveChallengeCertification({
alarmId,
challengeCertificationId,
});

Expand All @@ -67,10 +68,11 @@ const alarmController = {
}
},
rejectAlarm: async (req, res) => {
const { challengeCertificationId } = req.body;
const { alarmId, challengeCertificationId } = req.body;

try {
await alarmService.rejectChallengeCertification({
alarmId,
challengeCertificationId,
});

Expand Down
20 changes: 17 additions & 3 deletions models/alarmModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const alarmModel = {
const connection = await pool.getConnection();

try {
const [rows, fields] = await connection.query('SELECT * FROM alarm WHERE member_id = ? ORDER BY id DESC', [
memberId,
]);
const [rows, fields] = await connection.query(
'SELECT alarm.id, alarm.member_id, alarm.challenge_certification_id, alarm.alarm_type, alarm.is_read, challenge_certification.challenge_id, challenge.name FROM alarm JOIN challenge_certification ON alarm.challenge_certification_id = challenge_certification.id JOIN challenge ON challenge_certification.challenge_id = challenge.id WHERE alarm.member_id = ? AND alarm.is_active = 1 ORDER BY alarm.id DESC',
[memberId]
);

return rows;
} finally {
connection.release();
Expand Down Expand Up @@ -86,6 +88,18 @@ const alarmModel = {
connection.release();
}
},

deleteAlarm: async ({ alarmId }) => {
const connection = await pool.getConnection();

try {
const [rows, fields] = await connection.query('UPDATE alarm SET is_active = 0 WHERE id = ?', [alarmId]);

return rows;
} finally {
connection.release();
}
},
};

module.exports = {
Expand Down
21 changes: 17 additions & 4 deletions routes/alarmRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,18 @@ router.get('/new', alarmController.getNewAlarmExist);
* schema:
* type: object
* properties:
* alarmId:
* type: integer
* description: "알람의 ID"
* example: 123
* challengeCertificationId:
* type: integer
* description: "인증 요청 알람의 challengeCertificationId"
* example: 456
* required:
* - alarmId
* - challengeCertificationId
* description: "인증 요청 알람의 challengeCertificationId"
* description: "알람 및 인증 요청에 필요한 정보"
* responses:
* "200":
* description: "상대방 인증 요청 알람 승인 요청에 성공했습니다."
Expand All @@ -103,7 +110,6 @@ router.get('/new', alarmController.getNewAlarmExist);
* message:
* type: string
*/

router.post('/approve', alarmController.approveAlarm);

/**
Expand All @@ -127,14 +133,21 @@ router.post('/approve', alarmController.approveAlarm);
* schema:
* type: object
* properties:
* alarmId:
* type: integer
* description: "알람의 ID"
* example: 123
* challengeCertificationId:
* type: integer
* description: "인증 요청 알람의 challengeCertificationId"
* example: 456
* required:
* - alarmId
* - challengeCertificationId
* description: "인증 요청 알람의 challengeCertificationId"
* description: "알람 및 인증 요청에 필요한 정보"
* responses:
* "200":
* description: "상대방 인증 요청 알람 승인 거절에 성공했습니다."
* description: "상대방 인증 요청 알람 거절에 성공했습니다."
* content:
* application/json:
* schema:
Expand Down
8 changes: 6 additions & 2 deletions services/alarmService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ const alarmService = {
return result;
},

approveChallengeCertification: async ({ challengeCertificationId }) => {
approveChallengeCertification: async ({ alarmId, challengeCertificationId }) => {
const result = await challengeCertificationModel.approveChallengeCertification({
challengeCertificationId,
});

await alarmModel.deleteAlarm({ alarmId });

const [{ member_id: memberId }] = await challengeCertificationModel.findMemberIdByChallengeCertificationId({
challengeCertificationId,
});
Expand All @@ -44,11 +46,13 @@ const alarmService = {
return result;
},

rejectChallengeCertification: async ({ challengeCertificationId }) => {
rejectChallengeCertification: async ({ alarmId, challengeCertificationId }) => {
const result = await challengeCertificationModel.rejectChallengeCertification({
challengeCertificationId,
});

await alarmModel.deleteAlarm({ alarmId });

const [{ member_id: memberId }] = await challengeCertificationModel.findMemberIdByChallengeCertificationId({
challengeCertificationId,
});
Expand Down

0 comments on commit 7de9b9c

Please sign in to comment.