Skip to content

Commit

Permalink
๐Ÿ› fix: detail NaN ์ž„์‹œ ํ•ด๊ฒฐ
Browse files Browse the repository at this point in the history
  • Loading branch information
swkim12345 committed Nov 21, 2024
1 parent 8e7e73c commit b92e3e6
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions packages/backend/src/scraper/openapi/api/openapiDetailData.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject, Injectable, UseFilters } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { DataSource } from 'typeorm';
import { Between, DataSource } from 'typeorm';
import { Logger } from 'winston';
import { openApiConfig } from '../config/openapi.config';
import { OpenapiExceptionFilter } from '../Decorator/openapiException.filter';
Expand Down Expand Up @@ -130,23 +130,26 @@ export class OpenapiDetailData {
}

private async get52WeeksLowHigh() {
//const manager = this.datasource.manager;
//const nowDate = new Date();
//const weeksAgoDate = this.getDate52WeeksAgo();
//// ์ฃผ์‹์˜ 52์ฃผ๊ฐ„ ์ผ๋‹จ์œ„ ๋ฐ์ดํ„ฐ ์ „์ฒด ์ค‘์— ์ตœ๊ณ , ์ตœ์ €๊ฐ€๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ตœ์ €๊ฐ€, ์ตœ๊ณ ๊ฐ€ ๊ณ„์‚ฐํ•ด์„œ ๊ฐ€์ ธ์˜ค๊ธฐ
//const output = await manager.find(StockDaily, {
// select: ['low', 'high'],
// where: {
// startTime: Between(weeksAgoDate, nowDate),
// },
//});
//const result = output.reduce((prev, cur) => {
// if (prev.low > cur.low) prev.low = cur.low;
// if (prev.high < cur.high) prev.high = cur.high;
// return cur;
//}, new StockDaily());
//return { low: result.low, high: result.high };
return { low: 0, high: 0 };
const manager = this.datasource.manager;
const nowDate = new Date();
const weeksAgoDate = this.getDate52WeeksAgo();
// ์ฃผ์‹์˜ 52์ฃผ๊ฐ„ ์ผ๋‹จ์œ„ ๋ฐ์ดํ„ฐ ์ „์ฒด ์ค‘์— ์ตœ๊ณ , ์ตœ์ €๊ฐ€๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ตœ์ €๊ฐ€, ์ตœ๊ณ ๊ฐ€ ๊ณ„์‚ฐํ•ด์„œ ๊ฐ€์ ธ์˜ค๊ธฐ
const output = await manager.find(StockDaily, {
select: ['low', 'high'],
where: {
startTime: Between(weeksAgoDate, nowDate),
},
});
const result = output.reduce((prev, cur) => {
if (prev.low > cur.low) prev.low = cur.low;
if (prev.high < cur.high) prev.high = cur.high;
return cur;
}, new StockDaily());
let low = 0;
let high = 0;
if (result.low && !isNaN(result.low)) low = result.low;
if (result.high && !isNaN(result.high)) high = result.high;
return { low, high };
}

private async makeStockDetailObject(
Expand Down

0 comments on commit b92e3e6

Please sign in to comment.