Skip to content

Commit

Permalink
챌린지 인증 요청 api 수정, 인증알람가는 코드는 추가필요
Browse files Browse the repository at this point in the history
  • Loading branch information
bhh9860 committed Dec 16, 2023
1 parent 807b9ee commit 6ce1c7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion controllers/challengeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const challengeController = {
// 챌린지 인증 테이블 인설트 하기 전,
// 제일 최근 인증이 수락되지 않은 인증(Null)인가?
const findNullApproved = await challengeService.findNullApproved({ memberId, challengeId });
console.log('find', findNullApproved);

const [{ is_authenticate: isAuthenticate, participation_count: participationCount }] = findNullApproved.data;

Expand Down Expand Up @@ -151,8 +152,9 @@ const challengeController = {
}
}

if (isAuthenticate === 1) {
if (isAuthenticate === 1 || isAuthenticate === undefined) {
// 3. 제일 최근 인증이 승인된 인증이면?
// 4. 제일 최근 인증이 없어도 이 이프문에 해당(첫 인증). 카운트는 0로 들어가기 때문에 1로 설정된다.
const submitResult = await challengeService.createChallengeCertification({
memberId,
challengeId,
Expand Down
9 changes: 8 additions & 1 deletion models/challengeCertificationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ const challengeCertificationModel = {
const connection = await pool.getConnection();

try {
const [rows, fields] = await connection.query(
let [rows, fields] = await connection.query(
// 제일 최근의 인증이 NULL이면 true, 아니면 false
`SELECT is_authenticate, participation_count FROM challenge_certification WHERE member_id = ${memberId} AND challenge_id = ${challengeId} ORDER BY id DESC LIMIT 1;`
);

// 제일 최근 인증이 없으면?(인증시도을 한 번도 안 했으면?)
if (rows.length === 0) {
rows = [{ is_authenticate: undefined, participation_count: 0 }];
console.log('result2', rows);
return rows;
}

return rows;
} finally {
connection.release();
Expand Down
1 change: 1 addition & 0 deletions services/challengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const challengeService = {
memberId,
challengeId,
});
console.log('result', result);

return {
success: true,
Expand Down

0 comments on commit 6ce1c7f

Please sign in to comment.