Skip to content

Commit 638e233

Browse files
alicegoarnissonxav-car
authored andcommitted
feat(api): update route and add error mapper
1 parent 7fa587e commit 638e233

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const register = async (server) => {
1313
server.route([
1414
{
1515
method: 'DELETE',
16-
path: '/api/organizations/{id}/organization-learners',
16+
path: '/api/organizations/{organizationId}/organization-learners',
1717
config: {
1818
pre: [
1919
{
@@ -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,

api/src/shared/application/security-pre-handlers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ async function checkUserDoesNotBelongsToScoOrganizationManagingStudents(
468468
return _replyForbiddenError(h);
469469
}
470470

471-
const organizationId = request.params.id;
471+
const organizationId = request.params.organizationId || request.params.id;
472472

473473
const isOrganizationScoManagingStudent = await dependencies.checkOrganizationIsScoAndManagingStudentUsecase.execute({
474474
organizationId,

api/tests/prescription/learner-management/integration/application/organization-learners-route_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../../../../test-helper.js';
1111

1212
describe('Integration | Application | Organization Learners Management | Routes', function () {
13-
describe('DELETE /organizations/{id}/organization-learners', function () {
13+
describe('DELETE /organizations/{organizationId}/organization-learners', function () {
1414
const method = 'DELETE';
1515

1616
let headers, httpTestServer, organizationId, url, payload;

0 commit comments

Comments
 (0)