Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DTFS2-7733): post cancel amendment #4199

Merged
merged 27 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9be8dec
feat(DTFS2-7730): delete amendment endpoint dtfs-central-api
rkontogianni Jan 27, 2025
b29a4d5
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Jan 27, 2025
d5a78e8
feat(DTFS2-7730): fix delete amentment endpoint
rkontogianni Jan 27, 2025
c8f2804
feat(DTFS2-7730): fix delete endpoint
rkontogianni Jan 27, 2025
6975fdf
feat(DTFS2-7730): address pr comments
rkontogianni Jan 27, 2025
9fca07c
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Jan 28, 2025
21fca5d
feat(DTFS2-7730): address pr comments
rkontogianni Jan 29, 2025
db99cd9
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Jan 29, 2025
c57ce7e
feat(DTFS2-7730): address pr comments
rkontogianni Jan 29, 2025
2dd83b8
feat(DTFS2-7730): address pr comments
rkontogianni Jan 30, 2025
4f13167
feat(DTFS-7730): fix assertion
rkontogianni Jan 30, 2025
ac388b7
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Jan 30, 2025
ca306e2
feat(DTFS2-7731): delete endpoint portal-api
rkontogianni Jan 31, 2025
1b4d6eb
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Jan 31, 2025
d521e1a
feat(DTFS-7733): post cancel amendment page
rkontogianni Jan 31, 2025
9fe7ae0
feat(DTFS2-7733): add post api test
rkontogianni Feb 3, 2025
6d02aa9
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Feb 11, 2025
f5d52af
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Feb 12, 2025
300b7c7
feat(DTFS2-7733): address pr comments
rkontogianni Feb 13, 2025
2f3ab90
feat(DTFS2-7533): address pr comments
rkontogianni Feb 13, 2025
b01b75d
Merge branch 'main' into feat/DTFS2-7733/post-cancel-amendment
rkontogianni Feb 13, 2025
a3346ea
feat(DTFS-7533): add validateMongoId middleware
rkontogianni Feb 13, 2025
957fb4c
feat(DTFS2-7533): post cancel amendment
rkontogianni Feb 14, 2025
4aa7337
feat(DTFS2-7533): address pr comments
rkontogianni Feb 14, 2025
5a11a1d
Merge branch 'main' of github.com:UK-Export-Finance/dtfs2 into feat/D…
rkontogianni Feb 14, 2025
9c3de57
feat(DTFS2-7533): update valid ids
rkontogianni Feb 14, 2025
5854cac
Merge branch 'main' into feat/DTFS2-7733/post-cancel-amendment
abhi-markan Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as storage from '../test-helpers/storage/storage';
import { MOCK_BASIC_DEAL } from '../../server/utils/mocks/mock-applications';
import { MOCK_UNISSUED_FACILITY, MOCK_ISSUED_FACILITY } from '../../server/utils/mocks/mock-facilities';
import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../test-helpers/mock-amendment';
import { PORTAL_AMENDMENT_PAGES } from '../../server/constants/amendments';
import { withGetAmendmentPageErrorHandlingTests } from './with-get-amendment-page-error-handling.api-tests';

const originalEnv = { ...process.env };
Expand All @@ -25,13 +26,13 @@ const mockGetFacility = jest.fn();
const mockGetApplication = jest.fn();
const mockGetAmendment = jest.fn();

const dealId = '123';
const facilityId = '111';
const amendmentId = '111';
const dealId = '6597dffeb5ef5ff4267e5044';
const facilityId = '6597dffeb5ef5ff4267e5045';
const amendmentId = '6597dffeb5ef5ff4267e5046';

const mockDeal = { ...MOCK_BASIC_DEAL, submissionType: DEAL_SUBMISSION_TYPE.AIN, status: DEAL_STATUS.UKEF_ACKNOWLEDGED };

const url = `/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`;
const url = `/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/${PORTAL_AMENDMENT_PAGES.CANCEL}`;

describe(`GET ${url}`, () => {
let sessionCookie: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { Headers } from 'node-mocks-http';
import { NextFunction, Request, Response } from 'express';
import { HttpStatusCode } from 'axios';
import { ROLES, API_ERROR_CODE } from '@ukef/dtfs2-common';

Check failure on line 4 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L4

Unable to resolve path to module '@ukef/dtfs2-common'.
import { withRoleValidationApiTests } from '../common-tests/role-validation-api-tests';
import app from '../../server/createApp';
import { createApi } from '../create-api';
import api from '../../server/services/api';
import * as storage from '../test-helpers/storage/storage';
import { PORTAL_AMENDMENT_PAGES } from '../../server/constants/amendments';

const originalEnv = { ...process.env };

const { post } = createApi(app);

jest.mock('csurf', () => () => (_req: Request, _res: Response, next: NextFunction) => next());
jest.mock('../../server/middleware/csrf', () => ({
csrfToken: () => (_req: Request, _res: Response, next: NextFunction) => next(),
}));

const mockDeleteAmendment = jest.fn();

const dealId = '6597dffeb5ef5ff4267e5044';
const facilityId = '6597dffeb5ef5ff4267e5045';
const amendmentId = '6597dffeb5ef5ff4267e5046';

const validUrl = `/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/${PORTAL_AMENDMENT_PAGES.CANCEL}`;

describe(`POST ${validUrl}`, () => {
let sessionCookie: string;

beforeEach(async () => {
await storage.flush();
jest.resetAllMocks();

({ sessionCookie } = await storage.saveUserSession([ROLES.MAKER]));

Check failure on line 36 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L36

Unsafe member access .MAKER on an `error` typed value.
jest.spyOn(api, 'deleteAmendment').mockImplementation(mockDeleteAmendment);
jest.spyOn(console, 'error');
});

afterAll(async () => {
jest.resetAllMocks();
await storage.flush();
process.env = originalEnv;
});

describe('when FF_PORTAL_FACILITY_AMENDMENTS_ENABLED is disabled', () => {
beforeEach(() => {
process.env.FF_PORTAL_FACILITY_AMENDMENTS_ENABLED = 'false';
});

it('should redirect to /not-found', async () => {
// Act
const response = await postWithSessionCookie(sessionCookie, validUrl);

// Assert
expect(response.status).toEqual(HttpStatusCode.Found);
expect(response.headers.location).toEqual('/not-found');
});
});

describe('when FF_PORTAL_FACILITY_AMENDMENTS_ENABLED is not set', () => {
beforeEach(() => {
delete process.env.FF_PORTAL_FACILITY_AMENDMENTS_ENABLED;
});

it('should redirect to /not-found', async () => {
// Act
const response = await postWithSessionCookie(sessionCookie, validUrl);

// Assert
expect(response.status).toEqual(HttpStatusCode.Found);
expect(response.headers.location).toEqual('/not-found');
});
});

describe('when FF_PORTAL_FACILITY_AMENDMENTS_ENABLED is enabled', () => {
beforeEach(() => {
process.env.FF_PORTAL_FACILITY_AMENDMENTS_ENABLED = 'true';
});

withRoleValidationApiTests({
makeRequestWithHeaders: (headers: Headers) => post(headers).to(validUrl),
whitelistedRoles: [ROLES.MAKER],
successCode: HttpStatusCode.Found,
});

it(`should return ${HttpStatusCode.BadRequest} when the deal id is invalid`, async () => {
const invalidDealId = 'InvalidId';

const invalidUrl = `/application-details/${invalidDealId}/facilities/${facilityId}/amendments/${amendmentId}/${PORTAL_AMENDMENT_PAGES.CANCEL}`;
const response = await postWithSessionCookie(sessionCookie, invalidUrl);

Check failure on line 92 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L92

Unsafe assignment of an error typed value.
expect(response.status).toEqual(HttpStatusCode.BadRequest);

Check failure on line 93 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L93

Unsafe member access .status on an `error` typed value.

expect(response.body).toEqual({

Check failure on line 95 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L95

Unsafe member access .body on an `error` typed value.
message: "Expected path parameter 'dealId' to be a valid mongo id",
code: API_ERROR_CODE.INVALID_MONGO_ID_PATH_PARAMETER,

Check failure on line 97 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L97

Unsafe assignment of an error typed value.

Check failure on line 97 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L97

Unsafe member access .INVALID_MONGO_ID_PATH_PARAMETER on an `error` typed value.
});
});

it(`should return ${HttpStatusCode.BadRequest} when the facility id is invalid`, async () => {
const invalidFacilityId = 'InvalidId';

const invalidUrl = `/application-details/${dealId}/facilities/${invalidFacilityId}/amendments/${amendmentId}/${PORTAL_AMENDMENT_PAGES.CANCEL}`;
const response = await postWithSessionCookie(sessionCookie, invalidUrl);
expect(response.status).toEqual(HttpStatusCode.BadRequest);

expect(response.body).toEqual({
message: "Expected path parameter 'facilityId' to be a valid mongo id",
code: API_ERROR_CODE.INVALID_MONGO_ID_PATH_PARAMETER,
});
});

it(`should return ${HttpStatusCode.BadRequest} when the amendment id is invalid`, async () => {
const invalidAmendmentId = 'InvalidId';

const invalidUrl = `/application-details/${dealId}/facilities/${facilityId}/amendments/${invalidAmendmentId}/${PORTAL_AMENDMENT_PAGES.CANCEL}`;
const response = await postWithSessionCookie(sessionCookie, invalidUrl);
expect(response.status).toEqual(HttpStatusCode.BadRequest);

expect(response.body).toEqual({
message: "Expected path parameter 'amendmentId' to be a valid mongo id",
code: API_ERROR_CODE.INVALID_MONGO_ID_PATH_PARAMETER,
});
});

it('should not call console.error if the facility and amendment are valid', async () => {
// Act
await postWithSessionCookie(sessionCookie, validUrl);

// Assert
expect(console.error).not.toHaveBeenCalled();
});

it('should redirect to the applications details page, after the amendment has been deleted successfully', async () => {
// Act
const response = await postWithSessionCookie(sessionCookie, validUrl);

// Assert
expect(mockDeleteAmendment).toHaveBeenCalledTimes(1);
expect(response.status).toEqual(HttpStatusCode.Found);
expect(response.headers.location).toEqual(`/gef/application-details/${dealId}`);

Check failure on line 142 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L142

Unsafe member access .headers on an `error` typed value.
});

it('should render `problem with service` if deleteAmendment throws an error', async () => {
// Arrange
mockDeleteAmendment.mockRejectedValue(new Error('test error'));

// Act
const response = await postWithSessionCookie(sessionCookie, validUrl);

// Assert
expect(mockDeleteAmendment).toHaveBeenCalledTimes(1);
expect(response.status).toEqual(HttpStatusCode.Ok);

Check failure on line 154 in gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/cancel-portal-facility-amendment.post.api-test.ts#L154

Unsafe member access .status on an `error` typed value.
expect(response.text).toContain('Problem with the service');
});
});
});

function postWithSessionCookie(sessionCookie: string, url: string) {
return post({}, { Cookie: [`dtfs-session=${encodeURIComponent(sessionCookie)}`] }).to(url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CancelAmendmentViewModel } from '../../../types/view-models/amendments/
import { MOCK_BASIC_DEAL } from '../../../utils/mocks/mock-applications';
import { MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities';
import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment';
import { getCancelPortalFacilityAmendment, GetCancelPortalFacilityAmendmentRequest } from './cancel-portal-facility-amendment';
import { getCancelPortalFacilityAmendment, GetCancelPortalFacilityAmendmentRequest } from './get-cancel-portal-facility-amendment';

jest.mock('../../../services/api', () => ({
getApplication: getApplicationMock,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable import/first */
const deleteAmendmentMock = jest.fn();

import httpMocks from 'node-mocks-http';
import * as dtfsCommon from '@ukef/dtfs2-common';

Check failure on line 5 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L5

Unable to resolve path to module '@ukef/dtfs2-common'.
import { aPortalSessionUser, PORTAL_LOGIN_STATUS } from '@ukef/dtfs2-common';

Check failure on line 6 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L6

Unable to resolve path to module '@ukef/dtfs2-common'.
import { postCancelPortalFacilityAmendment, PostCancelPortalFacilityAmendmentRequest } from './post-cancel-portal-facility-amendment';

jest.mock('../../../services/api', () => ({
deleteAmendment: deleteAmendmentMock,
}));

const dealId = '6597dffeb5ef5ff4267e5044';
const facilityId = '6597dffeb5ef5ff4267e5045';
const amendmentId = '6597dffeb5ef5ff4267e5046';

const aMockError = () => new Error();

const mockUser = aPortalSessionUser();

Check failure on line 19 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L19

Unsafe assignment of an error typed value.

Check failure on line 19 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L19

Unsafe call of an `error` type typed value.
const userToken = 'userToken';

const getHttpMocks = () =>
httpMocks.createMocks<PostCancelPortalFacilityAmendmentRequest>({

Check failure on line 23 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L23

Unsafe call of an `error` type typed value.

Check failure on line 23 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L23

Unsafe return of an error typed value.
params: {
dealId,
facilityId,
amendmentId,
},
session: {
user: mockUser,

Check failure on line 30 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L30

Unsafe assignment of an error typed value.
userToken,
loginStatus: PORTAL_LOGIN_STATUS.VALID_2FA,

Check failure on line 32 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L32

Unsafe assignment of an error typed value.
},
});

describe('postCancelPortalFacilityAmendment', () => {
beforeEach(() => {
jest.resetAllMocks();

jest.spyOn(dtfsCommon, 'isPortalFacilityAmendmentsFeatureFlagEnabled').mockReturnValue(true);
jest.spyOn(console, 'error');

deleteAmendmentMock.mockResolvedValue(undefined);
});

it('should call deleteAmendment with the correct facilityId, amendmentId, and userToken', async () => {
// Arrange
const { req, res } = getHttpMocks();

Check failure on line 48 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L48

Unsafe assignment of an error typed value.

// Act
await postCancelPortalFacilityAmendment(req, res);

Check failure on line 51 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L51

Unsafe argument of type `any` assigned to a parameter of type `Response<any, Record<string, any>>`.

// Assert
expect(deleteAmendmentMock).toHaveBeenCalledTimes(1);
expect(deleteAmendmentMock).toHaveBeenCalledWith({ facilityId, amendmentId, userToken });
});

it('should redirect to details page after amendment has been deleted', async () => {
// Arrange
const { req, res } = getHttpMocks();

// Act
await postCancelPortalFacilityAmendment(req, res);

// Assert
expect(deleteAmendmentMock).toHaveBeenCalledTimes(1);
expect(res._getRedirectUrl()).toEqual(`/gef/application-details/${dealId}`);
});

it('should render `problem with service` if deleteAmendment throws an error', async () => {
// Arrange
const mockError = aMockError();
deleteAmendmentMock.mockRejectedValue(mockError);
const { req, res } = getHttpMocks();

// Act
await postCancelPortalFacilityAmendment(req, res);

// Assert
expect(deleteAmendmentMock).toHaveBeenCalledTimes(1);
expect(res._getRenderView()).toEqual('partials/problem-with-service.njk');

Check failure on line 81 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.test.ts#L81

Unsafe call of an `error` type typed value.
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenCalledWith('Error posting cancel amendments page %o', mockError);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CustomExpressRequest } from '@ukef/dtfs2-common';
import { Response } from 'express';
import * as api from '../../../services/api';
import { asLoggedInUserSession } from '../../../utils/express-session';

export type PostCancelPortalFacilityAmendmentRequest = CustomExpressRequest<{
params: { dealId: string; facilityId: string; amendmentId: string };
}>;

/**
* controller to post the cancel amendment page
*
* @param req - The express request
* @param res - The express response
*/
export const postCancelPortalFacilityAmendment = async (req: PostCancelPortalFacilityAmendmentRequest, res: Response) => {
try {
const { dealId, facilityId, amendmentId } = req.params;

Check failure on line 18 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.ts#L18

Unsafe member access .params on an `error` typed value.
const { userToken } = asLoggedInUserSession(req.session);

Check failure on line 19 in gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.ts#L19

Unsafe member access .session on an `error` typed value.

await api.deleteAmendment({ facilityId, amendmentId, userToken });

return res.redirect(`/gef/application-details/${dealId}`);
} catch (error) {
console.error('Error posting cancel amendments page %o', error);
return res.render('partials/problem-with-service.njk');
}
};
17 changes: 14 additions & 3 deletions gef-ui/server/routes/facilities/amendments/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import express from 'express';
import { validateMongoId } from '@ukef/dtfs2-common';
import { validatePortalFacilityAmendmentsEnabled } from '../../../middleware/feature-flags/portal-facility-amendments';
import { validateRole, validateToken, validateBank } from '../../../middleware';
import { MAKER } from '../../../constants/roles';
Expand All @@ -11,7 +12,8 @@
import { getCoverEndDate } from '../../../controllers/amendments/cover-end-date/get-cover-end-date';
import { postCoverEndDate } from '../../../controllers/amendments/cover-end-date/post-cover-end-date';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { getCancelPortalFacilityAmendment } from '../../../controllers/amendments/cancel-amendment/cancel-portal-facility-amendment';
import { getCancelPortalFacilityAmendment } from '../../../controllers/amendments/cancel-amendment/get-cancel-portal-facility-amendment.ts';
import { postCancelPortalFacilityAmendment } from '../../../controllers/amendments/cancel-amendment/post-cancel-portal-facility-amendment.ts';
import { getDoYouHaveAFacilityEndDate } from '../../../controllers/amendments/do-you-have-a-facility-end-date/get-do-you-have-a-facility-end-date';
import { postDoYouHaveAFacilityEndDate } from '../../../controllers/amendments/do-you-have-a-facility-end-date/post-do-you-have-a-facility-end-date';
import { getFacilityEndDate } from '../../../controllers/amendments/facility-end-date/get-facility-end-date';
Expand Down Expand Up @@ -69,8 +71,17 @@

router
.route(`/application-details/:dealId/facilities/:facilityId/amendments/:amendmentId/${CANCEL}`)
.all([validatePortalFacilityAmendmentsEnabled, validateToken, validateBank, validateRole({ role: [MAKER] })])
.get(getCancelPortalFacilityAmendment);
.all([
validatePortalFacilityAmendmentsEnabled,
validateToken,
validateBank,
validateMongoId('dealId'),

Check failure on line 78 in gef-ui/server/routes/facilities/amendments/index.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/routes/facilities/amendments/index.ts#L78

Unsafe call of an `error` type typed value.
validateMongoId('facilityId'),

Check failure on line 79 in gef-ui/server/routes/facilities/amendments/index.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/routes/facilities/amendments/index.ts#L79

Unsafe call of an `error` type typed value.
validateMongoId('amendmentId'),

Check failure on line 80 in gef-ui/server/routes/facilities/amendments/index.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/routes/facilities/amendments/index.ts#L80

Unsafe call of an `error` type typed value.
validateRole({ role: [MAKER] }),
])
.get(getCancelPortalFacilityAmendment)
.post(postCancelPortalFacilityAmendment);

router
.route(`/application-details/:dealId/facilities/:facilityId/amendments/:amendmentId/${DO_YOU_HAVE_A_FACILITY_END_DATE}`)
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './feature-flags';
export * from './create-validation-middleware-for-schema';
export * from './set-no-store-cache-control';
export * from './validate-mongoId';
1 change: 1 addition & 0 deletions libs/common/src/middleware/validate-mongoId/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './validate-mongoId';
Loading
Loading