11const pool = require ( "../common/database" ) ;
22
33const getEtfDetailDao = async ( etfCode ) => {
4- try {
5- console . log ( `[DAO] getEtfDetailDao called with etfCode: ${ etfCode } ` ) ;
4+ try {
5+ console . log ( `[DAO] getEtfDetailDao called with etfCode: ${ etfCode } ` ) ;
66
7- const query = `
7+ const query = `
88 SELECT
99 e.etf_code,
1010 e.etf_name,
@@ -44,27 +44,27 @@ const getEtfDetailDao = async (etfCode) => {
4444 ORDER BY p.trade_date DESC
4545 ` ;
4646
47- console . log ( `[DAO] Executing query with parameter: ${ etfCode } ` ) ;
48- const result = await pool . query ( query , [ etfCode ] ) ;
49- console . log ( `[DAO] Query result: ${ result . rows . length } rows found` ) ;
47+ console . log ( `[DAO] Executing query with parameter: ${ etfCode } ` ) ;
48+ const result = await pool . query ( query , [ etfCode ] ) ;
49+ console . log ( `[DAO] Query result: ${ result . rows . length } rows found` ) ;
5050
51- if ( result . rows . length === 0 ) {
52- console . log ( `[DAO] No data found for ETF code: ${ etfCode } ` ) ;
53- return null ;
54- }
55-
56- console . log ( `[DAO] First row sample:` , result . rows [ 0 ] ) ;
57- return result . rows ;
58- } catch ( error ) {
59- console . error ( "ETF 상세 정보 조회 DAO 에러:" , error ) ;
60- throw error ;
51+ if ( result . rows . length === 0 ) {
52+ console . log ( `[DAO] No data found for ETF code: ${ etfCode } ` ) ;
53+ return null ;
6154 }
55+
56+ console . log ( `[DAO] First row sample:` , result . rows [ 0 ] ) ;
57+ return result . rows ;
58+ } catch ( error ) {
59+ console . error ( "ETF 상세 정보 조회 DAO 에러:" , error ) ;
60+ throw error ;
61+ }
6262} ;
6363
6464const getEtfYieldDao = async ( etfCode ) => {
65- try {
66- // etf_return_cache 테이블에서 미리 계산된 수익률 데이터 조회
67- const query = `
65+ try {
66+ // etf_return_cache 테이블에서 미리 계산된 수익률 데이터 조회
67+ const query = `
6868 SELECT
6969 etf_code,
7070 etf_name,
@@ -82,26 +82,26 @@ const getEtfYieldDao = async (etfCode) => {
8282 WHERE etf_code = $1
8383 ` ;
8484
85- const result = await pool . query ( query , [ etfCode ] ) ;
86-
87- if ( result . rows . length === 0 ) {
88- return null ;
89- }
85+ const result = await pool . query ( query , [ etfCode ] ) ;
9086
91- return result . rows [ 0 ] ;
92- } catch ( error ) {
93- console . error ( "ETF 수익률 데이터 조회 DAO 에러:" , error ) ;
94- throw error ;
87+ if ( result . rows . length === 0 ) {
88+ return null ;
9589 }
90+
91+ return result . rows [ 0 ] ;
92+ } catch ( error ) {
93+ console . error ( "ETF 수익률 데이터 조회 DAO 에러:" , error ) ;
94+ throw error ;
95+ }
9696} ;
9797
9898const getEtfHoldingsDao = async ( etfCode , date = null ) => {
99- try {
100- console . log ( `Fetching holdings data for ETF: ${ etfCode } ` ) ;
99+ try {
100+ console . log ( `Fetching holdings data for ETF: ${ etfCode } ` ) ;
101101
102- // etfs + etf_holdings + stock 조인
103- // SUBSTRING(s.holding_code FROM 4 FOR 6) as stock_code, 부분 고려해야 함
104- let query = `
102+ // etfs + etf_holdings + stock 조인
103+ // SUBSTRING(s.holding_code FROM 4 FOR 6) as stock_code, 부분 고려해야 함
104+ let query = `
105105 SELECT
106106 e.etf_code,
107107 e.etf_name,
@@ -117,35 +117,38 @@ const getEtfHoldingsDao = async (etfCode, date = null) => {
117117 WHERE e.etf_code = $1
118118 ` ;
119119
120- let params = [ etfCode ] ;
121-
122- // 모든 holdings 데이터 조회 (날짜 필터링 제거)
123- query += ` ORDER BY h.weight_pct DESC` ;
120+ let params = [ etfCode ] ;
124121
125- console . log ( 'Executing JOIN query with params:' , params ) ;
126- const result = await pool . query ( query , params ) ;
122+ // 모든 holdings 데이터 조회 (날짜 필터링 제거)
123+ query += ` ORDER BY h.weight_pct DESC` ;
127124
128- if ( result . rows . length === 0 ) {
129- console . log ( `No holdings data found for ETF code: ${ etfCode } ` ) ;
130- return [ ] ;
131- }
125+ console . log ( "Executing JOIN query with params:" , params ) ;
126+ const result = await pool . query ( query , params ) ;
132127
133- console . log ( `Found ${ result . rows . length } holdings records for ETF: ${ etfCode } ` ) ;
134- console . log ( 'Sample holdings data:' , result . rows [ 0 ] ) ;
128+ if ( result . rows . length === 0 ) {
129+ console . log ( `No holdings data found for ETF code: ${ etfCode } ` ) ;
130+ return [ ] ;
131+ }
135132
136- return result . rows ;
133+ console . log (
134+ `Found ${ result . rows . length } holdings records for ETF: ${ etfCode } `
135+ ) ;
136+ console . log ( "Sample holdings data:" , result . rows [ 0 ] ) ;
137137
138- } catch ( error ) {
139- console . error ( "ETF 보유 종목 데이터 조회 DAO 에러:" , error ) ;
140- throw error ;
141- }
138+ return result . rows ;
139+ } catch ( error ) {
140+ console . error ( "ETF 보유 종목 데이터 조회 DAO 에러:" , error ) ;
141+ throw error ;
142+ }
142143} ;
143144
144145const getEtfRecommendationScoreDao = async ( etfCode ) => {
145- try {
146- console . log ( `[DAO] getEtfRecommendationScoreDao called with etfCode: ${ etfCode } ` ) ;
146+ try {
147+ console . log (
148+ `[DAO] getEtfRecommendationScoreDao called with etfCode: ${ etfCode } `
149+ ) ;
147150
148- const query = `
151+ const query = `
149152 SELECT
150153 base_date,
151154 etf_code,
@@ -171,26 +174,32 @@ const getEtfRecommendationScoreDao = async (etfCode) => {
171174 LIMIT 1
172175 ` ;
173176
174- console . log ( `[DAO] Executing recommendation score query with parameter: ${ etfCode } ` ) ;
175- const result = await pool . query ( query , [ etfCode ] ) ;
176- console . log ( `[DAO] Recommendation score query result: ${ result . rows . length } rows found` ) ;
177-
178- if ( result . rows . length === 0 ) {
179- console . log ( `[DAO] No recommendation score data found for ETF code: ${ etfCode } ` ) ;
180- return null ;
181- }
182-
183- console . log ( `[DAO] Recommendation score data:` , result . rows [ 0 ] ) ;
184- return result . rows [ 0 ] ;
185- } catch ( error ) {
186- console . error ( "ETF 추천 점수 데이터 조회 DAO 에러:" , error ) ;
187- throw error ;
177+ console . log (
178+ `[DAO] Executing recommendation score query with parameter: ${ etfCode } `
179+ ) ;
180+ const result = await pool . query ( query , [ etfCode ] ) ;
181+ console . log (
182+ `[DAO] Recommendation score query result: ${ result . rows . length } rows found`
183+ ) ;
184+
185+ if ( result . rows . length === 0 ) {
186+ console . log (
187+ `[DAO] No recommendation score data found for ETF code: ${ etfCode } `
188+ ) ;
189+ return null ;
188190 }
191+
192+ console . log ( `[DAO] Recommendation score data:` , result . rows [ 0 ] ) ;
193+ return result . rows [ 0 ] ;
194+ } catch ( error ) {
195+ console . error ( "ETF 추천 점수 데이터 조회 DAO 에러:" , error ) ;
196+ throw error ;
197+ }
189198} ;
190199
191200module . exports = {
192- getEtfDetailDao,
193- getEtfYieldDao,
194- getEtfHoldingsDao,
195- getEtfRecommendationScoreDao,
201+ getEtfDetailDao,
202+ getEtfYieldDao,
203+ getEtfHoldingsDao,
204+ getEtfRecommendationScoreDao,
196205} ;
0 commit comments