diff --git a/api/src/prescription/campaign/domain/usecases/create-campaigns.js b/api/src/prescription/campaign/domain/usecases/create-campaigns.js index e1ce8d1ae3b..71ac8d3110a 100644 --- a/api/src/prescription/campaign/domain/usecases/create-campaigns.js +++ b/api/src/prescription/campaign/domain/usecases/create-campaigns.js @@ -8,22 +8,21 @@ const createCampaigns = async function ({ userRepository, organizationRepository, }) { - const enrichedCampaignsData = await Promise.all( - campaignsToCreate.map(async (campaign) => { - await _checkIfOwnerIsExistingUser(userRepository, campaign.ownerId); - await _checkIfOrganizationExists(organizationRepository, campaign.organizationId); + const enrichedCampaignsData = []; + for (const campaign of campaignsToCreate) { + await _checkIfOwnerIsExistingUser(userRepository, campaign.ownerId); + await _checkIfOrganizationExists(organizationRepository, campaign.organizationId); - const generatedCampaignCode = await codeGenerator.generate(campaignAdministrationRepository); - const campaignCreator = await campaignCreatorRepository.get(campaign.organizationId); - - return campaignCreator.createCampaign({ - ...campaign, - type: CampaignTypes.ASSESSMENT, - code: generatedCampaignCode, - }); - }), - ); + const generatedCampaignCode = await codeGenerator.generate(campaignAdministrationRepository); + const campaignCreator = await campaignCreatorRepository.get(campaign.organizationId); + const campaignToCreate = await campaignCreator.createCampaign({ + ...campaign, + type: CampaignTypes.ASSESSMENT, + code: generatedCampaignCode, + }); + enrichedCampaignsData.push(campaignToCreate); + } return campaignAdministrationRepository.save(enrichedCampaignsData); };