-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93405c2
commit d2b8e8e
Showing
5 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { alarmService } = require('../services/alarmService'); | ||
const { getUserIdFromJwt } = require('../utils/jwt'); | ||
|
||
const alarmController = { | ||
getAlarms: async (req, res) => { | ||
// 유저의 알람 전체 조회 및 읽음 상태 모두 업데이트 | ||
try { | ||
const result = await alarmService.getAlarms({ | ||
memberId: getUserIdFromJwt(req.headers.authorization), | ||
}); | ||
|
||
return res.status(200).json({ | ||
success: true, | ||
message: '알람 조회에 성공했습니다.', | ||
data: { | ||
alarms: result, | ||
}, | ||
}); | ||
} catch (err) { | ||
return res.status(400).json({ | ||
success: false, | ||
message: '알람 조회에 실패했습니다.', | ||
err: err.message, | ||
}); | ||
} | ||
}, | ||
|
||
getNewAlarmExist: async (req, res) => { | ||
try { | ||
const result = await alarmService.getNewAlarmExist({ | ||
memberId: getUserIdFromJwt(req.headers.authorization), | ||
}); | ||
|
||
return res.status(200).json({ | ||
success: true, | ||
message: '새로운 알람 존재 여부 조회에 성공했습니다.', | ||
data: { | ||
isNewAlarmExist: result, | ||
}, | ||
}); | ||
} catch (err) { | ||
return res.status(400).json({ | ||
success: false, | ||
message: '새로운 알람 존재 여부 조회에 실패했습니다.', | ||
err: err.message, | ||
}); | ||
} | ||
}, | ||
approveAlarm: async (req, res) => { | ||
// 상대방의 인증 요청 알람을 승인 | ||
}, | ||
rejectAlarm: async (req, res) => { | ||
// 상대방의 인증 요청 알람을 거절 | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
alarmController, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { pool } = require('./pool'); | ||
|
||
const alarmModel = { | ||
getAlarms: async ({ memberId }) => { | ||
const connection = await pool.getConnection(); | ||
|
||
const [rows, fields] = await connection.query('SELECT * FROM alarm WHERE member_id = ? ORDER BY id DESC', [ | ||
memberId, | ||
]); | ||
return rows; | ||
}, | ||
|
||
updateAlarmStatus: async ({ memberId }) => { | ||
const connection = await pool.getConnection(); | ||
|
||
const [rows, fields] = await connection.query('UPDATE alarm SET is_read = 1 WHERE member_id = ? AND is_read = 0', [ | ||
memberId, | ||
]); | ||
return rows; | ||
}, | ||
|
||
findNewAlarmExist: async ({ memberId }) => { | ||
const connection = await pool.getConnection(); | ||
|
||
const [rows, fields] = await connection.query('SELECT * FROM alarm WHERE member_id = ? AND is_read = 0', [ | ||
memberId, | ||
]); | ||
|
||
return rows.length > 0; | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
alarmModel, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const express = require('express'); | ||
|
||
const router = express.Router(); | ||
|
||
const { alarmController } = require('../controllers/alarmController'); | ||
|
||
/** | ||
* @swagger | ||
* paths: | ||
* /alarms: | ||
* get: | ||
* tags: [Alarms] | ||
* summary: "유저의 알람 전체 조회" | ||
* description: "유저의 알람 전체 조회 및 읽음 상태 모두 업데이트" | ||
* parameters: | ||
* - name: "Authorization" | ||
* in: "header" | ||
* description: "Access Token" | ||
* required: true | ||
* schema: | ||
* type: "string" | ||
* responses: | ||
* "200": | ||
* description: "유저의 알람 전체 조회 요청에 성공했습니다." | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* success: | ||
* type: boolean | ||
* message: | ||
* type: string | ||
*/ | ||
router.get('/', alarmController.getAlarms); | ||
|
||
/** | ||
* @swagger | ||
* paths: | ||
* /alarms/new: | ||
* get: | ||
* tags: [Alarms] | ||
* summary: "새로운 알람 존재 여부 조회" | ||
* description: "새로운 알람 존재 여부 조회" | ||
* parameters: | ||
* - name: "Authorization" | ||
* in: "header" | ||
* description: "Access Token" | ||
* required: true | ||
* schema: | ||
* type: "string" | ||
* responses: | ||
* "200": | ||
* description: "새로운 알람 존재 여부 조회 요청에 성공했습니다." | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* success: | ||
* type: boolean | ||
* message: | ||
* type: string | ||
*/ | ||
router.get('/new', alarmController.getNewAlarmExist); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { alarmModel } = require('../models/alarmModel'); | ||
const { challengeCertificationModel } = require('../models/challengeCertificationModel'); | ||
|
||
const alarmService = { | ||
getAlarms: async ({ memberId }) => { | ||
// 유저의 알람 전체 조회 및 읽음 상태 모두 업데이트 | ||
const alarms = await alarmModel.getAlarms({ memberId }); | ||
await alarmModel.updateAlarmStatus({ memberId }); | ||
|
||
const result = Promise.all( | ||
alarms.map(async (alarm) => { | ||
const [{ authenticate_image_url }] = | ||
await challengeCertificationModel.findAuthenticateImageUrlByChallengeCertificationId({ | ||
challengeCertificationId: alarm.challenge_certification_id, | ||
}); | ||
|
||
return { | ||
...alarm, | ||
authenticateImageUrl: authenticate_image_url, | ||
}; | ||
}) | ||
); | ||
|
||
return result; | ||
}, | ||
|
||
getNewAlarmExist: async ({ memberId }) => { | ||
const result = await alarmModel.findNewAlarmExist({ memberId }); | ||
|
||
return result; | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
alarmService, | ||
}; |