Skip to content

Commit

Permalink
feat(api): update batch usecase with external api
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car committed Nov 28, 2024
1 parent 5b8ff67 commit 6793907
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const addOrganizationFeatureInBatch = withTransaction(
* @param {Object} params.dependencies
* @returns {Promise<void>}
*/
async ({ filePath, organizationFeatureRepository }) => {
async ({ filePath, organizationFeatureRepository, learnersApi }) => {
const stream = createReadStream(filePath);
const buffer = await getDataBuffer(stream);

Expand All @@ -53,6 +53,11 @@ export const addOrganizationFeatureInBatch = withTransaction(
throw new FeatureParamsNotProcessable();
}
});

data.forEach(async ({ organizationId }) => {
await learnersApi.deleteOrganizationLearnerBeforeImportFeature({ organizationId });
});

return organizationFeatureRepository.saveInBatch(data);
},
);
4 changes: 3 additions & 1 deletion api/src/organizational-entities/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import * as organizationTagRepository from '../../../../lib/infrastructure/repositories/organization-tag-repository.js';
import * as learnersApi from '../../../prescription/learner-management/application/api/learners-api.js';
import * as schoolRepository from '../../../school/infrastructure/repositories/school-repository.js';
import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js';
import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/utils/import-named-exports-from-directory.js';
Expand All @@ -12,10 +13,10 @@ import * as dataProtectionOfficerRepository from '../../infrastructure/repositor
import * as organizationFeatureRepository from '../../infrastructure/repositories/organization-feature-repository.js';
import { organizationForAdminRepository } from '../../infrastructure/repositories/organization-for-admin.repository.js';
import { tagRepository } from '../../infrastructure/repositories/tag.repository.js';

const path = dirname(fileURLToPath(import.meta.url));

/**
* @typedef {import ('../../../prescription/learner-management/application/api/learners-api.js')} learnersApi
* @typedef {import ('../../infrastructure/repositories/certification-center.repository.js')} CertificationCenterRepository
* @typedef {import ('../../infrastructure/repositories/certification-center-for-admin-repository.js')} CertificationCenterForAdminRepository
* @typedef {import ('../../infrastructure/repositories/complementary-certification-habilitation-repository.js')} ComplementaryCertificationHabilitationRepository
Expand All @@ -34,6 +35,7 @@ const repositories = {
organizationForAdminRepository,
organizationFeatureRepository,
schoolRepository,
learnersApi,
organizationTagRepository,
tagRepository,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'

describe('Unit | Organizational Entities | Application | Controller | Admin | organization', function () {
describe('#addOrganizationFeatureInBatch', function () {
let filePath, request;
let filePath, request, userId;

beforeEach(function () {
userId = Symbol('userId');
filePath = Symbol('filePath');
request = { payload: { path: filePath } };
request = { payload: { path: filePath }, auth: { credentials: { userId } } };
sinon.stub(usecases, 'addOrganizationFeatureInBatch').resolves();
});

Expand All @@ -24,6 +25,7 @@ describe('Unit | Organizational Entities | Application | Controller | Admin | or

// then
expect(usecases.addOrganizationFeatureInBatch).to.have.been.calledWithExactly({
userId,
filePath,
});
});
Expand Down

0 comments on commit 6793907

Please sign in to comment.