Skip to content

Commit

Permalink
feat(seeds): reset index when creating learners
Browse files Browse the repository at this point in the history
by organizations in seeds

Co-authored-by: Yann Bertrand <[email protected]>
Co-authored-by: Diane Cordier <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent fbe7d0f commit 1729d0f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/db/seeds/data/common/tooling/campaign-tooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function _buildCampaign({
return { realCampaignId, realOrganizationId, realCreatedAt };
}

let emailIndex = 0;
const emailIndexesByOrganizationId = new Map();

function _createAnonymousParticipation(databaseBuilder, organizationId, campaignId, createdAt) {
const createdDate = dayjs(createdAt)
Expand Down Expand Up @@ -541,6 +541,12 @@ function _createAnonymousParticipation(databaseBuilder, organizationId, campaign
async function _createOrRetrieveUsersAndLearners(databaseBuilder, organizationId, requiredParticipantCount) {
const userAndLearnerIds = [];

if (!emailIndexesByOrganizationId.has(organizationId)) {
emailIndexesByOrganizationId.set(organizationId, 0);
}

let emailIndex = emailIndexesByOrganizationId.get(organizationId);

const result = await databaseBuilder
.knex('organizations')
.select('type', 'isManagingStudents')
Expand Down Expand Up @@ -605,6 +611,7 @@ async function _createOrRetrieveUsersAndLearners(databaseBuilder, organizationId
userAndLearnerIds.push({ userId, organizationLearnerId });
emailIndex++;
}
emailIndexesByOrganizationId.set(organizationId, emailIndex);
return userAndLearnerIds;
}

Expand Down

0 comments on commit 1729d0f

Please sign in to comment.