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

Feature/words #46

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Changes from all commits
Commits
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: 11 additions & 5 deletions src/routes/word/word.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -79,7 +87,6 @@ exports.addWord = async (requestId, formData) => {
return null;
}


const newWord = new Word({
word: formData.devTerm,
awkPron: formData.awkPron,
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Expand Down