From 25bde836130e92f87b5debcefe361c572652ba37 Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Wed, 18 Dec 2024 15:40:59 +0100 Subject: [PATCH] feat(orga): added attribute campaignParticipationId in repository and in save method --- .../repositories/knowledge-element-snapshot-repository.js | 3 ++- .../repositories/campaign-participation-repository.js | 1 + .../knowledge-element-snapshot-repository_test.js | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js b/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js index cc86d529eee..54e6a907759 100644 --- a/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js +++ b/api/lib/infrastructure/repositories/knowledge-element-snapshot-repository.js @@ -18,13 +18,14 @@ function _toKnowledgeElementCollection({ snapshot } = {}) { ); } -const save = async function ({ userId, snappedAt, knowledgeElements }) { +const save = async function ({ userId, snappedAt, knowledgeElements, campaignParticipationId }) { try { const knexConn = DomainTransaction.getConnection(); return await knexConn('knowledge-element-snapshots').insert({ userId, snappedAt, snapshot: JSON.stringify(knowledgeElements), + campaignParticipationId, }); } catch (error) { if (knexUtils.isUniqConstraintViolated(error)) { diff --git a/api/src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js b/api/src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js index 84d4dbe7bbf..0d4cea31655 100644 --- a/api/src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js +++ b/api/src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js @@ -37,6 +37,7 @@ const updateWithSnapshot = async function (campaignParticipation) { userId: campaignParticipation.userId, snappedAt: campaignParticipation.sharedAt, knowledgeElements, + campaignParticipationId: campaignParticipation.id, }); }; diff --git a/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js b/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js index d686036b840..6af3f5eac45 100644 --- a/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js +++ b/api/tests/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js @@ -10,19 +10,22 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi // given const snappedAt = new Date('2019-04-01'); const userId = databaseBuilder.factory.buildUser().id; + const campaignParticipationId = databaseBuilder.factory.buildCampaignParticipation().id; const knowledgeElement1 = databaseBuilder.factory.buildKnowledgeElement({ userId, createdAt: new Date('2019-03-01'), + campaignParticipationId, }); const knowledgeElement2 = databaseBuilder.factory.buildKnowledgeElement({ userId, createdAt: new Date('2019-03-01'), + campaignParticipationId, }); const knowledgeElements = [knowledgeElement1, knowledgeElement2]; await databaseBuilder.commit(); // when - await knowledgeElementSnapshotRepository.save({ userId, snappedAt, knowledgeElements }); + await knowledgeElementSnapshotRepository.save({ userId, snappedAt, knowledgeElements, campaignParticipationId }); // then const actualUserSnapshot = await knex.select('*').from('knowledge-element-snapshots').first();