Browse Source

Refactoring

pull/3190/head
Thomas Kaul 1 year ago
parent
commit
ac405dcd63
  1. 29
      apps/api/src/app/portfolio/portfolio.service.ts
  2. 2
      apps/api/src/app/user/update-user-setting.dto.ts

29
apps/api/src/app/portfolio/portfolio.service.ts

@ -26,7 +26,8 @@ import {
DATE_FORMAT, DATE_FORMAT,
getAllActivityTypes, getAllActivityTypes,
getSum, getSum,
parseDate parseDate,
resetHours
} from '@ghostfolio/common/helper'; } from '@ghostfolio/common/helper';
import { import {
Accounts, Accounts,
@ -1625,44 +1626,34 @@ export class PortfolioService {
switch (aDateRange) { switch (aDateRange) {
case '1d': case '1d':
startDate = max([ startDate = max([startDate, subDays(resetHours(new Date()), 1)]);
startDate,
subDays(new Date().setHours(0, 0, 0, 0), 1)
]);
break; break;
case 'mtd': case 'mtd':
startDate = max([ startDate = max([
startDate, startDate,
subDays(startOfMonth(new Date().setHours(0, 0, 0, 0)), 1) subDays(startOfMonth(resetHours(new Date())), 1)
]); ]);
break; break;
case 'wtd': case 'wtd':
startDate = max([ startDate = max([
startDate, startDate,
subDays( subDays(startOfWeek(resetHours(new Date()), { weekStartsOn: 1 }), 1)
startOfWeek(new Date().setHours(0, 0, 0, 0), { weekStartsOn: 1 }),
1
)
]); ]);
break; break;
case 'ytd': case 'ytd':
startDate = max([ startDate = max([
startDate, startDate,
subDays(startOfYear(new Date().setHours(0, 0, 0, 0)), 1) subDays(startOfYear(resetHours(new Date())), 1)
]); ]);
break; break;
case '1y': case '1y':
startDate = max([ startDate = max([startDate, subYears(resetHours(new Date()), 1)]);
startDate,
subYears(new Date().setHours(0, 0, 0, 0), 1)
]);
break; break;
case '5y': case '5y':
startDate = max([ startDate = max([startDate, subYears(resetHours(new Date()), 5)]);
startDate,
subYears(new Date().setHours(0, 0, 0, 0), 5)
]);
break; break;
default:
startDate = max([startDate, new Date(aDateRange)]);
} }
return startDate; return startDate;

2
apps/api/src/app/user/update-user-setting.dto.ts

@ -41,7 +41,7 @@ export class UpdateUserSettingDto {
'mtd', 'mtd',
'wtd', 'wtd',
'ytd', 'ytd',
...eachYearOfInterval({ end: new Date(1900), start: new Date() }).map( ...eachYearOfInterval({ end: new Date(), start: new Date(1900) }).map(
(date) => { (date) => {
return format(date, 'yyyy'); return format(date, 'yyyy');
} }

Loading…
Cancel
Save