Skip to content

Commit

Permalink
๐Ÿ”ง fix: ์ค‘๋ณต๋œ ๋งํฌ๋ฅผ ๋„ฃ์ง€ ์•Š๊ฒŒ ์ค‘๋ณต์„ ํ™•์ธํ•˜๋Š” ๋กœ์ง ์ถ”๊ฐ€#181
Browse files Browse the repository at this point in the history
  • Loading branch information
uuuo3o committed Nov 29, 2024
1 parent 332aa16 commit 93848c0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions BE/src/news/news.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ export class NewsService {
@Cron('*/1 8-16 * * 1-5')
async cronNewsData() {
await this.newsRepository.delete({ query: In(['์ฆ๊ถŒ', '์ฃผ์‹']) });
await this.getNewsDataByQuery('์ฃผ์‹');
await this.getNewsDataByQuery('์ฆ๊ถŒ');
const stockNews = await this.getNewsDataByQuery('์ฃผ์‹');
const securityNews = await this.getNewsDataByQuery('์ฆ๊ถŒ');

const allNews = [...stockNews, ...securityNews];
const uniqueNews = allNews.filter(
(news, index) =>
allNews.findIndex((i) => i.originallink === news.originallink) ===
index,
);

await this.newsRepository.save(uniqueNews);
await this.newsRepository.update(
{},
{
Expand All @@ -67,13 +75,16 @@ export class NewsService {

const response =
await this.naverApiDomainService.requestApi<NewsApiResponse>(queryParams);
const formattedData = this.formatNewsData(value, response.items);

return this.newsRepository.save(formattedData);
return this.newsRepository.save(this.formatNewsData(value, response.items));
}

private formatNewsData(query: string, items: NewsDataOutputDto[]) {
return items.slice(0, 10).map((item) => {
const uniqueItems = items.filter(
(item, index) =>
items.findIndex((i) => i.originallink === item.originallink) === index,
);

return uniqueItems.slice(0, 10).map((item) => {
const result = new NewsItemDataDto();

result.title = this.htmlEncode(item.title);
Expand Down

0 comments on commit 93848c0

Please sign in to comment.