-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Ne recuperer que les attestations partagées pour le prescri…
- Loading branch information
Showing
19 changed files
with
480 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { REWARD_TYPES } from '../../../../src/quest/domain/constants.js'; | |
import { COMPARISON } from '../../../../src/quest/domain/models/Quest.js'; | ||
import { Assessment, CampaignParticipationStatuses } from '../../../../src/shared/domain/models/index.js'; | ||
import { temporaryStorage } from '../../../../src/shared/infrastructure/temporary-storage/index.js'; | ||
import { AEFE_TAG, FEATURE_ATTESTATIONS_MANAGEMENT_ID } from '../common/constants.js'; | ||
import { AEFE_TAG, FEATURE_ATTESTATIONS_MANAGEMENT_ID, USER_ID_ADMIN_ORGANIZATION } from '../common/constants.js'; | ||
import { TARGET_PROFILE_BADGES_STAGES_ID } from './constants.js'; | ||
|
||
const profileRewardTemporaryStorage = temporaryStorage.withPrefix('profile-rewards:'); | ||
|
@@ -81,7 +81,7 @@ const buildOrganization = (databaseBuilder) => databaseBuilder.factory.buildOrga | |
const buildOrganizationLearners = (databaseBuilder, organization, users) => | ||
users.map((user) => | ||
databaseBuilder.factory.buildOrganizationLearner({ | ||
userId: user.id, | ||
...user, | ||
organizationId: organization.id, | ||
}), | ||
); | ||
|
@@ -199,6 +199,14 @@ export const buildQuests = async (databaseBuilder) => { | |
|
||
const organization = buildOrganization(databaseBuilder); | ||
|
||
// Add [email protected] as Admin in organization | ||
|
||
databaseBuilder.factory.buildMembership({ | ||
organizationId: organization.id, | ||
organizationRole: 'ADMIN', | ||
userId: USER_ID_ADMIN_ORGANIZATION, | ||
}); | ||
|
||
// Associate attestation feature to organization | ||
|
||
databaseBuilder.factory.buildOrganizationFeature({ | ||
|
@@ -212,18 +220,25 @@ export const buildQuests = async (databaseBuilder) => { | |
|
||
// Create organizationLearners | ||
|
||
const organizationLearnersData = [ | ||
{ userId: successUser.id, division: '6emeA', firstName: 'attestation-success', lastName: 'attestation-success' }, | ||
{ | ||
userId: successSharedUser.id, | ||
division: '6emeA', | ||
firstName: 'attestation-success-shared', | ||
lastName: 'attestation-success-shared', | ||
}, | ||
{ userId: failedUser.id, division: '6emeA', firstName: 'attestation-failed', lastName: 'attestation-failed' }, | ||
{ userId: pendingUser.id, division: '6emeB', firstName: 'attestation-pending', lastName: 'attestation-pending' }, | ||
{ userId: blankUser.id, division: '6emeB', firstName: 'attestation-blank', lastName: 'attestation-blank' }, | ||
]; | ||
|
||
const [ | ||
successOrganizationLearner, | ||
successSharedOrganizationLearner, | ||
failedOrganizationLearner, | ||
pendingOrganizationLearner, | ||
] = buildOrganizationLearners(databaseBuilder, organization, [ | ||
successUser, | ||
successSharedUser, | ||
failedUser, | ||
pendingUser, | ||
blankUser, | ||
]); | ||
] = buildOrganizationLearners(databaseBuilder, organization, organizationLearnersData); | ||
|
||
// Create target profile | ||
|
||
|
13 changes: 10 additions & 3 deletions
13
api/src/prescription/organization-learner/application/organization-learners-controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class OrganizationProfileReward { | ||
constructor({ organizationId, profileRewardId }) { | ||
this.profileRewardId = profileRewardId; | ||
this.organizationId = organizationId; | ||
} | ||
} | ||
|
||
export { OrganizationProfileReward }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
api/src/profile/domain/usecases/get-shared-attestations-for-organization-by-user-ids.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { AttestationNotFoundError, NoProfileRewardsFoundError } from '../errors.js'; | ||
|
||
export async function getSharedAttestationsForOrganizationByUserIds({ | ||
attestationKey, | ||
userIds, | ||
organizationId, | ||
locale, | ||
userRepository, | ||
profileRewardRepository, | ||
attestationRepository, | ||
organizationProfileRewardRepository, | ||
}) { | ||
const attestationData = await attestationRepository.getByKey({ attestationKey }); | ||
|
||
if (!attestationData) { | ||
throw new AttestationNotFoundError(); | ||
} | ||
|
||
const users = await userRepository.getByIds({ userIds }); | ||
|
||
const sharedProfileRewards = await organizationProfileRewardRepository.getByOrganizationId({ organizationId }); | ||
const profileRewardIds = sharedProfileRewards.map((sharedProfileReward) => sharedProfileReward.profileRewardId); | ||
|
||
const profileRewards = await profileRewardRepository.getByIds({ profileRewardIds }); | ||
const filteredProfileRewards = profileRewards.filter((profileReward) => userIds.includes(profileReward.userId)); | ||
|
||
if (filteredProfileRewards.length === 0) { | ||
throw new NoProfileRewardsFoundError(); | ||
} | ||
|
||
return { | ||
data: filteredProfileRewards.map(({ userId, createdAt }) => { | ||
const user = users.find((user) => user.id === userId); | ||
return user.toForm(createdAt, locale); | ||
}), | ||
templateName: attestationData.templateName, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.