Skip to content

Commit

Permalink
Merge pull request #54 from Murakano/feature/user
Browse files Browse the repository at this point in the history
Feature/user
  • Loading branch information
jjikky authored Jul 12, 2024
2 parents 999951c + d841826 commit 33ff058
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/routes/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const jwt = require('jsonwebtoken');
const config = require('../../common/config');

const userService = require('./user.service');
const wordService = require('../word/word.service');
const sendResponse = require('../../common/utils/response-handler');
const ErrorMessage = require('../../common/constants/error-message');
const SuccessMessage = require('../../common/constants/success-message');
Expand Down Expand Up @@ -319,6 +320,7 @@ exports.updateRequestState = async (req, res) => {
exports.deleteUser = async (req, res) => {
try {
const { _id } = req.user;
await wordService.deleteWordContributor(_id);
await userService.deleteUser(_id);
sendResponse.ok(res, {
message: SuccessMessage.DELETE_USER_SUCCESS,
Expand Down
25 changes: 21 additions & 4 deletions src/routes/word/word.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ exports.getAllWords = async (isSorted, page, limit) => {

exports.addWord = async (requestId, formData) => {
try {
// requestId에 해당하는 request를 찾습니다.
// requestId에 해당하는 request를 찾습니다.
const user = await User.findOne({ 'requests._id': requestId });
if (!user) {
console.log('User with the given request not found');
Expand Down Expand Up @@ -141,14 +141,31 @@ exports.updateWord = async (requestId, formData) => {
}
};

exports.deleteWordContributor = async (_id) => {
// _id가 일치하는 유저의 닉네임 값을 가져오고, 해당 유저가 suggestedBy로 있는 모든 단어의 suggestedBy를 null로 변경
try {
const user = await User.findById(_id);

if (!user) {
console.log('User not found');
return null;
}
const nickname = user.nickname;

const words = await Word.updateMany({ suggestedBy: nickname }, { suggestedBy: null });
return words;
} catch (error) {
console.log('Error while deleting word contributor:', error);
return null;
}
};
exports.checkDuplicateWord = async (word) => {
try {
const wordExists = await Word.findOne({ word: { $regex: new RegExp(`^${word}$`, 'i') } });
console.log('wordExists:', wordExists);
return wordExists;
}
catch (error) {
} catch (error) {
console.log('Error while checking duplicate word:', error);
return null;
}
}
};
6 changes: 5 additions & 1 deletion src/routes/word/word.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ exports.getAllWords = async (sort, page, limit) => {
return words;
};

exports.deleteWordContributor = async (_id) => {
return await wordRepository.deleteWordContributor(_id);
};

// 등록 단어 중복 검사
exports.checkDuplicateWord = async (word) => {
const isDuplicate = await wordRepository.checkDuplicateWord(word);
console.log("isDuplicate: ", isDuplicate)
console.log('isDuplicate: ', isDuplicate);
return isDuplicate;
};

0 comments on commit 33ff058

Please sign in to comment.