@@ -9,13 +9,13 @@ export class WordsService {
99 /**
1010 * 내부용: 전체 낱말 카드 목록 생성 (categoryId 없이)
1111 */
12- async _getAllWordCards ( userId , onlyFavorite = false ) {
12+ async _getAllWordCards ( userId , accountType , onlyFavorite = false ) {
1313 const wordCards = [ ] ;
1414 let categoryNameToUserCategoryIdMap = new Map ( ) ;
1515 let categoryNameToCategoryIdMap = new Map ( ) ;
1616 let hasUserCategories = false ;
1717
18- if ( userId ) {
18+ if ( userId && accountType !== 'GUEST' ) {
1919 const userCategories = await wordsRepository . findAllUserCategories ( userId ) ;
2020 if ( userCategories . length > 0 ) {
2121 hasUserCategories = true ;
@@ -44,17 +44,14 @@ export class WordsService {
4444 } ) ;
4545 }
4646
47- // 소셜 로그인(유저가 존재) 시에는 기본 Word를 반환하지 않고 UserWord만 반환
48- // 게스트(유저 없음)일 때만 기본 Word 반환
49- if ( ! onlyFavorite && ! userId ) {
50- const words = await wordsRepository . findWords ( null , userId ) ;
47+ // 소셜/게스트 로그인(유저가 존재) 시에는 UserWord 기반, 비회원(토큰 없음)만 기본 Word 반환
48+ if ( ! onlyFavorite && ! userId && ! accountType ) {
49+ const words = await wordsRepository . findWords ( ) ;
5150 words . forEach ( ( word , index ) => {
52- const wordCategoryName = word . category ?. categoryName ;
53- let mappedCategoryId = categoryNameToCategoryIdMap . get ( wordCategoryName ) || word . categoryId ;
5451 wordCards . push ( new WordCardResponseDto ( {
5552 cardId : word . id ,
56- categoryId : mappedCategoryId ,
57- categoryName : wordCategoryName ,
53+ categoryId : word . categoryId ,
54+ categoryName : word . category ?. categoryName ,
5855 partOfSpeech : word . partOfSpeech ,
5956 word : word . word ,
6057 imageUrl : word . imageUrl ,
@@ -101,20 +98,20 @@ export class WordsService {
10198 /**
10299 * 다음 displayOrder 계산 (기본 Word + UserWord 모두 고려)
103100 * @param {string } userId
101+ * @param {string } accountType
104102 * @param {string } categoryId
105103 * @returns {Promise<number> }
106104 */
107- async getNextDisplayOrder ( userId , categoryId ) {
105+ async getNextDisplayOrder ( userId , accountType , categoryId ) {
108106 // 1. UserWord 조회 (삭제된 것 제외)
109- const userWords = await wordsRepository . findUserWords ( userId , categoryId , false , false ) ;
110-
111- // 2. UserWord가 있으면 최대값 + 1 반환
112- if ( userWords . length > 0 ) {
113- const maxOrder = Math . max ( ... userWords . map ( w => w . displayOrder ) ) ;
114- return maxOrder + 1 ;
107+ if ( accountType !== 'GUEST' ) {
108+ const userWords = await wordsRepository . findUserWords ( userId , categoryId , false , false ) ;
109+ if ( userWords . length > 0 ) {
110+ const maxOrder = Math . max ( ... userWords . map ( w => w . displayOrder ) ) ;
111+ return maxOrder + 1 ;
112+ }
115113 }
116-
117- // 3. UserWord가 없으면 기본 Word 개수 반환
114+ // 게스트이거나 UserWord가 없으면 기본 Word 개수 반환
118115 const words = await wordsRepository . findWords ( categoryId , userId ) ;
119116 return words . length ;
120117 }
@@ -124,13 +121,14 @@ export class WordsService {
124121 * 기본 낱말(Word) + 개인 낱말(UserWord) 통합 반환
125122 *
126123 * @param {string } userId
124+ * @param {string } accountType
127125 * @param {string|null } categoryId - Category.id 또는 UserCategory.id
128126 * @param {boolean } onlyFavorite
129127 * @returns {Promise<Object> } { category, words }
130128 */
131- async getWords ( userId , categoryId = null , onlyFavorite = false ) {
129+ async getWords ( userId , accountType , categoryId = null , onlyFavorite = false ) {
132130 // 1. 전체 낱말 목록 생성 (categoryId 없이)
133- const allWords = await this . _getAllWordCards ( userId , onlyFavorite ) ;
131+ const allWords = await this . _getAllWordCards ( userId , accountType , onlyFavorite ) ;
134132
135133 // 2. categoryId가 없으면 전체 반환
136134 if ( ! categoryId ) {
0 commit comments