mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
feat: rework document table filters
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
import { TeamMemberRole } from '@prisma/client';
|
||||
import type { Prisma, User } from '@prisma/client';
|
||||
import { SigningStatus } from '@prisma/client';
|
||||
import { DocumentVisibility } from '@prisma/client';
|
||||
import { DocumentVisibility, SigningStatus, TeamMemberRole } from '@prisma/client';
|
||||
import { DateTime } from 'luxon';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
@ -27,13 +25,60 @@ export const getStats = async ({
|
||||
}: GetStatsInput) => {
|
||||
let createdAt: Prisma.DocumentWhereInput['createdAt'];
|
||||
|
||||
if (period) {
|
||||
const daysAgo = parseInt(period.replace(/d$/, ''), 10);
|
||||
if (period && period !== 'all-time') {
|
||||
const now = DateTime.now();
|
||||
let startDate: DateTime;
|
||||
let endDate: DateTime;
|
||||
|
||||
const startOfPeriod = DateTime.now().minus({ days: daysAgo }).startOf('day');
|
||||
switch (period) {
|
||||
case 'today':
|
||||
startDate = now.startOf('day');
|
||||
endDate = now.endOf('day');
|
||||
break;
|
||||
case 'yesterday':
|
||||
startDate = now.minus({ days: 1 }).startOf('day');
|
||||
endDate = now.minus({ days: 1 }).endOf('day');
|
||||
break;
|
||||
case 'this-week':
|
||||
startDate = now.startOf('week');
|
||||
endDate = now.endOf('week');
|
||||
break;
|
||||
case 'last-week':
|
||||
startDate = now.minus({ weeks: 1 }).startOf('week');
|
||||
endDate = now.minus({ weeks: 1 }).endOf('week');
|
||||
break;
|
||||
case 'this-month':
|
||||
startDate = now.startOf('month');
|
||||
endDate = now.endOf('month');
|
||||
break;
|
||||
case 'last-month':
|
||||
startDate = now.minus({ months: 1 }).startOf('month');
|
||||
endDate = now.minus({ months: 1 }).endOf('month');
|
||||
break;
|
||||
case 'this-quarter':
|
||||
startDate = now.startOf('quarter');
|
||||
endDate = now.endOf('quarter');
|
||||
break;
|
||||
case 'last-quarter':
|
||||
startDate = now.minus({ quarters: 1 }).startOf('quarter');
|
||||
endDate = now.minus({ quarters: 1 }).endOf('quarter');
|
||||
break;
|
||||
case 'this-year':
|
||||
startDate = now.startOf('year');
|
||||
endDate = now.endOf('year');
|
||||
break;
|
||||
case 'last-year':
|
||||
startDate = now.minus({ years: 1 }).startOf('year');
|
||||
endDate = now.minus({ years: 1 }).endOf('year');
|
||||
break;
|
||||
default:
|
||||
startDate = now.startOf('day');
|
||||
endDate = now.endOf('day');
|
||||
}
|
||||
|
||||
createdAt = {
|
||||
gte: startOfPeriod.toJSDate(),
|
||||
gte: startDate.toJSDate(),
|
||||
lte: endDate.toJSDate(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user