Skip to content

Commit 4c771bd

Browse files
feat(api): update route and add error mapper
1 parent 49ccdf3 commit 4c771bd

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
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-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.organizationId;
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/application/organization-learners-route.js

+1-1
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()),

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,

0 commit comments

Comments
 (0)