Skip to content

Commit

Permalink
add count of vouches with comment
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadPCh committed Nov 5, 2024
1 parent 585ef9c commit 918c63b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/server-extension/organization-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/server-extension/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ export class VouchCountByUser {

@Field(() => Int)
totalCount: number = 0;

@Field(() => Int)
countWithComments: number = 0;
}

@ObjectType()
export class VouchCountByUserResult {
@Field(() => Int)
totalVouches: number = 0;

@Field(() => Int)
totalWithComments: number = 0;

@Field(() => [VouchCountByUser])
vouchCountByUser: VouchCountByUser[] = [];
}

0 comments on commit 918c63b

Please sign in to comment.