Refactored functionality for all time date range.
This commit is contained in:
@@ -122,7 +122,7 @@ async function findUnique(data) {
|
||||
throw `${data.length} records found when expecting 1.`;
|
||||
}
|
||||
|
||||
return data[0] ?? null;
|
||||
return findFirst(data);
|
||||
}
|
||||
|
||||
async function findFirst(data) {
|
||||
|
||||
11
lib/query.ts
11
lib/query.ts
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -137,3 +137,10 @@ export interface RealtimeUpdate {
|
||||
events: any[];
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export interface DateRange {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
unit: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user