Skip to content

Commit 19c6768

Browse files
fix(api): cleaning code and fixing tests for deleting organization learners feature
1 parent 186048b commit 19c6768

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

api/scripts/prod/delete-organization-learners-from-organization.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ async function deleteOrganizationLearnersFromOrganization(organizationId, date)
2929
await usecases.deleteOrganizationLearners({
3030
organizationLearnerIds: organizationLearnerToDeleteIds,
3131
userId: engineeringUserId,
32+
organizationId,
3233
});
3334

3435
await _anonymizeOrganizationLearners({ organizationId });

api/src/prescription/learner-management/application/organization-learners-controller.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { usecases } from '../domain/usecases/index.js';
66
const deleteOrganizationLearners = async function (request, h) {
77
const authenticatedUserId = request.auth.credentials.userId;
88
const listLearners = request.payload.listLearners;
9+
const organizationId = request.params.id;
910

1011
await DomainTransaction.execute(async () => {
1112
await usecases.deleteOrganizationLearners({
1213
organizationLearnerIds: listLearners,
1314
userId: authenticatedUserId,
15+
organizationId,
1416
});
1517
});
1618
return h.response().code(200);

api/src/prescription/learner-management/domain/usecases/delete-organization-learners.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const deleteOrganizationLearners = async function ({
1111
organizationId,
1212
});
1313

14-
const organizationLearnerList = new OrganizationLearnerList(organizationId, learnersBelogingToOrganization);
14+
const organizationLearnerList = new OrganizationLearnerList({
15+
organizationId,
16+
organizationLearnerIds: learnersBelogingToOrganization,
17+
});
1518

1619
organizationLearnerList.canDeleteOrganizationLearners(organizationLearnerIds);
1720
await campaignParticipationRepository.removeByOrganizationLearnerIds({

api/src/prescription/learner-management/infrastructure/repositories/campaign-participation-repository.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.j
22

33
const learnersBelongingToOrganization = function ({ organizationId }) {
44
const knexConnection = DomainTransaction.getConnection();
5-
return knexConnection('view-active-organization-learners')
6-
.where('organizationId', organizationId)
7-
.select('id')
8-
.pluck('id');
5+
return knexConnection('view-active-organization-learners').where({ organizationId }).select('id').pluck('id');
96
};
107
const removeByOrganizationLearnerIds = function ({ organizationLearnerIds, userId }) {
118
const knexConnection = DomainTransaction.getConnection();

0 commit comments

Comments
 (0)