Skip to content

Commit

Permalink
fix(api): cleaning code and fixing tests for deleting organization le…
Browse files Browse the repository at this point in the history
…arners feature
  • Loading branch information
alicegoarnisson committed Nov 14, 2024
1 parent 186048b commit 19c6768
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function deleteOrganizationLearnersFromOrganization(organizationId, date)
await usecases.deleteOrganizationLearners({
organizationLearnerIds: organizationLearnerToDeleteIds,
userId: engineeringUserId,
organizationId,
});

await _anonymizeOrganizationLearners({ organizationId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { usecases } from '../domain/usecases/index.js';
const deleteOrganizationLearners = async function (request, h) {
const authenticatedUserId = request.auth.credentials.userId;
const listLearners = request.payload.listLearners;
const organizationId = request.params.id;

await DomainTransaction.execute(async () => {
await usecases.deleteOrganizationLearners({
organizationLearnerIds: listLearners,
userId: authenticatedUserId,
organizationId,
});
});
return h.response().code(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const deleteOrganizationLearners = async function ({
organizationId,
});

const organizationLearnerList = new OrganizationLearnerList(organizationId, learnersBelogingToOrganization);
const organizationLearnerList = new OrganizationLearnerList({
organizationId,
organizationLearnerIds: learnersBelogingToOrganization,
});

organizationLearnerList.canDeleteOrganizationLearners(organizationLearnerIds);
await campaignParticipationRepository.removeByOrganizationLearnerIds({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.j

const learnersBelongingToOrganization = function ({ organizationId }) {
const knexConnection = DomainTransaction.getConnection();
return knexConnection('view-active-organization-learners')
.where('organizationId', organizationId)
.select('id')
.pluck('id');
return knexConnection('view-active-organization-learners').where({ organizationId }).select('id').pluck('id');
};
const removeByOrganizationLearnerIds = function ({ organizationLearnerIds, userId }) {
const knexConnection = DomainTransaction.getConnection();
Expand Down

0 comments on commit 19c6768

Please sign in to comment.