Skip to content

Commit

Permalink
change announcement metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
goemen committed Sep 13, 2024
1 parent 247fa95 commit 5fb9f3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 5 additions & 1 deletion backend/src/v1/services/dashboard-metrics-service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

describe('dashboard-metrics-service', () => {
describe('getDashboardMetrics', () => {
it('should return the dashboard metrics', async () => {
Expand All @@ -8,7 +9,10 @@ describe('dashboard-metrics-service', () => {
const reportsCount = 3;
const prismaMock = {
announcement: {
count: jest.fn().mockResolvedValueOnce(publishedAnnouncements).mockResolvedValueOnce(draftAnnouncements),
groupBy: jest.fn().mockResolvedValueOnce([
{ status: 'PUBLISHED', _count: publishedAnnouncements },
{ status: 'DRAFT', _count: draftAnnouncements },
]),
},
pay_transparency_report: {
count: jest.fn().mockResolvedValueOnce(reportsCount),
Expand Down
24 changes: 10 additions & 14 deletions backend/src/v1/services/dashboard-metrics-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,24 @@ interface IGetDashboardMetricsInput {
export const getDashboardMetrics = async ({
reportingYear,
}: IGetDashboardMetricsInput) => {
const publishedAnnouncements = await prisma.announcement.count({
where: {
status: 'PUBLISHED',
},
});

const draftAnnouncements = await prisma.announcement.count({
where: {
status: 'DRAFT',
},
const announcementsData = await prisma.announcement.groupBy({
where: { status: { in: ['PUBLISHED', 'DRAFT'] } },
by: ['status'],
_count: true,
});

const announcementsMetrics = announcementsData.reduce((acc, curr) => {
const key = curr.status.toLowerCase();
return { ...acc, [key]: curr._count };
}, {});

const reportsCount = await prisma.pay_transparency_report.count({
where: {
reporting_year: reportingYear,
},
});
return {
announcements: {
published: publishedAnnouncements,
draft: draftAnnouncements,
},
announcements: announcementsMetrics,
reports: {
count: reportsCount,
},
Expand Down

0 comments on commit 5fb9f3e

Please sign in to comment.