Skip to content

Commit

Permalink
tech(api): migrate reconcile manually usecase to prescription context
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car authored Nov 21, 2024
1 parent 103543b commit c51af8a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 58 deletions.
17 changes: 16 additions & 1 deletion api/src/prescription/learner-management/domain/usecases/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import * as obfuscationService from '../../../../../lib/domain/services/obfuscation-service.js';
import * as userReconciliationService from '../../../../../lib/domain/services/user-reconciliation-service.js';
import * as campaignRepository from '../../../../../lib/infrastructure/repositories/campaign-repository.js';
import * as libOrganizationLearnerRepository from '../../../../../lib/infrastructure/repositories/organization-learner-repository.js';
import * as userRepository from '../../../../identity-access-management/infrastructure/repositories/user.repository.js';
import * as organizationFeatureApi from '../../../../organizational-entities/application/api/organization-features-api.js';
import { logErrorWithCorrelationIds } from '../../../../shared/infrastructure/monitoring-tools.js';
import * as organizationRepository from '../../../../shared/infrastructure/repositories/organization-repository.js';
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js';
import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js';
import { logger } from '../../../../shared/infrastructure/utils/logger.js';
import * as membershipRepository from '../../../../team/infrastructure/repositories/membership.repository.js';
import * as registrationOrganizationLearnerRepository from '../../../organization-learner/infrastructure/repositories/registration-organization-learner-repository.js';
import * as campaignParticipationRepository from '../../infrastructure/repositories/campaign-participation-repository.js';
import { repositories } from '../../infrastructure/repositories/index.js';
import { importOrganizationLearnersJobRepository } from '../../infrastructure/repositories/jobs/import-organization-learners-job-repository.js';
Expand All @@ -18,6 +22,7 @@ import { validateOrganizationImportFileJobRepository } from '../../infrastructur
import * as organizationImportRepository from '../../infrastructure/repositories/organization-import-repository.js';
import * as organizationLearnerImportFormatRepository from '../../infrastructure/repositories/organization-learner-import-format-repository.js';
import * as organizationLearnerRepository from '../../infrastructure/repositories/organization-learner-repository.js';
import * as studentRepository from '../../infrastructure/repositories/student-repository.js';
import * as supOrganizationLearnerRepository from '../../infrastructure/repositories/sup-organization-learner-repository.js';
import { importStorage } from '../../infrastructure/storage/import-storage.js';

Expand All @@ -27,17 +32,22 @@ import { importStorage } from '../../infrastructure/storage/import-storage.js';
* @typedef {import ('../../infrastructure/repositories/jobs/import-organization-learners-job-repository.js')} ImportOrganizationLearnersJobRepository
* @typedef {import ('../../infrastructure/storage/import-storage.js')} ImportStorage
* @typedef {import ('../../infrastructure/repositories/jobs/import-sup-organization-learners-job-repository.js')} ImportSupOrganizationLearnersJobRepository
* @typedef {import ('../../../../../lib/infrastructure/repositories/organization-learner-repository.js')} libOrganizationLearnerRepository
* @typedef {import ('../../../../shared/infrastructure/monitoring-tools.js')} LogErrorWithCorrelationIds
* @typedef {import ('../../../../shared/infrastructure/utils/logger.js')} Loggger
* @typedef {import ('../../../../shared/infrastructure/utils/logger.js')} loggger
* @typedef {import ('../../../../team/infrastructure/repositories/membership-repository.js')} MembershipRepository
* @typedef {import ('../../../../../lib/domain/services/obfuscation-service.js')} obfuscationService
* @typedef {import ('../../../../organizational-entities/application/api/organization-features-api.js')} OrganizationFeatureApi
* @typedef {import ('../../infrastructure/repositories/organization-feature-repository.js')} OrganizationFeatureRepository
* @typedef {import ('../../infrastructure/repositories/organization-import-repository.js')} OrganizationImportRepository
* @typedef {import ('../../infrastructure/repositories/organization-learner-import-format-repository.js')} OrganizationLearnerImportFormatRepository
* @typedef {import ('../../infrastructure/repositories/organization-learner-repository.js')} OrganizationLearnerRepository
* @typedef {import ('../../../../shared/infrastructure/repositories/organization-repository.js')} OrganizationRepository
* @typedef {import('../../../organization-learner/infrastructure/repositories/registration-organization-learner-repository.js')} registrationOrganizationLearnerRepository
* @typedef {import ('../../infrastructure/repositories/student-repository.js')} studentRepository
* @typedef {import ('../../infrastructure/repositories/sup-organization-learner-repository.js')} SupOrganizationLearnerRepository
* @typedef {import ('../../../../../lib/domain/services/user-reconciliation-service.js')} UserReconciliationService
* @typedef {import('../../../../identity-access-management/infrastructure/repositories/user.repository.js')} userRepository
* @typedef {import ('../../infrastructure/repositories/jobs/validate-organization-learners-import-file-job-repository.js')} ValidateOrganizationImportFileJobRepository
*/
const dependencies = {
Expand All @@ -46,17 +56,22 @@ const dependencies = {
importOrganizationLearnersJobRepository,
importStorage,
importSupOrganizationLearnersJobRepository,
libOrganizationLearnerRepository,
logErrorWithCorrelationIds,
logger,
membershipRepository,
obfuscationService,
organizationFeatureApi,
organizationFeatureRepository: repositories.organizationFeatureRepository,
organizationImportRepository,
organizationLearnerImportFormatRepository,
organizationLearnerRepository,
organizationRepository,
registrationOrganizationLearnerRepository,
studentRepository,
supOrganizationLearnerRepository,
userReconciliationService,
userRepository,
validateOrganizationImportFileJobRepository,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import lodash from 'lodash';

import { STUDENT_RECONCILIATION_ERRORS } from '../../../src/shared/domain/constants.js';
import { STUDENT_RECONCILIATION_ERRORS } from '../../../../shared/domain/constants.js';
import {
CampaignCodeError,
OrganizationLearnerAlreadyLinkedToUserError,
UserShouldNotBeReconciledOnAnotherAccountError,
} from '../../../src/shared/domain/errors.js';
} from '../../../../shared/domain/errors.js';

const { isEmpty } = lodash;

Expand All @@ -14,8 +14,8 @@ const reconcileScoOrganizationLearnerManually = async function ({
reconciliationInfo,
withReconciliation,
campaignRepository,
libOrganizationLearnerRepository,
organizationLearnerRepository,
prescriptionOrganizationLearnerRepository,
registrationOrganizationLearnerRepository,
studentRepository,
userRepository,
Expand All @@ -31,7 +31,7 @@ const reconcileScoOrganizationLearnerManually = async function ({
await userReconciliationService.findMatchingOrganizationLearnerForGivenOrganizationIdAndReconciliationInfo({
organizationId: campaign.organizationId,
reconciliationInfo,
organizationLearnerRepository,
organizationLearnerRepository: libOrganizationLearnerRepository,
});

await userReconciliationService.assertStudentHasAnAlreadyReconciledAccount(
Expand All @@ -50,11 +50,11 @@ const reconcileScoOrganizationLearnerManually = async function ({
await _checkIfUserIsConnectedOnAnotherAccount({
organizationLearnerOfUserAccessingCampaign,
authenticatedUserId: reconciliationInfo.id,
organizationLearnerRepository,
libOrganizationLearnerRepository,
});

if (withReconciliation) {
return prescriptionOrganizationLearnerRepository.reconcileUserToOrganizationLearner({
return organizationLearnerRepository.reconcileUserToOrganizationLearner({
userId: reconciliationInfo.id,
organizationLearnerId: organizationLearnerOfUserAccessingCampaign.id,
});
Expand Down Expand Up @@ -86,9 +86,9 @@ async function _checkIfAnotherStudentIsAlreadyReconciledWithTheSameOrganizationA
async function _checkIfUserIsConnectedOnAnotherAccount({
organizationLearnerOfUserAccessingCampaign,
authenticatedUserId,
organizationLearnerRepository,
libOrganizationLearnerRepository,
}) {
const loggedAccountReconciledOrganizationLearners = await organizationLearnerRepository.findByUserId({
const loggedAccountReconciledOrganizationLearners = await libOrganizationLearnerRepository.findByUserId({
userId: authenticatedUserId,
});

Expand Down
Loading

0 comments on commit c51af8a

Please sign in to comment.