diff --git a/api/db/seeds/data/common/tooling/campaign-tooling.js b/api/db/seeds/data/common/tooling/campaign-tooling.js index e62c953e077..5afbc237eec 100644 --- a/api/db/seeds/data/common/tooling/campaign-tooling.js +++ b/api/db/seeds/data/common/tooling/campaign-tooling.js @@ -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) @@ -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') @@ -605,6 +611,7 @@ async function _createOrRetrieveUsersAndLearners(databaseBuilder, organizationId userAndLearnerIds.push({ userId, organizationLearnerId }); emailIndex++; } + emailIndexesByOrganizationId.set(organizationId, emailIndex); return userAndLearnerIds; } diff --git a/api/db/seeds/data/team-devcomp/build-campaigns.js b/api/db/seeds/data/team-devcomp/build-campaigns.js index 27ca839aa05..0d29405c6a2 100644 --- a/api/db/seeds/data/team-devcomp/build-campaigns.js +++ b/api/db/seeds/data/team-devcomp/build-campaigns.js @@ -1,11 +1,11 @@ -import { SCO_ORGANIZATION_ID, USER_ID_ADMIN_ORGANIZATION } from '../common/constants.js'; +import { USER_ID_ADMIN_ORGANIZATION } from '../common/constants.js'; import { createAssessmentCampaign } from '../common/tooling/campaign-tooling.js'; -import { PIX_EDU_SMALL_TARGET_PROFILE_ID } from './constants.js'; +import { PIX_EDU_SMALL_TARGET_PROFILE_ID, TEAM_DEVCOMP_ORGANIZATION_ID } from './constants.js'; async function _createScoCampaigns(databaseBuilder, trainingIds) { await createAssessmentCampaign({ databaseBuilder, - organizationId: SCO_ORGANIZATION_ID, + organizationId: TEAM_DEVCOMP_ORGANIZATION_ID, ownerId: USER_ID_ADMIN_ORGANIZATION, name: 'PIX+ EDU - SCO - envoi simple', code: 'EDUSIMPLE', @@ -19,7 +19,7 @@ async function _createScoCampaigns(databaseBuilder, trainingIds) { }); await createAssessmentCampaign({ databaseBuilder, - organizationId: SCO_ORGANIZATION_ID, + organizationId: TEAM_DEVCOMP_ORGANIZATION_ID, ownerId: USER_ID_ADMIN_ORGANIZATION, name: 'PIX+ EDU - SCO- envoi multiple', code: 'EDUMULTIP', diff --git a/api/db/seeds/data/team-devcomp/build-organization.js b/api/db/seeds/data/team-devcomp/build-organization.js new file mode 100644 index 00000000000..47238f9455e --- /dev/null +++ b/api/db/seeds/data/team-devcomp/build-organization.js @@ -0,0 +1,25 @@ +import { + FEATURE_COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY_ID, + FEATURE_MULTIPLE_SENDING_ASSESSMENT_ID, + USER_ID_ADMIN_ORGANIZATION, + USER_ID_MEMBER_ORGANIZATION, +} from '../common/constants.js'; +import { organization } from '../common/tooling/index.js'; +import { TEAM_DEVCOMP_ORGANIZATION_ID } from './constants.js'; + +export async function createDevcompOrganization(databaseBuilder) { + await organization.createOrganization({ + databaseBuilder, + organizationId: TEAM_DEVCOMP_ORGANIZATION_ID, + type: 'SCO', + name: 'DevComp', + isManagingStudents: true, + externalId: 'SCO_DEVCOMP', + adminIds: [USER_ID_ADMIN_ORGANIZATION], + memberIds: [USER_ID_MEMBER_ORGANIZATION], + features: [ + { id: FEATURE_COMPUTE_ORGANIZATION_LEARNER_CERTIFICABILITY_ID }, + { id: FEATURE_MULTIPLE_SENDING_ASSESSMENT_ID }, + ], + }); +} diff --git a/api/db/seeds/data/team-devcomp/constants.js b/api/db/seeds/data/team-devcomp/constants.js index 6e7d31f9997..cd4cc695a48 100644 --- a/api/db/seeds/data/team-devcomp/constants.js +++ b/api/db/seeds/data/team-devcomp/constants.js @@ -2,9 +2,12 @@ const DEFAULT_PASSWORD = 'pix123'; const TEAM_DEVCOMP_OFFSET_ID = 8000; -let nextId = TEAM_DEVCOMP_OFFSET_ID; +const nextId = TEAM_DEVCOMP_OFFSET_ID; // TARGET PROFILES -const PIX_EDU_SMALL_TARGET_PROFILE_ID = nextId++; +const PIX_EDU_SMALL_TARGET_PROFILE_ID = nextId; -export { DEFAULT_PASSWORD, PIX_EDU_SMALL_TARGET_PROFILE_ID }; +// ORGANIZATIONS +const TEAM_DEVCOMP_ORGANIZATION_ID = nextId; + +export { DEFAULT_PASSWORD, PIX_EDU_SMALL_TARGET_PROFILE_ID, TEAM_DEVCOMP_ORGANIZATION_ID }; diff --git a/api/db/seeds/data/team-devcomp/data-builder.js b/api/db/seeds/data/team-devcomp/data-builder.js index 11f388a43c3..e0667f4e0e3 100644 --- a/api/db/seeds/data/team-devcomp/data-builder.js +++ b/api/db/seeds/data/team-devcomp/data-builder.js @@ -1,9 +1,11 @@ import { buildCampaigns } from './build-campaigns.js'; +import { createDevcompOrganization } from './build-organization.js'; import { buildTargetProfiles } from './build-target-profiles.js'; import { buildTrainings } from './build-trainings.js'; async function teamDevcompDataBuilder({ databaseBuilder }) { await buildTargetProfiles(databaseBuilder); + await createDevcompOrganization(databaseBuilder); const trainingsIds = await buildTrainings(databaseBuilder); await buildCampaigns(databaseBuilder, trainingsIds); }