From a1f9d8e618a1170b608c847fc94a812eb33f5d69 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 4 Sep 2024 21:25:01 +0200 Subject: [PATCH] Add check for dateOfFirstActivity --- .../admin-market-data-detail.component.ts | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts b/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts index 7e7168a6e..a1261c37f 100644 --- a/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts +++ b/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts @@ -93,52 +93,52 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit { }; }); - let date = parseISO(this.dateOfFirstActivity); - - const missingMarketData: Partial[] = []; - - if (this.historicalDataItems?.[0]?.date) { - while ( - isBefore( - date, - parse(this.historicalDataItems[0].date, DATE_FORMAT, new Date()) - ) - ) { - missingMarketData.push({ - date, - marketPrice: undefined - }); - - date = addDays(date, 1); + if (this.dateOfFirstActivity) { + let date = parseISO(this.dateOfFirstActivity); + + const missingMarketData: Partial[] = []; + + if (this.historicalDataItems?.[0]?.date) { + while ( + isBefore( + date, + parse(this.historicalDataItems[0].date, DATE_FORMAT, new Date()) + ) + ) { + missingMarketData.push({ + date, + marketPrice: undefined + }); + + date = addDays(date, 1); + } } - } - const marketDataItems = [...missingMarketData, ...this.marketData]; + const marketDataItems = [...missingMarketData, ...this.marketData]; - if (!isToday(last(marketDataItems)?.date)) { - marketDataItems.push({ date: new Date() }); - } + if (!isToday(last(marketDataItems)?.date)) { + marketDataItems.push({ date: new Date() }); + } - this.marketDataByMonth = {}; + this.marketDataByMonth = {}; - for (const marketDataItem of marketDataItems) { - const currentDay = parseInt(format(marketDataItem.date, 'd'), 10); - const key = format(marketDataItem.date, 'yyyy-MM'); + for (const marketDataItem of marketDataItems) { + const currentDay = parseInt(format(marketDataItem.date, 'd'), 10); + const key = format(marketDataItem.date, 'yyyy-MM'); - if (!this.marketDataByMonth[key]) { - this.marketDataByMonth[key] = {}; - } + if (!this.marketDataByMonth[key]) { + this.marketDataByMonth[key] = {}; + } - this.marketDataByMonth[key][ - currentDay < 10 ? `0${currentDay}` : currentDay - ] = { - date: marketDataItem.date, - day: currentDay, - marketPrice: marketDataItem.marketPrice - }; - } + this.marketDataByMonth[key][ + currentDay < 10 ? `0${currentDay}` : currentDay + ] = { + date: marketDataItem.date, + day: currentDay, + marketPrice: marketDataItem.marketPrice + }; + } - if (this.dateOfFirstActivity) { // Fill up missing months const dates = Object.keys(this.marketDataByMonth).sort(); const startDate = min([