Skip to content

Commit

Permalink
[TECH] Améliorer la performance de la route de création d'organisatio…
Browse files Browse the repository at this point in the history
…n en masse (PIX-15486).

 #10666
  • Loading branch information
pix-service-auto-merge authored Nov 28, 2024
2 parents 3e4a7f8 + 7b6b7cb commit bf9d2c9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions api/src/prescription/campaign/domain/usecases/create-campaigns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit bf9d2c9

Please sign in to comment.