fix: enable sessions for API keys (#283)
* fix: enable sessions for API keys * chore: remove old due date filters * chore: update lockfile * fix: temp ignore eslint errors on build
This commit is contained in:
63
packages/shared/src/utils/dueDateFilters.ts
Normal file
63
packages/shared/src/utils/dueDateFilters.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { addDays, endOfDay, startOfDay } from "date-fns";
|
||||
|
||||
export type DueDateFilterKey =
|
||||
| "overdue"
|
||||
| "today"
|
||||
| "tomorrow"
|
||||
| "next-week"
|
||||
| "next-month"
|
||||
| "no-due-date";
|
||||
|
||||
export interface DueDateFilter {
|
||||
startDate?: Date;
|
||||
endDate?: Date;
|
||||
hasNoDueDate?: boolean;
|
||||
}
|
||||
|
||||
export const convertDueDateFiltersToRanges = (
|
||||
filters: DueDateFilterKey[],
|
||||
): DueDateFilter[] => {
|
||||
if (!filters.length) return [];
|
||||
|
||||
const today = startOfDay(new Date());
|
||||
const tomorrow = addDays(today, 1);
|
||||
const nextWeekEnd = addDays(today, 8);
|
||||
const nextMonthEnd = addDays(today, 31);
|
||||
|
||||
return filters.map((filter) => {
|
||||
switch (filter) {
|
||||
case "overdue":
|
||||
return {
|
||||
endDate: today,
|
||||
};
|
||||
case "today":
|
||||
return {
|
||||
startDate: today,
|
||||
endDate: endOfDay(today),
|
||||
};
|
||||
case "tomorrow":
|
||||
return {
|
||||
startDate: tomorrow,
|
||||
endDate: endOfDay(tomorrow),
|
||||
};
|
||||
case "next-week": {
|
||||
return {
|
||||
startDate: today,
|
||||
endDate: nextWeekEnd,
|
||||
};
|
||||
}
|
||||
case "next-month": {
|
||||
return {
|
||||
startDate: nextWeekEnd,
|
||||
endDate: nextMonthEnd,
|
||||
};
|
||||
}
|
||||
case "no-due-date":
|
||||
return {
|
||||
hasNoDueDate: true,
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -2,3 +2,4 @@ export * from "./generateUID";
|
||||
export * from "./generateSlug";
|
||||
export * from "./subscriptions";
|
||||
export * from "./email";
|
||||
export * from "./dueDateFilters";
|
||||
|
||||
Reference in New Issue
Block a user