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(cb2-12681): implement common package test type id and types defi… #425

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"@aws-sdk/client-lambda": "^3.634.0",
"@aws-sdk/lib-dynamodb": "^3.632.0",
"@aws-sdk/smithy-client": "^3.374.0",
"@dvsa/cvs-microservice-common": "1.2.4",
"@dvsa/cvs-type-definitions": "^7.4.0",
"@dvsa/cvs-microservice-common": "^1.2.4",
"@dvsa/cvs-type-definitions": "^7.6.1",
"@smithy/smithy-client": "^2.5.1",
"@smithy/util-utf8": "^2.3.0",
"aws-lambda": "^1.0.7",
Expand Down
19 changes: 0 additions & 19 deletions src/assets/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ export const TEST_TYPE_CLASSIFICATION = {
MSVA_WITH_CERTIFICATE: 'MSVA With Certificate',
};

export const TEST_RESULT = {
PASS: 'pass',
FAIL: 'fail',
ABANDONED: 'abandoned',
PRS: 'prs',
};

export const TEST_STATUS = {
SUBMITTED: 'submitted',
CANCELLED: 'cancelled',
Expand Down Expand Up @@ -132,18 +125,6 @@ export const COIF_EXPIRY_TEST_TYPES = {
IDS: ['142', '146', '175', '177'],
};

export const LEC_TEST_TYPES = {
IDS: ['39', '201', '44', '45'],
};

export const ADR_TEST_TYPES = {
IDS: ['50', '59', '60'],
};

export const TIR_TEST_TYPES = {
IDS: ['49', '56', '57'],
};

export const COUNTRY_OF_REGISTRATION: string[] = [
'gb',
'gba',
Expand Down
80 changes: 42 additions & 38 deletions src/handlers/VehicleTestController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { cloneDeep, differenceWith, isEqual, mergeWith } from 'lodash';
import {
TestResultSchema,
TestTypeSchema,
} from '@dvsa/cvs-type-definitions/types/v1/test-result';
import { TestResults } from '@dvsa/cvs-type-definitions/types/v1/enums/testResult.enum';
import * as enums from '../assets/Enums';
import * as models from '../models';
import { TestType } from '../models';
import { TestTypeForExpiry } from '../models/TestTypeforExpiry';
import { Service } from '../models/injector/ServiceDecorator';
import * as utils from '../utils';
Expand All @@ -25,7 +29,7 @@ export class VehicleTestController implements IVehicleTestController {
*/
public async getTestResultBySystemNumber(
filters: models.ITestResultFilters,
): Promise<models.ITestResult[]> {
): Promise<TestResultSchema[]> {
if (
!filters.systemNumber ||
!utils.ValidationUtil.validateGetTestResultFilters(filters)
Expand All @@ -45,7 +49,7 @@ export class VehicleTestController implements IVehicleTestController {
*/
public async getTestResultByTestStaffId(
filters: models.ITestResultFilters,
): Promise<models.ITestResult[]> {
): Promise<TestResultSchema[]> {
if (
!filters.testerStaffId ||
!utils.ValidationUtil.validateGetTestResultFilters(filters)
Expand Down Expand Up @@ -75,7 +79,7 @@ export class VehicleTestController implements IVehicleTestController {
return selectedStrategy;
}

public async insertTestResult(payload: models.ITestResultPayload) {
public async insertTestResult(payload: TestResultSchema) {
try {
utils.ValidationUtil.validateInsertTestResultPayload(payload);
console.info('validation is success');
Expand All @@ -95,11 +99,12 @@ export class VehicleTestController implements IVehicleTestController {
payload.testTypes,
testTypeParams,
);
payload.testTypes = testTypesWithTestCodesAndClassification as TestType[];
payload.testTypes =
testTypesWithTestCodesAndClassification as TestTypeSchema[];

const payloadWithTestNumber =
await this.dataProvider.setTestNumberForEachTestType(payload);
payload.testTypes = payloadWithTestNumber as models.TestType[];
payload.testTypes = payloadWithTestNumber as TestTypeSchema[];

const payloadWithExpiryDate = await this.generateExpiryDate(payload);
const payloadWithCertificateNumber =
Expand Down Expand Up @@ -132,10 +137,10 @@ export class VehicleTestController implements IVehicleTestController {

public async updateTestResult(
systemNumber: string,
payload: models.ITestResult,
payload: TestResultSchema,
msUserDetails: models.IMsUserDetails,
) {
let newTestResult: models.ITestResult;
let newTestResult: TestResultSchema;
try {
const { testTypes } = payload;
utils.MappingUtil.removeNonEditableAttributes(payload);
Expand Down Expand Up @@ -176,8 +181,8 @@ export class VehicleTestController implements IVehicleTestController {
* @param payload
*/
private async generateExpiryDate(
payload: models.ITestResultPayload,
): Promise<models.ITestResultPayload> {
payload: TestResultSchema,
): Promise<TestResultSchema> {
try {
if (
payload.testStatus !== enums.TEST_STATUS.SUBMITTED ||
Expand All @@ -194,20 +199,23 @@ export class VehicleTestController implements IVehicleTestController {
const recentExpiry = await this.dataProvider.getMostRecentExpiryDate(
payload.systemNumber,
);
const registrationDate =
VehicleTestController.getRegistrationOrFirstUseDate(payload);

expiryTestTypes.forEach((testType: any, index: number) => {
const testTypeForExpiry: models.TestTypeForExpiry = {
expiryTestTypes.forEach((testType: TestTypeSchema, index: number) => {
const testTypeForExpiry: TestTypeForExpiry = {
testType,
vehicleType:
enums.VEHICLE_TYPE[
payload.vehicleType.toUpperCase() as keyof typeof enums.VEHICLE_TYPE
],
recentExpiry,
regnOrFirstUseDate:
VehicleTestController.getRegistrationOrFirstUseDate(payload),
regnOrFirstUseDate: registrationDate ?? '',
hasHistory: !DateProvider.isSameAsEpoc(recentExpiry),
hasRegistration: DateProvider.isValidDate(
VehicleTestController.getRegistrationOrFirstUseDate(payload),
VehicleTestController.getRegistrationOrFirstUseDate(
payload,
) as string,
),
};
console.log('testTypeForExpiry');
Expand Down Expand Up @@ -239,23 +247,21 @@ export class VehicleTestController implements IVehicleTestController {
/**
* This function will not remove the certificate number on the test types which already have it set
*/
private static AssignCertificateNumberToTestTypes(
payload: models.ITestResultPayload,
) {
private static AssignCertificateNumberToTestTypes(payload: TestResultSchema) {
if (payload.testStatus !== enums.TEST_STATUS.SUBMITTED) {
return payload;
}
payload.testTypes.forEach((testType) => {
if (this.shouldGenerateCertificateNumber(testType, payload.vehicleType)) {
testType.certificateNumber = testType.testNumber;
testType.certificateNumber = testType.testNumber as string;
}
});
return payload;
}

private static calculateAnniversaryDate(payload: models.ITestResultPayload) {
private static calculateAnniversaryDate(payload: TestResultSchema) {
const { vehicleType } = payload;
payload.testTypes.forEach((testType: models.TestType) => {
payload.testTypes.forEach((testType: TestTypeSchema) => {
const { testExpiryDate } = testType;
if (!testExpiryDate) {
return;
Expand All @@ -268,9 +274,7 @@ export class VehicleTestController implements IVehicleTestController {
return payload;
}

private static getRegistrationOrFirstUseDate(
payload: models.ITestResultPayload,
) {
private static getRegistrationOrFirstUseDate(payload: TestResultSchema) {
return payload.vehicleType === enums.VEHICLE_TYPES.TRL
? payload.firstUseDate
: payload.regnDate;
Expand All @@ -279,7 +283,7 @@ export class VehicleTestController implements IVehicleTestController {
// #endregion
public async mapOldTestResultToNew(
systemNumber: string,
payload: models.ITestResult,
payload: TestResultSchema,
msUserDetails: models.IMsUserDetails,
) {
const testResults = await this.dataProvider.getBySystemNumber(systemNumber);
Expand Down Expand Up @@ -322,8 +326,8 @@ export class VehicleTestController implements IVehicleTestController {
}

private async generateNewTestCode(
oldTestResult: models.ITestResult,
newTestResult: models.ITestResult,
oldTestResult: TestResultSchema,
newTestResult: TestResultSchema,
) {
const {
vehicleType,
Expand Down Expand Up @@ -354,8 +358,8 @@ export class VehicleTestController implements IVehicleTestController {
}

private static shouldGenerateNewTestCode(
oldTestResult: models.ITestResult,
newTestResult: models.ITestResult,
oldTestResult: TestResultSchema,
newTestResult: TestResultSchema,
) {
const attributesToCheck = [
'vehicleType',
Expand Down Expand Up @@ -383,14 +387,14 @@ export class VehicleTestController implements IVehicleTestController {
}

public async checkTestTypeStartAndEndTimestamp(
newTestResult: models.ITestResult,
newTestResult: TestResultSchema,
) {
const { testTypes } = newTestResult;
const isStartAfterEnd = testTypes.some((testType) => {
const { testTypeStartTimestamp, testTypeEndTimestamp } = testType;
return DateProvider.isAfterDate(
testTypeStartTimestamp,
testTypeEndTimestamp,
testTypeStartTimestamp as string,
testTypeEndTimestamp as string,
);
});
if (isStartAfterEnd) {
Expand All @@ -399,9 +403,9 @@ export class VehicleTestController implements IVehicleTestController {
}

private static getTestResultToArchive(
testResults: models.ITestResult[],
testResults: TestResultSchema[],
testResultId: string,
): models.ITestResult {
): TestResultSchema {
testResults = testResults.filter(
(testResult) =>
testResult.testResultId === testResultId &&
Expand All @@ -415,14 +419,14 @@ export class VehicleTestController implements IVehicleTestController {
}

private static shouldGenerateCertificateNumber(
testType: models.TestType,
testType: TestTypeSchema,
vehicleType: string,
): boolean {
if (
(testType.testTypeClassification ===
enums.TEST_TYPE_CLASSIFICATION.ANNUAL_WITH_CERTIFICATE ||
this.isSpecialistTestWithoutCertificateNumber(testType)) &&
testType.testResult !== enums.TEST_RESULT.ABANDONED
testType.testResult !== TestResults.ABANDONED
) {
if (
utils.ValidationUtil.isTestTypeAdr(testType) ||
Expand All @@ -437,7 +441,7 @@ export class VehicleTestController implements IVehicleTestController {
return (
// @ts-ignore
utils.ValidationUtil.isHgvOrTrl(vehicleType) &&
testType.testResult !== enums.TEST_RESULT.FAIL
testType.testResult !== TestResults.FAIL
);
}
return true;
Expand All @@ -446,7 +450,7 @@ export class VehicleTestController implements IVehicleTestController {
}

private static isSpecialistTestWithoutCertificateNumber(
testType: models.TestType,
testType: TestTypeSchema,
): boolean {
return (
(testType.testTypeClassification ===
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/expiry/providers/ITestDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ITestResult } from '../../../models/ITestResult';
import { TestResultSchema } from '@dvsa/cvs-type-definitions/types/v1/test-result';

export interface ITestDataProvider {
getTestHistory(systemNumber: string): Promise<ITestResult[]>;
getTestHistory(systemNumber: string): Promise<TestResultSchema[]>;
getMostRecentExpiryDate(systemNumber: string): Promise<Date>;
}
Loading
Loading