From 874cae4ea4648aea8f8ad9adb6e044585e947e6b Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Wed, 18 Dec 2024 15:26:47 +0100 Subject: [PATCH] feat(orga): added campaignParticipationId attribute / column in shared, lib and scripts --- .../repositories/knowledge-element-snapshot-repository.js | 3 ++- .../generate-knowledge-element-snapshots-for-campaigns.js | 7 ++++++- .../CampaignParticipationKnowledgeElementSnapshots.js | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js b/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js index a314a63ca43..cc86d529eee 100644 --- a/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js +++ b/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js @@ -78,7 +78,7 @@ const findMultipleUsersFromUserIdsAndSnappedAtDates = async function (userIdsAnd }); const results = await knex - .select('userId', 'snapshot', 'snappedAt') + .select('userId', 'snapshot', 'snappedAt', 'campaignParticipationId') .from('knowledge-element-snapshots') .whereIn(['knowledge-element-snapshots.userId', 'snappedAt'], params); @@ -89,6 +89,7 @@ const findMultipleUsersFromUserIdsAndSnappedAtDates = async function (userIdsAnd userId: result.userId, snappedAt: result.snappedAt, knowledgeElements: mappedKnowledgeElements, + campaignParticipationId: result.campaignParticipationId, }); }); }; diff --git a/api/scripts/prod/generate-knowledge-element-snapshots-for-campaigns.js b/api/scripts/prod/generate-knowledge-element-snapshots-for-campaigns.js index ba3c5838b82..c18f92382d9 100644 --- a/api/scripts/prod/generate-knowledge-element-snapshots-for-campaigns.js +++ b/api/scripts/prod/generate-knowledge-element-snapshots-for-campaigns.js @@ -77,7 +77,12 @@ async function generateKnowledgeElementSnapshots( limitDate: sharedAt, }); try { - await dependencies.knowledgeElementSnapshotRepository.save({ userId, snappedAt: sharedAt, knowledgeElements }); + await dependencies.knowledgeElementSnapshotRepository.save({ + userId, + snappedAt: sharedAt, + knowledgeElements, + campainParticipationId: campaignParticipation.id, + }); } catch (err) { if (!(err instanceof AlreadyExistingEntityError)) { throw err; diff --git a/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js b/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js index e7b65784608..f850352289d 100644 --- a/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js +++ b/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js @@ -1,8 +1,9 @@ class CampaignParticipationKnowledgeElementSnapshots { - constructor({ userId, snappedAt, knowledgeElements } = {}) { + constructor({ userId, snappedAt, knowledgeElements, campaignParticipationId } = {}) { this.userId = userId; this.snappedAt = snappedAt; this.knowledgeElements = knowledgeElements; + this.campaginParticipationId = campaignParticipationId; } }