Skip to content

Commit

Permalink
feat(api): update route and add error mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
alicegoarnisson committed Nov 15, 2024
1 parent 49ccdf3 commit 4c771bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpErrors } from '../../../shared/application/http-errors.js';
import { AggregateImportError } from '../domain/errors.js';
import { AggregateImportError, CouldNotDeleteLearnersError } from '../domain/errors.js';

const learnerManagementDomainErrorMappingConfiguration = [
{
Expand All @@ -8,6 +8,12 @@ const learnerManagementDomainErrorMappingConfiguration = [
return new HttpErrors.PreconditionFailedError(error.message, error.code, error.meta);
},
},
{
name: CouldNotDeleteLearnersError.name,
httpErrorFn: (error) => {
return new HttpErrors.PreconditionFailedError(error.message);
},
},
];

export { learnerManagementDomainErrorMappingConfiguration };
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.organizationId;

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 @@ -27,7 +27,7 @@ const register = async (server) => {
],
validate: {
params: Joi.object({
id: identifiersType.organizationId,
organizationId: identifiersType.organizationId,
}),
payload: Joi.object({
listLearners: Joi.array().required().items(Joi.number().required()),
Expand Down
7 changes: 7 additions & 0 deletions api/src/prescription/learner-management/domain/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ class ReconcileCommonOrganizationLearnerError extends DomainError {
}
}

class CouldNotDeleteLearnersError extends DomainError {
constructor() {
super(`Could not delete the following organization learners.`);
}
}

export {
AggregateImportError,
CouldNotDeleteLearnersError,
OrganizationDoesNotHaveFeatureEnabledError,
OrganizationLearnerImportFormatNotFoundError,
OrganizationLearnersCouldNotBeSavedError,
Expand Down

0 comments on commit 4c771bd

Please sign in to comment.