From 6ce1c7f5a5d6438a0f03a1b0efa029de00f65f1f Mon Sep 17 00:00:00 2001 From: bhh9860 Date: Sun, 17 Dec 2023 01:43:35 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EC=9A=94=EC=B2=AD=20api=20=EC=88=98=EC=A0=95,=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=EC=95=8C=EB=9E=8C=EA=B0=80=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=8A=94=20=EC=B6=94=EA=B0=80=ED=95=84?= =?UTF-8?q?=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/challengeController.js | 4 +++- models/challengeCertificationModel.js | 9 ++++++++- services/challengeService.js | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/controllers/challengeController.js b/controllers/challengeController.js index 1060d97..025b6d8 100644 --- a/controllers/challengeController.js +++ b/controllers/challengeController.js @@ -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; @@ -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, diff --git a/models/challengeCertificationModel.js b/models/challengeCertificationModel.js index da9c8d6..f7d5d9a 100644 --- a/models/challengeCertificationModel.js +++ b/models/challengeCertificationModel.js @@ -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(); diff --git a/services/challengeService.js b/services/challengeService.js index b134009..0068b4a 100644 --- a/services/challengeService.js +++ b/services/challengeService.js @@ -119,6 +119,7 @@ const challengeService = { memberId, challengeId, }); + console.log('result', result); return { success: true,