Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored and xav-car committed Feb 4, 2025
1 parent 5094199 commit 95015c9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 5 deletions.
33 changes: 32 additions & 1 deletion api/db/seeds/data/team-prescription/build-quests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,39 @@ import {
USER_ID_ADMIN_ORGANIZATION,
USER_ID_MEMBER_ORGANIZATION,
} from '../common/constants.js';
import { TARGET_PROFILE_BADGES_STAGES_ID } from './constants.js';
import { TARGET_PROFILE_BADGES_STAGES_ID, TARGET_PROFILE_NO_BADGES_NO_STAGES_ID } from './constants.js';

const profileRewardTemporaryStorage = temporaryStorage.withPrefix('profile-rewards:');

function buildParenthoodQuest(databaseBuilder) {
const { id: rewardId } = databaseBuilder.factory.buildAttestation({
templateName: 'parenthood-attestation-template',
key: ATTESTATIONS.PARENTHOOD,
});

const targetProfileId = TARGET_PROFILE_NO_BADGES_NO_STAGES_ID;
databaseBuilder.factory.buildQuest({
rewardType: REWARD_TYPES.ATTESTATION,
rewardId,
eligibilityRequirements: [
{
type: TYPES.CAMPAIGN_PARTICIPATIONS,
data: {
targetProfileIds: [targetProfileId],
},
},
],
successRequirements: [
{
type: SUCCESS_TYPES.ASSESSMENT,
data: {
state: Assessment.states.COMPLETED,
},
},
],
});
}

const USERS = [
{
firstName: 'attestation-success',
Expand Down Expand Up @@ -442,4 +471,6 @@ export const buildQuests = async (databaseBuilder) => {
organizationId: SCO_ORGANIZATION_ID,
profileRewardId: otherUserProfileRewardId,
});

buildParenthoodQuest(databaseBuilder);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const save = async function (request, h, dependencies = { answerSerializer, requ
!config.featureToggles.isAsyncQuestRewardingCalculationEnabled &&
config.featureToggles.isQuestEnabled
) {
await questUsecases.rewardUser({ userId });
await questUsecases.rewardUser({ userId, assessmentId: answer.assessment.id });
}

return h.response(dependencies.answerSerializer.serialize(createdAnswer)).created();
Expand Down
1 change: 1 addition & 0 deletions api/src/profile/domain/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const ATTESTATIONS = {
SIXTH_GRADE: 'SIXTH_GRADE',
PARENTHOOD: 'PARENTHOOD',
};
Binary file not shown.
1 change: 1 addition & 0 deletions api/src/quest/domain/models/Eligibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Eligibility {
get campaignParticipations() {
return {
targetProfileIds: this.#campaignParticipations.map(({ targetProfileId }) => targetProfileId),
statuses: this.#campaignParticipations.map(({ status }) => status),
};
}

Expand Down
4 changes: 4 additions & 0 deletions api/src/quest/domain/models/Quest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Quest {
if (Array.isArray(criterion)) {
return criterion.every((valueToTest) => eligibilityData.includes(valueToTest));
}
if (typeof criterion === 'object') {
const comparaisonFunction = criterion.comparison === COMPARISON.ONE_OF ? 'some' : 'every';
return criterion[comparaisonFunction]((valueToTest) => eligibilityData.includes(valueToTest));
}
return eligibilityData === criterion;
});
}
Expand Down
5 changes: 4 additions & 1 deletion api/src/quest/domain/usecases/reward-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const rewardUser = async ({
continue;
}

const success = await successRepository.find({ userId, skillIds: quest.successRequirements[0].data.ids });
const success = await successRepository.find({
userId,
skillIds: quest.successRequirements[0].data.ids,
});
const userHasSucceedQuest = quest.isSuccessful(success);

if (userHasSucceedQuest) {
Expand Down
8 changes: 6 additions & 2 deletions api/tests/quest/unit/domain/models/Quest_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,20 @@ describe('Quest | Unit | Domain | Models | Quest ', function () {
comparison: COMPARISON.ONE_OF,
},
{
type: TYPES.ORGANIZATION_LEARNER,
type: TYPES.ORGANIZATION_LEARNER, // Object
data: {
MEFCode: '10010012110',
},
comparison: COMPARISON.ALL,
},
{
type: TYPES.CAMPAIGN_PARTICIPATIONS,
type: TYPES.CAMPAIGN_PARTICIPATIONS, // Array
data: {
targetProfileIds: [eligibleTargetProfileId],
statuses: {
value: ['TO_SHARE', 'SHARED'],
comparison: COMPARISON.ONE_OF,
},
},
comparison: COMPARISON.ALL,
},
Expand Down

0 comments on commit 95015c9

Please sign in to comment.