From 4587b58de09b77c8fe4f92b94fe3a2959afeeba1 Mon Sep 17 00:00:00 2001 From: dev-Rhea Date: Tue, 9 Jul 2024 13:54:45 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=20=EC=98=A4=EB=A6=84?= =?UTF-8?q?=EC=B0=A8=EC=88=9C,=20=EB=82=B4=EB=A6=BC=EC=B0=A8=EC=88=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=EC=8B=9C=20=EB=8C=80=EC=86=8C=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=20=EA=B5=AC=EB=B6=84=20=EC=97=86=EC=9D=B4=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/word/word.repository.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/routes/word/word.repository.js b/src/routes/word/word.repository.js index 1588088..04733e8 100644 --- a/src/routes/word/word.repository.js +++ b/src/routes/word/word.repository.js @@ -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') { @@ -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); @@ -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'); @@ -79,7 +87,6 @@ exports.addWord = async (requestId, formData) => { return null; } - const newWord = new Word({ word: formData.devTerm, awkPron: formData.awkPron, @@ -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'); @@ -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;