diff --git a/src/routes/user/user.controller.js b/src/routes/user/user.controller.js index a1f4aea..520eaae 100755 --- a/src/routes/user/user.controller.js +++ b/src/routes/user/user.controller.js @@ -267,8 +267,8 @@ exports.postWords = async (req, res) => { try { const validData = validateRequest(requestBodySchema, req.body); const { _id } = req.user; - const { nickname } = req.params; - const { formData, type } = req.body; + const { formData, type, nickname } = validData; + console.log(formData); const result = await userService.postWords(_id, formData, nickname, type); sendResponse.ok(res, { message: SuccessMessage.REGISTER_WORDS_SUCCESS, diff --git a/src/routes/user/user.repository.js b/src/routes/user/user.repository.js index 21a6ff0..fe10352 100644 --- a/src/routes/user/user.repository.js +++ b/src/routes/user/user.repository.js @@ -96,6 +96,13 @@ exports.postWords = async (userId, formData, nickname, type) => { console.log('User before modification:', JSON.stringify(user.requests, null, 2)); + // 이미 존재하는 단어 요청 확인 (status가 'pend'인 경우에만 중복 확인) + const existingRequest = user.requests.find((req) => req.word === formData.devTerm && req.status === 'pend'); + if (existingRequest) { + console.log('이미 같은 단어 요청이 존재합니다.'); + throw new Error('Word request already exists'); + } + if (type === 'add') { user.requests.push({ word: formData.devTerm, @@ -108,22 +115,16 @@ exports.postWords = async (userId, formData, nickname, type) => { suggestedBy: nickname, // nickname 추가 }); } else if (type === 'mod') { - const request = user.requests.find((req) => req.word === formData.devTerm); - if (!request) { - user.requests.push({ - word: formData.devTerm, - info: formData.addInfo, - awkPron: formData.awkPron, - comPron: formData.commonPron, - deletedAt: null, - status: 'pend', - type: 'mod', - suggestedBy: nickname, // nickname 추가 - }); - } else { - console.log('이미 같은 단어 수정 요청이 존재합니다.'); - throw new Error('Word not found'); - } + user.requests.push({ + word: formData.devTerm, + info: formData.addInfo, + awkPron: formData.awkPron, + comPron: formData.commonPron, + deletedAt: null, + status: 'pend', + type: 'mod', + suggestedBy: nickname, // nickname 추가 + }); } else { throw new Error('Invalid type'); } @@ -137,6 +138,7 @@ exports.postWords = async (userId, formData, nickname, type) => { } }; + exports.getUserRequests = async (userId) => { try { const user = await User.findById(userId).select('requests').exec(); diff --git a/src/routes/user/user.schema.js b/src/routes/user/user.schema.js index d5d33cc..d81a9f2 100644 --- a/src/routes/user/user.schema.js +++ b/src/routes/user/user.schema.js @@ -17,7 +17,7 @@ const commonSchemas = { }, word: { type: 'string', - pattern: '^[a-zA-Z!@#$%^&*()_+\\-=\\[\\]{};:\'",.<>/?]+$', + pattern: '^[a-zA-Z0-9 !@#$%^&*()_+\\-=\\[\\]{};:\'",.<>/?~`/]+$', }, };