Skip to content

Commit

Permalink
Merge pull request #57 from Murakano/feature/requests-true
Browse files Browse the repository at this point in the history
Feature/requests true (qa 이슈 해결)
  • Loading branch information
trueS2 authored Jul 15, 2024
2 parents 403ceeb + 984c16c commit ab9e1a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/routes/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 18 additions & 16 deletions src/routes/user/user.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
}
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/routes/user/user.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const commonSchemas = {
},
word: {
type: 'string',
pattern: '^[a-zA-Z!@#$%^&*()_+\\-=\\[\\]{};:\'",.<>/?]+$',
pattern: '^[a-zA-Z0-9 !@#$%^&*()_+\\-=\\[\\]{};:\'",.<>/?~`/]+$',
},
};

Expand Down

0 comments on commit ab9e1a2

Please sign in to comment.