Skip to content

Commit

Permalink
findOtherMemberByChallengeId
Browse files Browse the repository at this point in the history
  • Loading branch information
wook-hyung committed Dec 16, 2023
1 parent 39dbf2d commit 993ef96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions controllers/challengeController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { challengeService } = require('../services/challengeService');
const { challengeCertificationModel } = require('../models/challengeCertificationModel');
const { challengeModel } = require('../models/challengeModel');
const { alarmService } = require('../services/alarmService');
const { getUserIdFromJwt } = require('../utils/jwt');
const { getUserChampionFromJwt } = require('../utils/jwt');
Expand Down Expand Up @@ -163,10 +164,10 @@ const challengeController = {
participationCount: participationCount + 1,
});

const [{ member_id: memberIdForAlarm }] =
await challengeCertificationModel.findMemberIdByChallengeCertificationId({
challengeCertificationId: submitResult.data.insertId,
});
const [{ member_id: memberIdForAlarm }] = await challengeModel.findOtherMemberByChallengeId({
memberId,
challengeId,
});

// TODO: 새로운 인증 요청 알람을 상대방에게 전송한다.
await alarmService.createCertificationAlarm({
Expand Down
15 changes: 15 additions & 0 deletions models/challengeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ const challengeModel = {
connection.release();
}
},

findOtherMemberByChallengeId: async ({ memberId, challengeId }) => {
const connection = await pool.getConnection();

try {
const [rows, fields] = await connection.query(
'SELECT * FROM member WHERE id IN (SELECT member_id FROM challenge_participant WHERE challenge_id = ? AND member_id != ?)',
[challengeId, memberId]
);

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

module.exports = {
Expand Down

0 comments on commit 993ef96

Please sign in to comment.