Skip to content

Commit dd09a85

Browse files
authored
ORV2-3491 Add claimed company validation to verify-client endpoint. (#1836)
1 parent f17088f commit dd09a85

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

vehicles/src/modules/company-user-management/company/company.controller.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ApiOkResponse,
2121
ApiOperation,
2222
ApiTags,
23+
ApiUnprocessableEntityResponse,
2324
} from '@nestjs/swagger';
2425
import { DataNotFoundException } from '../../../common/exception/data-not-found.exception';
2526
import { ExceptionDto } from '../../../common/exception/exception.dto';
@@ -63,6 +64,10 @@ import { doesUserHaveRole } from '../../../common/helper/auth.helper';
6364
description: 'The Company Api Internal Server Error Response',
6465
type: ExceptionDto,
6566
})
67+
@ApiUnprocessableEntityResponse({
68+
description: 'The Company Entity could not be processed.',
69+
type: ExceptionDto,
70+
})
6671
@ApiBearerAuth()
6772
@Controller('companies')
6873
export class CompanyController {
@@ -228,8 +233,9 @@ export class CompanyController {
228233
}
229234

230235
/**
231-
* A POST method defined with a route of /verify-client that verifies
232-
* the existence of a migrated/onRoute BC client and their permit in the system.
236+
* A POST method is defined with a route of /verify-client that verifies
237+
* the existence of a migrated/OnRouteBC client and their permit in the system.
238+
* A 422 unprocessable exception will be thrown if it is found that the company has already been claimed in OnRouteBC.
233239
*
234240
* @returns The verified client details with response object {@link ReadVerifyClientDto}.
235241
*/
@@ -240,7 +246,7 @@ export class CompanyController {
240246
@ApiOperation({
241247
summary: 'Verify Migrated/onRouteBC Client',
242248
description:
243-
'Verifies the existence of a migrated/onRouteBC client and their permit in the database',
249+
'Verifies the existence of a migrated/onRouteBC client and their permit in the database. A 422 unprocessable exception will be thrown if it is found that the company has already been claimed in OnRouteBC.',
244250
})
245251
@AuthOnly()
246252
@Post('verify-client')

vehicles/src/modules/company-user-management/company/company.service.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { ReadVerifyClientDto } from './dto/response/read-verify-client.dto';
5353
import { Permit } from '../../permit-application-payment/permit/entities/permit.entity';
5454
import { DopsService } from '../../common/dops.service';
5555
import { INotificationDocument } from '../../../common/interface/notification-document.interface';
56+
import { throwUnprocessableEntityException } from '../../../common/helper/exception.helper';
5657

5758
@Injectable()
5859
export class CompanyService {
@@ -792,8 +793,9 @@ export class CompanyService {
792793
* The verifyClient() method attempts to validate the existence and correct linkage of a specified client
793794
* and their associated permit within the system. The process involves searching for a company using a provided
794795
* client number (including handling legacy client number scenarios) and then verifying the existence of a
795-
* permit that correlates with the identified company. The outcome is encapsulated in a ReadVerifyClientDto
796-
* object indicating the presence of the client, the permit, and the successful verification if applicable.
796+
* permit that correlates with the identified company. If the company has been claimed already, an unprocessable
797+
* entity error is thrown. The outcome is encapsulated in a ReadVerifyClientDto object indicating the presence
798+
* of the client, the permit, and the successful verification if applicable.
797799
*
798800
* @param currentUser The current logged in user's JWT token.
799801
* @param verifyClientDto The DTO containing the client and permit number to verify.
@@ -850,6 +852,12 @@ export class CompanyService {
850852
if (permit) {
851853
verifyClient.foundPermit = true;
852854
if (permit.company?.companyId === company?.companyId) {
855+
//Throw an error if the company has already been claimed
856+
if (company?.companyUsers?.length) {
857+
throwUnprocessableEntityException(
858+
`You do not have the necessary authorization to view this page. Please contact your administrator.`,
859+
);
860+
}
853861
verifyClient.verifiedClient =
854862
await this.mapCompanyEntityToCompanyDto(company);
855863
}

0 commit comments

Comments
 (0)