Refactored functionality for all time date range.

This commit is contained in:
Mike Cao 2023-07-26 13:42:55 -07:00
parent c3973f5fb5
commit d06808985b
11 changed files with 91 additions and 33 deletions

View file

@ -7,12 +7,15 @@ export async function parseDateRangeQuery(req: NextApiRequest) {
// All-time
if (+startAt === 0 && +endAt === 1) {
const { min, max } = await getWebsiteDateRange(websiteId as string);
const result = await getWebsiteDateRange(websiteId as string);
const { min, max } = result[0];
const startDate = new Date(min);
const endDate = new Date(max);
return {
startDate: min,
endDate: max,
unit: getMinimumUnit(min, max),
startDate,
endDate,
unit: getMinimumUnit(startDate, endDate),
};
}