From 96b24ab54027e2c8f20db8f8d850a8357ff4efae Mon Sep 17 00:00:00 2001 From: grulla79 Date: Mon, 8 Jul 2024 01:39:04 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=90=9B=20user=20=EC=8A=A4=ED=82=A4?= =?UTF-8?q?=EB=A7=88=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/user/user.model.js | 6 +++--- src/routes/word/word.repository.js | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/routes/user/user.model.js b/src/routes/user/user.model.js index fabaff8..dddfc3b 100644 --- a/src/routes/user/user.model.js +++ b/src/routes/user/user.model.js @@ -4,15 +4,15 @@ const bcrypt = require('bcrypt'); const requestSchema = new mongoose.Schema( { word: { type: String, required: true }, - awkPron: [{ type: String }], - comPron: [ + awkPron: { type: String }, + comPron: { type: String, required: function () { return this.type === 'mod'; }, }, - ], + info: { type: String }, suggestedBy: { type: String, required: true }, type: { type: String, enum: ['add', 'mod'], required: true }, diff --git a/src/routes/word/word.repository.js b/src/routes/word/word.repository.js index 1588088..3fa3095 100644 --- a/src/routes/word/word.repository.js +++ b/src/routes/word/word.repository.js @@ -65,8 +65,7 @@ exports.getAllWords = async (isSorted, page, limit) => { exports.addWord = async (requestId, formData) => { try { - // requestId에 해당하는 request를 찾습니다. - console.log("addWord 진입!!!!!!!!", requestId, formData) + // requestId에 해당하는 request를 찾습니다. const user = await User.findOne({ 'requests._id': requestId }); if (!user) { console.log('User with the given request not found'); @@ -79,7 +78,6 @@ exports.addWord = async (requestId, formData) => { return null; } - const newWord = new Word({ word: formData.devTerm, awkPron: formData.awkPron, From 4587b58de09b77c8fe4f92b94fe3a2959afeeba1 Mon Sep 17 00:00:00 2001 From: dev-Rhea Date: Tue, 9 Jul 2024 13:54:45 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=20=EC=98=A4=EB=A6=84?= =?UTF-8?q?=EC=B0=A8=EC=88=9C,=20=EB=82=B4=EB=A6=BC=EC=B0=A8=EC=88=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=EC=8B=9C=20=EB=8C=80=EC=86=8C=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=20=EA=B5=AC=EB=B6=84=20=EC=97=86=EC=9D=B4=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/word/word.repository.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/routes/word/word.repository.js b/src/routes/word/word.repository.js index 1588088..04733e8 100644 --- a/src/routes/word/word.repository.js +++ b/src/routes/word/word.repository.js @@ -47,6 +47,8 @@ exports.getAllWords = async (isSorted, page, limit) => { try { const skip = (page - 1) * limit; const sortOrder = {}; + const collation = { locale: 'en', strength: 2 }; // 대소문자 구분 없이 정렬하기 위한 collation 설정 + if (isSorted === 'asc' || isSorted === 'desc') { sortOrder.word = isSorted === 'asc' ? 1 : -1; } else if (isSorted === 'popularity') { @@ -55,7 +57,13 @@ exports.getAllWords = async (isSorted, page, limit) => { sortOrder.createdAt = -1; sortOrder.word = 1; // createdAt이 동일한 경우 단어 오름차순으로 정렬 } - const words = await Word.find().sort(sortOrder).skip(skip).limit(parseInt(limit, 10)); + + const words = await Word.find() + .collation(collation) // collation을 추가하여 대소문자 구분 없이 정렬 + .sort(sortOrder) + .skip(skip) + .limit(parseInt(limit, 10)); + return words; } catch (error) { console.log('Error while getting all words:', error); @@ -66,7 +74,7 @@ exports.getAllWords = async (isSorted, page, limit) => { exports.addWord = async (requestId, formData) => { try { // requestId에 해당하는 request를 찾습니다. - console.log("addWord 진입!!!!!!!!", requestId, formData) + console.log('addWord 진입!!!!!!!!', requestId, formData); const user = await User.findOne({ 'requests._id': requestId }); if (!user) { console.log('User with the given request not found'); @@ -79,7 +87,6 @@ exports.addWord = async (requestId, formData) => { return null; } - const newWord = new Word({ word: formData.devTerm, awkPron: formData.awkPron, @@ -100,7 +107,7 @@ exports.addWord = async (requestId, formData) => { exports.updateWord = async (requestId, formData) => { try { // requestId에 해당하는 request를 찾습니다. - console.log("updateWord 레포진입!!!!!!!!!!!!", requestId, formData) + console.log('updateWord 레포진입!!!!!!!!!!!!', requestId, formData); const user = await User.findOne({ 'requests._id': requestId }); if (!user) { console.log('User with the given request not found'); @@ -129,7 +136,6 @@ exports.updateWord = async (requestId, formData) => { console.log('Word updated successfully'); return wordToUpdate; - } catch (error) { console.log('Error while updating word:', error); return null; From f9e339a8b8526f4eb568c3a8ff28539f3f4f9079 Mon Sep 17 00:00:00 2001 From: grulla79 Date: Tue, 9 Jul 2024 14:41:32 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=A6=BA=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD=20=EA=B0=9C=EB=B0=9C=EC=9A=A9=EC=96=B4=20?= =?UTF-8?q?db=20=EC=9C=A0=ED=9A=A8=EC=84=B1=EA=B2=80=EC=A6=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/user/user.model.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/routes/user/user.model.js b/src/routes/user/user.model.js index dddfc3b..ad510f6 100644 --- a/src/routes/user/user.model.js +++ b/src/routes/user/user.model.js @@ -3,7 +3,11 @@ const bcrypt = require('bcrypt'); const requestSchema = new mongoose.Schema( { - word: { type: String, required: true }, + word: { + type: String, + required: true, + match: /^[a-zA-Z0-9\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/ + }, awkPron: { type: String }, comPron: { From 447c1f9b48bf94a7e05400a5d9c82bec7343a6bf Mon Sep 17 00:00:00 2001 From: true Date: Tue, 9 Jul 2024 20:46:20 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=8E=A8=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EC=B6=94=EA=B0=80=20(=EC=98=81=EC=96=B4,=20?= =?UTF-8?q?=EA=B8=B0=ED=98=B8=EB=A7=8C=20=EA=B0=80=EB=8A=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/user/user.controller.js | 15 +++++++++++---- src/routes/user/user.schema.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/routes/user/user.controller.js b/src/routes/user/user.controller.js index c71e708..a0695e5 100755 --- a/src/routes/user/user.controller.js +++ b/src/routes/user/user.controller.js @@ -13,6 +13,7 @@ const { registerBodySchema, emailCheckReqQuerySchema, loginBodySchema, + requestBodySchema, } = require('./user.schema'); const { generateAccessToken, generateRefreshToken } = require('../../common/utils/auth'); const { getKakaoToken, getUserInfo } = require('../../common/utils/kakao'); @@ -223,21 +224,27 @@ exports.delRecentSearch = async (req, res) => { // 새로운 단어 등록 및 수정 exports.postWords = async (req, res) => { try { + const validData = validateRequest(requestBodySchema, req.body); const { _id } = req.user; - const { nickname } = req.params; // URL 파라미터에서 nickname 추출 - const { formData, type } = req.body; // formData와 type을 요청 본문에서 분리 - + const { nickname } = req.params; + const { formData, type } = req.body; const result = await userService.postWords(_id, formData, nickname, type); - sendResponse.ok(res, { message: SuccessMessage.REGISTER_WORDS_SUCCESS, data: result }); } catch (error) { console.log("Error during postWords:", error); + if (error?.type === 'ajv') { + return sendResponse.badRequest(res, "영어와 기호만 입력 가능합니다."); + } sendResponse.fail(req, res, ErrorMessage.REGISTER_WORDS_ERROR); } }; + + + + exports.UserRequests = async (req, res) => { try{ const { _id } = req.user; diff --git a/src/routes/user/user.schema.js b/src/routes/user/user.schema.js index 699e673..d5d33cc 100644 --- a/src/routes/user/user.schema.js +++ b/src/routes/user/user.schema.js @@ -15,6 +15,10 @@ const commonSchemas = { maxLength: 20, pattern: '^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-=\\[\\]{};:\'",.<>\\/\\\\?]).+$', }, + word: { + type: 'string', + pattern: '^[a-zA-Z!@#$%^&*()_+\\-=\\[\\]{};:\'",.<>/?]+$', + }, }; const registerBodySchema = { @@ -56,4 +60,27 @@ const loginBodySchema = { additionalProperties: false, }; -module.exports = { registerBodySchema, nicknameCheckReqQuerySchema, emailCheckReqQuerySchema, loginBodySchema }; +const requestBodySchema = { + type: 'object', + properties: { + word: commonSchemas.word, + type: { type: 'string' }, + nickname: { type: 'string' }, + formData: { + type: 'object', + properties: { + devTerm: { type: 'string' }, + commonPron: { type: 'string' }, + awkPron: { type: 'string' }, + addInfo: { type: 'string' } + }, + additionalProperties: false + } + }, + required: ['word', 'type', 'nickname', 'formData'], + additionalProperties: false, +}; + + + +module.exports = { registerBodySchema, nicknameCheckReqQuerySchema, emailCheckReqQuerySchema, loginBodySchema, requestBodySchema }; From 0816ead1f04db745e131fc2b56ca8daf15e58358 Mon Sep 17 00:00:00 2001 From: true Date: Tue, 9 Jul 2024 23:48:59 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=8E=A8=20=EC=97=90=EB=9F=AC=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/constants/error-message.js | 1 + src/routes/user/user.controller.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/constants/error-message.js b/src/common/constants/error-message.js index 0261a19..21237ea 100644 --- a/src/common/constants/error-message.js +++ b/src/common/constants/error-message.js @@ -39,6 +39,7 @@ const ErrorMessage = Object.freeze({ GET_REQUESTS_ERROR: '요청 조회중 오류가 발생하였습니다.', DELETE_REQUEST_ERROR: '요청 삭제중 오류가 발생하였습니다.', UPDATE_REQUEST_STATE_ERROR: '요청 상태 변경중 오류가 발생하였습니다.', + ADD_REQUEST_WORDS_ERROR: '단어는 영어와 기호만 입력할 수 ' }); module.exports = ErrorMessage; diff --git a/src/routes/user/user.controller.js b/src/routes/user/user.controller.js index a0695e5..6bfceeb 100755 --- a/src/routes/user/user.controller.js +++ b/src/routes/user/user.controller.js @@ -236,7 +236,7 @@ exports.postWords = async (req, res) => { } catch (error) { console.log("Error during postWords:", error); if (error?.type === 'ajv') { - return sendResponse.badRequest(res, "영어와 기호만 입력 가능합니다."); + return sendResponse.badRequest(res, ErrorMessage.ADD_REQUEST_WORDS_ERROR); } sendResponse.fail(req, res, ErrorMessage.REGISTER_WORDS_ERROR); } From c6c7bde47ec283bd48eb81e03c252ebccecff55a Mon Sep 17 00:00:00 2001 From: jjikky Date: Wed, 10 Jul 2024 19:30:25 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9C=A8=20=ED=9A=8C=EC=9B=90=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/constants/error-message.js | 1 + src/common/constants/success-message.js | 2 +- src/routes/user/user.controller.js | 37 ++++++++++------ src/routes/user/user.repository.js | 57 ++++++++++++++----------- src/routes/user/user.route.js | 8 ++-- src/routes/user/user.service.js | 10 +++-- 6 files changed, 70 insertions(+), 45 deletions(-) diff --git a/src/common/constants/error-message.js b/src/common/constants/error-message.js index 0261a19..87baed5 100644 --- a/src/common/constants/error-message.js +++ b/src/common/constants/error-message.js @@ -25,6 +25,7 @@ const ErrorMessage = Object.freeze({ KAKAO_LOGIN_ERROR: '카카오 로그인중 오류가 발생하였습니다.', NO_REFRESH_TOKEN: 'refresh token이 존재하지 않습니다.', REFRESH_TOKEN_ERROR: 'refresh token 검증중 오류가 발생하였습니다.', + DELETE_USER_ERROR: '회원탈퇴중 오류가 발생하였습니다.', // WORD RECENT_WORDS_ERROR: '최근 검색어 조회중 오류가 발생하였습니다.', diff --git a/src/common/constants/success-message.js b/src/common/constants/success-message.js index e9575e3..b2c961f 100644 --- a/src/common/constants/success-message.js +++ b/src/common/constants/success-message.js @@ -8,8 +8,8 @@ const SuccessMessage = Object.freeze({ LOGIN_SUCCESSS: '로그인 성공', LOGOUT_SUCCESS: '로그아웃 성공', + DELETE_USER_SUCCESS: '회원 탈퇴 성공', REFRESH_TOKEN: 'access token 발급 성공', - GET_PROFILE_SUCCESS: '유저 정보 조회 성공', // WORD - 최근검색어 diff --git a/src/routes/user/user.controller.js b/src/routes/user/user.controller.js index c71e708..d5cf900 100755 --- a/src/routes/user/user.controller.js +++ b/src/routes/user/user.controller.js @@ -2,7 +2,6 @@ const passport = require('passport'); const jwt = require('jsonwebtoken'); const config = require('../../common/config'); - const userService = require('./user.service'); const sendResponse = require('../../common/utils/response-handler'); const ErrorMessage = require('../../common/constants/error-message'); @@ -231,15 +230,15 @@ exports.postWords = async (req, res) => { sendResponse.ok(res, { message: SuccessMessage.REGISTER_WORDS_SUCCESS, - data: result + data: result, }); } catch (error) { - console.log("Error during postWords:", error); + console.log('Error during postWords:', error); sendResponse.fail(req, res, ErrorMessage.REGISTER_WORDS_ERROR); } }; exports.UserRequests = async (req, res) => { - try{ + try { const { _id } = req.user; const requests = await userService.getUserRequests(_id); sendResponse.ok(res, { @@ -253,7 +252,7 @@ exports.UserRequests = async (req, res) => { }; exports.UserRequestsAll = async (req, res) => { - try{ + try { const requests = await userService.getUserRequestsAll(); sendResponse.ok(res, { message: SuccessMessage.GET_REQUESTS_SUCCESS, @@ -263,10 +262,10 @@ exports.UserRequestsAll = async (req, res) => { console.log(err); sendResponse.fail(req, res, ErrorMessage.GET_REQUESTS_ERROR); } -} +}; exports.deleteRequest = async (req, res) => { - try{ + try { const { _id } = req.user; // 현재 로그인한 사용자의 고유 식별자 const { word } = req.params; await userService.deleteRequest(_id, word); @@ -277,7 +276,7 @@ exports.deleteRequest = async (req, res) => { console.log(err); sendResponse.fail(req, res, ErrorMessage.DELETE_REQUEST_ERROR); } -} +}; exports.getRole = async (req, res) => { const { _id } = req.user; @@ -286,20 +285,20 @@ exports.getRole = async (req, res) => { message: SuccessMessage.GET_ROLE_SUCCESS, data: { role }, }); -} +}; exports.updateRequest = async (req, res) => { const { requestId } = req.params; const { formData } = req.body; await userService.updateRequest(requestId, formData); sendResponse.ok(res, { - message: SuccessMessage.UPDATE_REQUEST_SUCCESS + message: SuccessMessage.UPDATE_REQUEST_SUCCESS, }); -} +}; exports.updateRequestState = async (req, res) => { try { - const { _id} = req.user; + const { _id } = req.user; const { requestId } = req.params; const { status, formData, requestType } = req.body; @@ -311,5 +310,17 @@ exports.updateRequestState = async (req, res) => { console.log(err); sendResponse.fail(req, res, ErrorMessage.UPDATE_REQUEST_STATE_ERROR); } -} +}; +exports.deleteUser = async (req, res) => { + try { + const { _id } = req.user; + await userService.deleteUser(_id); + sendResponse.ok(res, { + message: SuccessMessage.DELETE_USER_SUCCESS, + }); + } catch (err) { + console.log(err); + sendResponse.fail(req, res, ErrorMessage.DELETE_USER_ERROR); + } +}; diff --git a/src/routes/user/user.repository.js b/src/routes/user/user.repository.js index 30e815b..21a6ff0 100644 --- a/src/routes/user/user.repository.js +++ b/src/routes/user/user.repository.js @@ -59,14 +59,14 @@ exports.delRecentSearch = async (_id, searchTerm) => { exports.updateRecentSearch = async (_id, searchTerm) => { try { - console.log("id", _id) - console.log("searchTerm", searchTerm) + console.log('id', _id); + console.log('searchTerm', searchTerm); const user = await User.findById(_id).exec(); if (!user) { console.log('User not found'); } const recentSearch = user.recentSearches.find((search) => search.searchTerm === searchTerm); - console.log("recentSearch", recentSearch) + console.log('recentSearch', recentSearch); if (recentSearch) { // 검색어가 이미 존재하는 경우 if (recentSearch.deletedAt) { @@ -94,7 +94,7 @@ exports.postWords = async (userId, formData, nickname, type) => { throw new Error('User not found'); } - console.log("User before modification:", JSON.stringify(user.requests, null, 2)); + console.log('User before modification:', JSON.stringify(user.requests, null, 2)); if (type === 'add') { user.requests.push({ @@ -105,10 +105,10 @@ exports.postWords = async (userId, formData, nickname, type) => { deletedAt: null, status: 'pend', type: 'add', - suggestedBy: nickname // nickname 추가 + suggestedBy: nickname, // nickname 추가 }); } else if (type === 'mod') { - const request = user.requests.find(req => req.word === formData.devTerm); + const request = user.requests.find((req) => req.word === formData.devTerm); if (!request) { user.requests.push({ word: formData.devTerm, @@ -118,8 +118,8 @@ exports.postWords = async (userId, formData, nickname, type) => { deletedAt: null, status: 'pend', type: 'mod', - suggestedBy: nickname // nickname 추가 - }) + suggestedBy: nickname, // nickname 추가 + }); } else { console.log('이미 같은 단어 수정 요청이 존재합니다.'); throw new Error('Word not found'); @@ -129,8 +129,8 @@ exports.postWords = async (userId, formData, nickname, type) => { } await user.save(); - console.log("User after modification:", JSON.stringify(user.requests, null, 2)); - return user.requests.find(req => req.word === formData.devTerm); + console.log('User after modification:', JSON.stringify(user.requests, null, 2)); + return user.requests.find((req) => req.word === formData.devTerm); } catch (err) { console.error(err); throw err; @@ -138,15 +138,14 @@ exports.postWords = async (userId, formData, nickname, type) => { }; exports.getUserRequests = async (userId) => { - try { + try { const user = await User.findById(userId).select('requests').exec(); if (!user) { throw new Error('User not found'); } // requests 배열에서 deletedAt이 null인 항목만 필터링 - const activeRequests = user.requests.filter(request => request.deletedAt === null); + const activeRequests = user.requests.filter((request) => request.deletedAt === null); return activeRequests; - } catch (err) { console.error(err); } @@ -157,8 +156,8 @@ exports.getUserRequestsAll = async () => { const users = await User.find({}, { requests: 1, _id: 0 }); // 모든 유저의 requests 필드만 가져옴 const allRequests = []; - users.forEach(user => { - user.requests.forEach(request => { + users.forEach((user) => { + user.requests.forEach((request) => { if (request.deletedAt === null) { allRequests.push(request); } @@ -169,29 +168,29 @@ exports.getUserRequestsAll = async () => { } catch (err) { console.error(err); } -} +}; exports.deleteRequest = async (userId, requestWord) => { try { const user = await User.findById(userId).select('requests').exec(); if (!user) { - console.log("사용자를 찾을 수 없음"); + console.log('사용자를 찾을 수 없음'); throw new Error('User not found'); } - const request = user.requests.find(req => req.word === requestWord && req.deletedAt === null); + const request = user.requests.find((req) => req.word === requestWord && req.deletedAt === null); if (request) { - console.log("삭제할 요청 찾음:", request); + console.log('삭제할 요청 찾음:', request); request.deletedAt = Date.now(); // 요청을 삭제로 표시 await user.save(); - console.log("요청 삭제 성공"); + console.log('요청 삭제 성공'); } else { } } catch (err) { console.error(err); } -} +}; exports.getRole = async (userId) => { try { @@ -200,7 +199,7 @@ exports.getRole = async (userId) => { } catch (err) { console.error(err); } -} +}; exports.updateRequest = async (requestId, formData) => { try { @@ -209,7 +208,7 @@ exports.updateRequest = async (requestId, formData) => { throw new Error('User not found'); } - const request = user.requests.find(req => req._id.toString() === requestId && req.deletedAt === null); + const request = user.requests.find((req) => req._id.toString() === requestId && req.deletedAt === null); if (request) { // formData의 각 속성 값으로 request의 해당 속성 값 업데이트 if (formData.addInfo !== undefined) { @@ -236,7 +235,7 @@ exports.updateRequest = async (requestId, formData) => { exports.updateRequestState = async (userId, requestId, status) => { try { - console.log("updateRequestState 레포진입!!!!!!!!!!!!", userId, requestId, status) + console.log('updateRequestState 레포진입!!!!!!!!!!!!', userId, requestId, status); const user = await User.findOneAndUpdate( { 'requests._id': requestId }, { $set: { 'requests.$.status': status } }, @@ -248,7 +247,15 @@ exports.updateRequestState = async (userId, requestId, status) => { } else { console.log('Request status updated successfully'); } + } catch (err) { + console.error(err); + } +}; +exports.deleteUserById = async (_id) => { + try { + return await User.findByIdAndDelete(_id); } catch (err) { console.error(err); - }} \ No newline at end of file + } +}; diff --git a/src/routes/user/user.route.js b/src/routes/user/user.route.js index 9934f25..836d9a0 100644 --- a/src/routes/user/user.route.js +++ b/src/routes/user/user.route.js @@ -17,10 +17,13 @@ const { updateRequest, getRole, updateRequestState, + deleteUser, } = require('./user.controller'); -const { isLoggedIn, isNotLoggedIn, isUser } = require('../../common/utils/auth'); +const { isLoggedIn, isNotLoggedIn } = require('../../common/utils/auth'); const userRouter = express.Router(); +userRouter.delete('/', isLoggedIn, deleteUser); + // 회원가입 userRouter.post('/register', isNotLoggedIn, register); userRouter.get('/check/nickname', isNicknameExist); @@ -49,8 +52,7 @@ userRouter.get('/role', isLoggedIn, getRole); // 사용자 역할 가져오기 userRouter.delete('/requests/:word', isLoggedIn, deleteRequest); // 사용자 요청 삭제 userRouter.post('/requests/:requestId', isLoggedIn, updateRequest); // 사용자 요청 수정 - -//요청 상태 변경 +//요청 상태 변경 userRouter.post('/requests/:requestId/status', isLoggedIn, updateRequestState); // 사용자 요청 status 변경 module.exports = userRouter; diff --git a/src/routes/user/user.service.js b/src/routes/user/user.service.js index 53fb77e..970287b 100644 --- a/src/routes/user/user.service.js +++ b/src/routes/user/user.service.js @@ -76,14 +76,14 @@ exports.getRole = async (userId) => { }; exports.updateRequest = async (requestId, formData) => { - if(requestId) { + if (requestId) { await userRepository.updateRequest(requestId, formData); } }; exports.updateRequestState = async (userId, requestId, status, formData, requestType) => { if (userId) { - console.log("업데이트 서비스 진입!!!!!!!!!!!!", userId, requestId, status, formData, requestType) + console.log('업데이트 서비스 진입!!!!!!!!!!!!', userId, requestId, status, formData, requestType); await userRepository.updateRequestState(userId, requestId, status, formData); if (requestType === 'add') { await wordRepository.addWord(requestId, formData); @@ -92,8 +92,12 @@ exports.updateRequestState = async (userId, requestId, status, formData, request await wordRepository.updateWord(requestId, formData); await userRepository.updateRequest(requestId, formData); //수정값 사용자 요청 업데이트 } else { - console.log("requestType 오류") + console.log('requestType 오류'); return; } } }; + +exports.deleteUser = async (_id) => { + return await userRepository.deleteUserById(_id); +}; From d0940c73e4a54a1bcb343ab145d5483781e80925 Mon Sep 17 00:00:00 2001 From: jjikky Date: Wed, 10 Jul 2024 22:04:59 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20qa=EB=95=8C=EB=AC=B8?= =?UTF-8?q?=EC=97=90=20limit=201000=EB=B2=88=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/rateLimit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/utils/rateLimit.js b/src/common/utils/rateLimit.js index 8721a08..b29fdf9 100644 --- a/src/common/utils/rateLimit.js +++ b/src/common/utils/rateLimit.js @@ -15,7 +15,7 @@ exports.postApiLimiter = rateLimit({ exports.commonLimiter = rateLimit({ windowMs: 60 * 1000, // 1분 간격 - max: 50, // windowMs동안 최대 호출 횟수 + max: 1000, // windowMs동안 최대 호출 횟수 handler(req, res) { // 제한 초과 시 콜백 함수 res.status(this.statusCode).json({