fix: show deleted counts on tab

This commit is contained in:
Ephraim Atta-Duncan
2024-06-13 06:39:43 +00:00
committed by Mythie
parent c6393b7a9e
commit 73e375938c

View File

@ -26,7 +26,7 @@ export const getStats = async ({ user, period, ...options }: GetStatsInput) => {
}; };
} }
const [ownerCounts, notSignedCounts, hasSignedCounts] = await (options.team const [ownerCounts, notSignedCounts, hasSignedCounts, deletedCounts] = await (options.team
? getTeamCounts({ ...options.team, createdAt }) ? getTeamCounts({ ...options.team, createdAt })
: getCounts({ user, createdAt })); : getCounts({ user, createdAt }));
@ -57,6 +57,10 @@ export const getStats = async ({ user, period, ...options }: GetStatsInput) => {
} }
}); });
deletedCounts.forEach((stat) => {
stats[ExtendedDocumentStatus.BIN] += stat._count._all;
});
Object.keys(stats).forEach((key) => { Object.keys(stats).forEach((key) => {
if (key !== ExtendedDocumentStatus.ALL && isExtendedDocumentStatus(key)) { if (key !== ExtendedDocumentStatus.ALL && isExtendedDocumentStatus(key)) {
stats[ExtendedDocumentStatus.ALL] += stats[key]; stats[ExtendedDocumentStatus.ALL] += stats[key];
@ -141,6 +145,20 @@ const getCounts = async ({ user, createdAt }: GetCountsOption) => {
], ],
}, },
}), }),
// Deleted counts.
prisma.document.groupBy({
by: ['status'],
_count: {
_all: true,
},
where: {
userId: user.id,
createdAt,
deletedAt: {
not: null,
},
},
}),
]); ]);
}; };
@ -172,6 +190,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
let notSignedCountsGroupByArgs = null; let notSignedCountsGroupByArgs = null;
let hasSignedCountsGroupByArgs = null; let hasSignedCountsGroupByArgs = null;
let deletedCountsGroupByArgs = null;
if (teamEmail) { if (teamEmail) {
ownerCountsWhereInput = { ownerCountsWhereInput = {
@ -244,6 +263,20 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
], ],
}, },
} satisfies Prisma.DocumentGroupByArgs; } satisfies Prisma.DocumentGroupByArgs;
deletedCountsGroupByArgs = {
by: ['status'],
_count: {
_all: true,
},
where: {
userId: userIdWhereClause,
createdAt,
deletedAt: {
not: null,
},
},
} satisfies Prisma.DocumentGroupByArgs;
} }
return Promise.all([ return Promise.all([
@ -256,5 +289,6 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
}), }),
notSignedCountsGroupByArgs ? prisma.document.groupBy(notSignedCountsGroupByArgs) : [], notSignedCountsGroupByArgs ? prisma.document.groupBy(notSignedCountsGroupByArgs) : [],
hasSignedCountsGroupByArgs ? prisma.document.groupBy(hasSignedCountsGroupByArgs) : [], hasSignedCountsGroupByArgs ? prisma.document.groupBy(hasSignedCountsGroupByArgs) : [],
deletedCountsGroupByArgs ? prisma.document.groupBy(deletedCountsGroupByArgs) : [],
]); ]);
}; };