fix: remove cummulative

This commit is contained in:
Ephraim Atta-Duncan
2024-05-21 22:44:44 +00:00
parent c1449e01b1
commit 39e7eb0568
2 changed files with 16 additions and 30 deletions

View File

@ -53,17 +53,13 @@ export const getUserWithAtLeastOneDocumentSignedPerMonth = async () => {
export type GetUserWithDocumentMonthlyGrowth = Array<{
month: string;
count: number;
cume_count: number;
signed_count: number;
cume_signed_count: number;
}>;
type GetUserWithDocumentMonthlyGrowthQueryResult = Array<{
month: Date;
count: bigint;
cume_count: bigint;
signed_count: bigint;
cume_signed_count: bigint;
}>;
export const getUserWithSignedDocumentMonthlyGrowth = async () => {
@ -71,9 +67,7 @@ export const getUserWithSignedDocumentMonthlyGrowth = async () => {
SELECT
DATE_TRUNC('month', "Document"."createdAt") AS "month",
COUNT(DISTINCT "Document"."userId") as "count",
SUM(COUNT(DISTINCT "Document"."userId")) OVER (ORDER BY DATE_TRUNC('month', "Document"."createdAt")) as "cume_count",
COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END) as "signed_count",
SUM(COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END)) OVER (ORDER BY DATE_TRUNC('month', "Document"."createdAt")) as "cume_signed_count"
COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END) as "signed_count"
FROM "Document"
GROUP BY "month"
ORDER BY "month" DESC
@ -83,8 +77,6 @@ export const getUserWithSignedDocumentMonthlyGrowth = async () => {
return result.map((row) => ({
month: DateTime.fromJSDate(row.month).toFormat('yyyy-MM'),
count: Number(row.count),
cume_count: Number(row.cume_count),
signed_count: Number(row.signed_count),
cume_signed_count: Number(row.cume_signed_count),
}));
};