Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelleBonnemay authored and P-Jeremy committed Jan 7, 2025
1 parent 4ea4a63 commit 4c785a6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions api/src/team/domain/read-models/Prescriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Prescriber {
* firstName: string,
* lastName: string,
* pixOrgaTermsOfServiceAccepted: boolean,
* pixOrgaTermsOfServiceStatus: string,
* pixOrgaTermsOfServiceDocumentPath: string,
* lang: string,
* areNewYearOrganizationLearnersImported: boolean,
* participantCount: number,
Expand Down
28 changes: 23 additions & 5 deletions api/src/team/infrastructure/repositories/prescriber-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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 =
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
});
Expand All @@ -83,13 +85,18 @@ 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);
expect(foundPrescriber.lastName).to.equal(expectedPrescriber.lastName);
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);
});

Expand Down
4 changes: 4 additions & 0 deletions api/tests/tooling/domain-builder/factory/build-prescriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -60,6 +62,8 @@ const buildPrescriber = function ({
firstName,
lastName,
pixOrgaTermsOfServiceAccepted,
pixOrgaTermsOfServiceStatus,
pixOrgaTermsOfServiceDocumentPath,
lang,
areNewYearOrganizationLearnersImported,
memberships,
Expand Down

0 comments on commit 4c785a6

Please sign in to comment.