diff --git a/api/src/team/domain/read-models/Prescriber.js b/api/src/team/domain/read-models/Prescriber.js index fa5e4624775..620d8608797 100644 --- a/api/src/team/domain/read-models/Prescriber.js +++ b/api/src/team/domain/read-models/Prescriber.js @@ -5,6 +5,8 @@ class Prescriber { * firstName: string, * lastName: string, * pixOrgaTermsOfServiceAccepted: boolean, + * pixOrgaTermsOfServiceStatus: string, + * pixOrgaTermsOfServiceDocumentPath: string, * lang: string, * areNewYearOrganizationLearnersImported: boolean, * participantCount: number, diff --git a/api/src/team/infrastructure/repositories/prescriber-repository.js b/api/src/team/infrastructure/repositories/prescriber-repository.js index 61f65fa005e..e0bb7a36a17 100644 --- a/api/src/team/infrastructure/repositories/prescriber-repository.js +++ b/api/src/team/infrastructure/repositories/prescriber-repository.js @@ -25,9 +25,7 @@ const getPrescriber = async function ({ userId, legalDocumentApi }) { service: 'pix-orga', type: 'TOS', }); - user.pixOrgaTermsOfServiceAccepted = pixOrgaLegalDocumentStatus.status == 'accepted'; - user.pixOrgaTermsOfServiceStatus = pixOrgaLegalDocumentStatus.status; - user.pixOrgaTermsOfServiceDocumentPath = pixOrgaLegalDocumentStatus.path; + const memberships = await knex('memberships').where({ userId, disabledAt: null }).orderBy('id'); @@ -44,7 +42,15 @@ const getPrescriber = async function ({ userId, legalDocumentApi }) { const schools = await knex('schools').whereIn('organizationId', organizationIds); - const prescriber = _toPrescriberDomain(user, userOrgaSettings, tags, memberships, organizations, schools); + const prescriber = _toPrescriberDomain({ + user, + pixOrgaLegalDocumentStatus, + userOrgaSettings, + tags, + memberships, + organizations, + schools, + }); const currentOrganizationId = prescriber.userOrgaSettings.currentOrganization.id; prescriber.areNewYearOrganizationLearnersImported = @@ -57,11 +63,23 @@ const getPrescriber = async function ({ userId, legalDocumentApi }) { export const prescriberRepository = { getPrescriber }; -function _toPrescriberDomain(user, userOrgaSettings, tags, memberships, organizations, schools) { +function _toPrescriberDomain({ + user, + pixOrgaLegalDocumentStatus, + userOrgaSettings, + tags, + memberships, + organizations, + schools, +}) { const currentSchool = schools.find((school) => school.organizationId === userOrgaSettings.currentOrganizationId); return new Prescriber({ ...user, + pixOrgaTermsOfServiceAccepted: pixOrgaLegalDocumentStatus.status === 'accepted', + pixOrgaTermsOfServiceStatus: pixOrgaLegalDocumentStatus.status, + pixOrgaTermsOfServiceDocumentPath: pixOrgaLegalDocumentStatus.documentPath, + memberships: memberships.map( (membership) => new Membership({ diff --git a/api/tests/team/integration/infrastructure/repositories/prescriber-repository_test.js b/api/tests/team/integration/infrastructure/repositories/prescriber-repository_test.js index e5c62bd0805..413c6a31674 100644 --- a/api/tests/team/integration/infrastructure/repositories/prescriber-repository_test.js +++ b/api/tests/team/integration/infrastructure/repositories/prescriber-repository_test.js @@ -72,6 +72,8 @@ describe('Integration | Team | Infrastructure | Repository | Prescriber', functi firstName: user.firstName, lastName: user.lastName, pixOrgaTermsOfServiceAccepted: user.pixOrgaTermsOfServiceAccepted, + pixOrgaTermsOfServiceStatus: 'requested', + pixOrgaTermsOfServiceDocumentPath: 'pix-orga-tos-2024-01-02', lang: user.lang, }; }); @@ -83,6 +85,7 @@ describe('Integration | Team | Infrastructure | Repository | Prescriber', functi }); // then + expect(foundPrescriber).to.be.an.instanceOf(Prescriber); expect(foundPrescriber.id).to.equal(expectedPrescriber.id); expect(foundPrescriber.firstName).to.equal(expectedPrescriber.firstName); @@ -90,6 +93,10 @@ describe('Integration | Team | Infrastructure | Repository | Prescriber', functi expect(foundPrescriber.pixOrgaTermsOfServiceAccepted).to.equal( expectedPrescriber.pixOrgaTermsOfServiceAccepted, ); + expect(foundPrescriber.pixOrgaTermsOfServiceStatus).to.equal(expectedPrescriber.pixOrgaTermsOfServiceStatus); + expect(foundPrescriber.pixOrgaTermsOfServiceDocumentPath).to.equal( + expectedPrescriber.pixOrgaTermsOfServiceDocumentPath, + ); expect(foundPrescriber.lang).to.equal(expectedPrescriber.lang); }); diff --git a/api/tests/tooling/domain-builder/factory/build-prescriber.js b/api/tests/tooling/domain-builder/factory/build-prescriber.js index 610382e22a4..fa770eb7dee 100644 --- a/api/tests/tooling/domain-builder/factory/build-prescriber.js +++ b/api/tests/tooling/domain-builder/factory/build-prescriber.js @@ -49,6 +49,8 @@ const buildPrescriber = function ({ firstName = 'Jean', lastName = 'Forme', pixOrgaTermsOfServiceAccepted = false, + pixOrgaTermsOfServiceStatus = 'requested', + pixOrgaTermsOfServiceDocumentPath = 'pix-orga-tos-2024-01-02', lang = 'fr', areNewYearOrganizationLearnersImported = false, memberships = _buildMemberships(), @@ -60,6 +62,8 @@ const buildPrescriber = function ({ firstName, lastName, pixOrgaTermsOfServiceAccepted, + pixOrgaTermsOfServiceStatus, + pixOrgaTermsOfServiceDocumentPath, lang, areNewYearOrganizationLearnersImported, memberships,