From e66908d5fcba3d021a5d3707e3c91407c3df9b1b Mon Sep 17 00:00:00 2001 From: Alexandre Monney Date: Thu, 21 Nov 2024 18:36:50 +0100 Subject: [PATCH] refactor(api): change id params to named params on campaign-stats-route.js --- .../application/campaign-stats-controller.js | 8 ++++---- .../campaign/application/campaign-stats-route.js | 16 ++++++++-------- .../application/campaign-stats-route_test.js | 8 ++++---- .../application/campaign-stats-route_test.js | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/src/prescription/campaign/application/campaign-stats-controller.js b/api/src/prescription/campaign/application/campaign-stats-controller.js index 5467ad86506..2e8ac01b9be 100644 --- a/api/src/prescription/campaign/application/campaign-stats-controller.js +++ b/api/src/prescription/campaign/application/campaign-stats-controller.js @@ -6,7 +6,7 @@ import * as participationsCountByMasteryRateSerializer from '../infrastructure/s const getParticipationsByStage = async function (request) { const { userId } = request.auth.credentials; - const campaignId = request.params.id; + const { campaignId } = request.params; const participationsByStage = await usecases.getCampaignParticipationsCountByStage({ userId, campaignId }); @@ -18,7 +18,7 @@ const getParticipationsByStage = async function (request) { const getParticipationsByStatus = async function (request) { const { userId } = request.auth.credentials; - const campaignId = request.params.id; + const { campaignId } = request.params; const participantsCounts = await usecases.getCampaignParticipationsCountsByStatus({ userId, campaignId }); @@ -29,7 +29,7 @@ const getParticipationsByStatus = async function (request) { }; const getParticipationsByDay = async function (request) { const { userId } = request.auth.credentials; - const campaignId = request.params.id; + const { campaignId } = request.params; const participantsCounts = await usecases.getCampaignParticipationsActivityByDay({ userId, campaignId }); @@ -41,7 +41,7 @@ const getParticipationsByDay = async function (request) { const getParticipationsCountByMasteryRate = async function (request) { const { userId } = request.auth.credentials; - const campaignId = request.params.id; + const { campaignId } = request.params; const resultDistribution = await usecases.getParticipationsCountByMasteryRate({ userId, campaignId }); diff --git a/api/src/prescription/campaign/application/campaign-stats-route.js b/api/src/prescription/campaign/application/campaign-stats-route.js index db10a9aa1ab..3f731f72b75 100644 --- a/api/src/prescription/campaign/application/campaign-stats-route.js +++ b/api/src/prescription/campaign/application/campaign-stats-route.js @@ -7,10 +7,10 @@ const register = async function (server) { server.route([ { method: 'GET', - path: '/api/campaigns/{id}/stats/participations-by-stage', + path: '/api/campaigns/{campaignId}/stats/participations-by-stage', config: { validate: { - params: Joi.object({ id: identifiersType.campaignId }), + params: Joi.object({ campaignId: identifiersType.campaignId }), }, handler: campaignStatsController.getParticipationsByStage, notes: [ @@ -22,10 +22,10 @@ const register = async function (server) { }, { method: 'GET', - path: '/api/campaigns/{id}/stats/participations-by-status', + path: '/api/campaigns/{campaignId}/stats/participations-by-status', config: { validate: { - params: Joi.object({ id: identifiersType.campaignId }), + params: Joi.object({ campaignId: identifiersType.campaignId }), }, handler: campaignStatsController.getParticipationsByStatus, notes: [ @@ -37,10 +37,10 @@ const register = async function (server) { }, { method: 'GET', - path: '/api/campaigns/{id}/stats/participations-by-day', + path: '/api/campaigns/{campaignId}/stats/participations-by-day', config: { validate: { - params: Joi.object({ id: identifiersType.campaignId }), + params: Joi.object({ campaignId: identifiersType.campaignId }), }, handler: campaignStatsController.getParticipationsByDay, notes: [ @@ -52,10 +52,10 @@ const register = async function (server) { }, { method: 'GET', - path: '/api/campaigns/{id}/stats/participations-by-mastery-rate', + path: '/api/campaigns/{campaignId}/stats/participations-by-mastery-rate', config: { validate: { - params: Joi.object({ id: identifiersType.campaignId }), + params: Joi.object({ campaignId: identifiersType.campaignId }), }, handler: campaignStatsController.getParticipationsCountByMasteryRate, notes: [ diff --git a/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js b/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js index d226af09fcd..919c79c55b1 100644 --- a/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js +++ b/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js @@ -14,7 +14,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { server = await createServer(); }); - describe('GET /api/campaigns/{id}/stats/participations-by-stage', function () { + describe('GET /api/campaigns/{campaignId}/stats/participations-by-stage', function () { it('should return the campaign by id', async function () { // given const learningContentObjects = learningContentBuilder.fromAreas([ @@ -101,7 +101,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { }); }); - describe('GET /api/campaigns/{id}/stats/participations-by-status', function () { + describe('GET /api/campaigns/{campaignId}/stats/participations-by-status', function () { it('should return participations counts by status for the campaign', async function () { // given const campaign = databaseBuilder.factory.buildCampaign(); @@ -140,7 +140,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { }); }); - describe('GET /api/campaigns/{id}/stats/participations-by-day', function () { + describe('GET /api/campaigns/{campaignId}/stats/participations-by-day', function () { it('should return the activity by day', async function () { // given const campaign = databaseBuilder.factory.buildCampaign(); @@ -168,7 +168,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { }); }); - describe('GET /api/campaigns/{id}/stats/participations-by-mastery-rate', function () { + describe('GET /api/campaigns/{campaignId}/stats/participations-by-mastery-rate', function () { it('should return the mastery rate distribution', async function () { const { id: userId } = databaseBuilder.factory.buildUser(); const { id: organizationId } = databaseBuilder.factory.buildOrganization(); diff --git a/api/tests/prescription/campaign/unit/application/campaign-stats-route_test.js b/api/tests/prescription/campaign/unit/application/campaign-stats-route_test.js index 169273fe970..5d1854befae 100644 --- a/api/tests/prescription/campaign/unit/application/campaign-stats-route_test.js +++ b/api/tests/prescription/campaign/unit/application/campaign-stats-route_test.js @@ -3,7 +3,7 @@ import * as moduleUnderTest from '../../../../../src/prescription/campaign/appli import { expect, HttpTestServer, sinon } from '../../../../test-helper.js'; describe('Unit | Application | Router | campaign-router ', function () { - describe('GET /api/campaigns/{id}/stats/participations-by-stage', function () { + describe('GET /api/campaigns/{campaignId}/stats/participations-by-stage', function () { it('should return 200', async function () { // given sinon @@ -32,7 +32,7 @@ describe('Unit | Application | Router | campaign-router ', function () { }); }); - describe('GET /api/campaigns/{id}/stats/participations-by-status', function () { + describe('GET /api/campaigns/{campaignId}/stats/participations-by-status', function () { it('should return 200', async function () { sinon .stub(campaignStatsController, 'getParticipationsByStatus') @@ -58,7 +58,7 @@ describe('Unit | Application | Router | campaign-router ', function () { }); }); - describe('GET /api/campaigns/{id}/stats/participations-by-mastery-rate', function () { + describe('GET /api/campaigns/{campaignId}/stats/participations-by-mastery-rate', function () { beforeEach(function () { sinon .stub(campaignStatsController, 'getParticipationsCountByMasteryRate')