From 918c63ba025364826d59599e77fbe31beee28be4 Mon Sep 17 00:00:00 2001 From: Cherik Date: Tue, 5 Nov 2024 12:14:51 +0330 Subject: [PATCH] add count of vouches with comment --- src/server-extension/organization-resolver.ts | 9 ++++++++- src/server-extension/types.ts | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/server-extension/organization-resolver.ts b/src/server-extension/organization-resolver.ts index 29c2bf1..bd27536 100644 --- a/src/server-extension/organization-resolver.ts +++ b/src/server-extension/organization-resolver.ts @@ -116,7 +116,8 @@ export class OrganisationResolver { const query = ` SELECT attestor_organisation.attestor_id AS attestor_id, - COUNT(*) AS total_count + COUNT(*) AS total_count, + SUM(CASE WHEN project_attestation.comment IS NOT NULL AND project_attestation.comment != '' THEN 1 ELSE 0 END) AS count_with_comments FROM project_attestation JOIN attestor_organisation @@ -139,18 +140,24 @@ export class OrganisationResolver { const result = await manager.query(query, params); let totalVouches = 0; + let totalWithComments = 0; const vouchCountByUser: VouchCountByUser[] = result.map((row: any) => { const totalCount = Number(row.total_count); + const countWithComments = Number(row.count_with_comments); + totalVouches += totalCount; + totalWithComments += countWithComments; return { attestorId: row.attestor_id, totalCount, + countWithComments, }; }); return { totalVouches, + totalWithComments, vouchCountByUser, }; } catch (error: any) { diff --git a/src/server-extension/types.ts b/src/server-extension/types.ts index 1c76316..a1c332b 100644 --- a/src/server-extension/types.ts +++ b/src/server-extension/types.ts @@ -46,6 +46,9 @@ export class VouchCountByUser { @Field(() => Int) totalCount: number = 0; + + @Field(() => Int) + countWithComments: number = 0; } @ObjectType() @@ -53,6 +56,9 @@ export class VouchCountByUserResult { @Field(() => Int) totalVouches: number = 0; + @Field(() => Int) + totalWithComments: number = 0; + @Field(() => [VouchCountByUser]) vouchCountByUser: VouchCountByUser[] = []; }