Skip to content

Commit 3d76fa5

Browse files
fix(api): after review fix
1 parent c2963d5 commit 3d76fa5

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpErrors } from '../../../shared/application/http-errors.js';
2-
import { AggregateImportError } from '../domain/errors.js';
2+
import { AggregateImportError, CouldNotDeleteLearnersError } from '../domain/errors.js';
33

44
const learnerManagementDomainErrorMappingConfiguration = [
55
{
@@ -8,6 +8,12 @@ const learnerManagementDomainErrorMappingConfiguration = [
88
return new HttpErrors.PreconditionFailedError(error.message, error.code, error.meta);
99
},
1010
},
11+
{
12+
name: CouldNotDeleteLearnersError.name,
13+
httpErrorFn: (error) => {
14+
return new HttpErrors.PreconditionFailedError(error.message);
15+
},
16+
},
1117
];
1218

1319
export { learnerManagementDomainErrorMappingConfiguration };

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const register = async (server) => {
2727
],
2828
validate: {
2929
params: Joi.object({
30-
id: identifiersType.organizationId,
30+
organizationId: identifiersType.organizationId,
3131
}),
3232
payload: Joi.object({
3333
listLearners: Joi.array().required().items(Joi.number().required()),
@@ -152,7 +152,7 @@ const register = async (server) => {
152152
handler: organizationLearnersController.dissociate,
153153
validate: {
154154
params: Joi.object({
155-
organizationId: identifiersType.organizationLearnerId,
155+
id: identifiersType.organizationLearnerId,
156156
}),
157157
},
158158
notes: [

api/src/prescription/learner-management/domain/errors.js

+7
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ class ReconcileCommonOrganizationLearnerError extends DomainError {
4141
}
4242
}
4343

44+
class CouldNotDeleteLearnersError extends DomainError {
45+
constructor() {
46+
super(`Could not delete the following organization learners.`);
47+
}
48+
}
49+
4450
export {
4551
AggregateImportError,
52+
CouldNotDeleteLearnersError,
4653
OrganizationDoesNotHaveFeatureEnabledError,
4754
OrganizationLearnerImportFormatNotFoundError,
4855
OrganizationLearnersCouldNotBeSavedError,

api/src/prescription/learner-management/domain/models/OrganizationLearnerList.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { logger } from '../../../../shared/infrastructure/utils/logger.js';
2+
import { CouldNotDeleteLearnersError } from '../errors.js';
23

34
class OrganizationLearnerList {
45
constructor({ organizationId, organizationLearnerIds } = {}) {
@@ -13,7 +14,7 @@ class OrganizationLearnerList {
1314
logger.error(
1415
`User id ${userId} could not delete organization learners because learner id ${result} don't belong to organization id ${this.organizationId} "`,
1516
);
16-
throw new Error('Could not delete organization learners.');
17+
throw new CouldNotDeleteLearnersError();
1718
}
1819
}
1920
}

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ const deleteOrganizationLearners = async function ({
77
organizationLearnerRepository,
88
campaignParticipationRepository,
99
}) {
10-
const learnersBelogingToOrganization = await organizationLearnerRepository.findOrganizationLearnerIdsByOrganizationId(
11-
{
10+
const organizationLearnerIdsFromOrganization =
11+
await organizationLearnerRepository.findOrganizationLearnerIdsByOrganizationId({
1212
organizationId,
13-
},
14-
);
13+
});
1514

1615
const organizationLearnerList = new OrganizationLearnerList({
1716
organizationId,
18-
organizationLearnerIds: learnersBelogingToOrganization,
17+
organizationLearnerIds: organizationLearnerIdsFromOrganization,
1918
});
2019

2120
organizationLearnerList.canDeleteOrganizationLearners(organizationLearnerIds, userId);

api/tests/prescription/learner-management/unit/domain/models/OrganizationLearnerList_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CouldNotDeleteLearnersError } from '../../../../../../src/prescription/learner-management/domain/errors.js';
12
import { OrganizationLearnerList } from '../../../../../../src/prescription/learner-management/domain/models/OrganizationLearnerList.js';
23
import { catchErrSync, expect } from '../../../../../test-helper.js';
34

@@ -31,7 +32,7 @@ describe('Unit | Models | OrganizationLearnerListFormat', function () {
3132
userId,
3233
);
3334

34-
expect(result).to.be.instanceof(Error);
35+
expect(result).to.be.instanceof(CouldNotDeleteLearnersError);
3536
});
3637

3738
it('should not throw when lists are identical', function () {

0 commit comments

Comments
 (0)