Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #72

Merged
merged 21 commits into from
Jul 17, 2024
Merged

Dev #72

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"tabWidth": 4,
"printWidth": 120,
"semi": true,
"useTabs": false,
"trailingComma": "es5",
"singleQuote": true,
"jsxSingleQuote": true,
"endOfLine": "auto"
"tabWidth": 4,
"printWidth": 120,
"semi": true,
"useTabs": false,
"trailingComma": "es5",
"singleQuote": true,
"jsxSingleQuote": true,
"endOfLine": "auto"
}
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/app.js"
}
]
}
1,454 changes: 1,292 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write ."
"format": "prettier --write .",
"prettier": "prettier --write --config ./.prettierrc './src/**'"
},
"author": "",
"license": "ISC",
Expand Down Expand Up @@ -45,11 +46,15 @@
"swagger-ui-express": "^5.0.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.2.5"
"eslint-plugin-react": "^7.34.4",
"prettier": "^3.3.3"
}
}
1 change: 1 addition & 0 deletions src/common/constants/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const ErrorMessage = Object.freeze({
DELETE_REQUEST_ERROR: '요청 삭제중 오류가 발생하였습니다.',
UPDATE_REQUEST_STATE_ERROR: '요청 상태 변경중 오류가 발생하였습니다.',
ADD_REQUEST_WORDS_ERROR: '단어는 영어와 기호만 입력할 수 있습니다.',
REQUEST_DUPLICATE_ERROR: '같은 단어에 대한 요청이 존재합니다.',
});

module.exports = ErrorMessage;
1 change: 0 additions & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ router.use('/users', userRouter);

router.use('/words', wordRouter);


// EB health check
router.get('/', (_, res) => {
res.status(200).json({ message: 'Success' });
Expand Down
8 changes: 3 additions & 5 deletions src/routes/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,18 @@ exports.postWords = async (req, res) => {
const validData = validateRequest(requestBodySchema, req.body);
const { _id } = req.user;
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,
data: result,
});
} catch (error) {
console.log(error);
console.log('Error during postWords:', error);
if (error?.type === 'ajv') {
return sendResponse.badRequest(res, ErrorMessage.ADD_REQUEST_WORDS_ERROR);
}
if (error.message === '이미 같은 단어 수정 요청이 존재합니다.') {
return sendResponse.badRequest(res, error.message);
}
sendResponse.fail(req, res, ErrorMessage.REGISTER_WORDS_ERROR);
sendResponse.fail(req, res, ErrorMessage.REQUEST_DUPLICATE_ERROR);
}
};

Expand Down
41 changes: 25 additions & 16 deletions src/routes/user/user.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ exports.postWords = async (userId, formData, nickname, type) => {
if (!user) {
throw new Error('User not found');
}

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' && req.deletedAt === 'null'
);
if (existingRequest) {
console.log('이미 같은 단어 요청이 존재합니다.');
throw new Error('Word request already exists');
}

if (type === 'add') {
user.requests.push({
word: formData.devTerm,
Expand All @@ -103,32 +115,29 @@ exports.postWords = async (userId, formData, nickname, type) => {
suggestedBy: nickname, // nickname 추가
});
} else if (type === 'mod') {
const requestExists = user.requests.some((req) => req.word === formData.devTerm);

if (!requestExists) {
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('이미 같은 단어 수정 요청이 존재합니다.');
}
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');
}

await user.save();
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;
}
};

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.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ userRouter.get('/profile', isLoggedIn, getProfile);

// 최근 검색어
userRouter.get('/recent', isLoggedIn, recentSearches); // 최근 검색어 조회
userRouter.delete('recent/:searchTerm', isLoggedIn, delRecentSearch); // 최근 검색어 삭제
userRouter.delete('/recent/:searchTerm', isLoggedIn, delRecentSearch); // 최근 검색어 삭제

//등록 요청
userRouter.post('/requests/new', isLoggedIn, postWords);
Expand Down
1 change: 1 addition & 0 deletions src/routes/user/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ exports.updateRequestState = async (userId, requestId, status, formData, request
if (userId) {
await userRepository.updateRequestState(userId, requestId, status, formData);
if (requestType === 'add') {
//TODO: add 일 때, 단어 중복검사 로직 우선적 검증 추가
await wordRepository.addWord(requestId, formData);
await userRepository.updateRequest(requestId, formData); //수정값 사용자 요청 업데이트
} else if (requestType === 'mod') {
Expand Down
2 changes: 0 additions & 2 deletions src/routes/word/word.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ wordSchema.pre(/^findOne/, async function (next) {
next();
});



module.exports = mongoose.model('Word', wordSchema);
1 change: 1 addition & 0 deletions src/routes/word/word.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ exports.updateWord = async (requestId, formData) => {
}

// word 데이터를 request 데이터로 업데이트합니다.
wordToUpdate.word = formData.devTerm;
wordToUpdate.awkPron = formData.awkPron;
wordToUpdate.comPron = formData.commonPron;
wordToUpdate.info = formData.addInfo;
Expand Down
3 changes: 1 addition & 2 deletions src/routes/word/word.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ wordRouter.get('/search/related', getRelatedWords);
wordRouter.post('/search/:searchTerm', isUser, getSearchWords);

//등록요청 단어 중복검사
wordRouter.post('/checkDuplicateWord', checkDuplicateWord);

wordRouter.post('/duplicate', checkDuplicateWord);

module.exports = wordRouter;
2 changes: 1 addition & 1 deletion src/swagger/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

/**
* @swagger
* /words/checkDuplicateWord:
* /words/duplicate:
* post:
* summary: 개발 용어 중복 검사
* tags: [개발 용어 API]
Expand Down
2 changes: 1 addition & 1 deletion src/swagger/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const options = {
description: 'Local Development',
},
{
url: 'https://api.surakano.site/',
url: 'https://api.murakano.site/',
description: 'Real Server',
},
],
Expand Down