Skip to content

Commit

Permalink
feat(vta-1674): corrected docblock
Browse files Browse the repository at this point in the history
  • Loading branch information
m-coslett committed Jul 26, 2023
1 parent 1646c23 commit 99ce798
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 49 deletions.
6 changes: 6 additions & 0 deletions src/models/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ export enum CERTIFICATE_DATA {
export const HGV_TRL_ROADWORTHINESS_TEST_TYPES = {
IDS: ["62", "63", "91", "101", "122"],
};

export enum ATF_COUNTRIES {
ENGLAND = "ENGLAND",
SCOTLAND = "SCOTLAND",
WALES = "WALES"
}
17 changes: 17 additions & 0 deletions src/models/ITestStations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface ITestStation {
testStationId: string;
testStationPNumber: string;
testStationStatus: string;
testStationName: string;
testStationContactNumber: string;
testStationAccessNotes: string;
testStationGeneralNotes: string;
testStationTown: string;
testStationAddress: string;
testStationPostcode: string;
testStationCountry?: string;
testStationLongitude: number;
testStationLatitude: number;
testStationType: string;
testStationEmails: string[];
}
21 changes: 2 additions & 19 deletions src/models/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,7 @@ interface IMOTConfig {
interface IS3Config {
endpoint: string;
}
interface ITestStation {
testStationId: string;
testStationPNumber: string;
testStationStatus: string;
testStationName: string;
testStationContactNumber: string;
testStationAccessNotes: string;
testStationGeneralNotes: string;
testStationTown: string;
testStationAddress: string;
testStationPostcode: string;
testStationCountry?: string;
testStationLongitude: number;
testStationLatitude: number;
testStationType: string;
testStationEmails: string[];
}

interface IGeneratedCertificateResponse {
fileName: string;
vrm: string;
Expand Down Expand Up @@ -262,6 +246,5 @@ export {
ITestResult,
ITestType,
ITrailerRegistration,
IMakeAndModel,
ITestStation
IMakeAndModel
};
84 changes: 54 additions & 30 deletions src/services/CertificateGenerationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
IWeightDetails,
ITrailerRegistration,
IMakeAndModel,
ITestType, ITestStation,
ITestType
} from "../models";
import {ITestStation} from "../models/ITestStations";
import { Configuration } from "../utils/Configuration";
import { S3BucketService } from "./S3BucketService";
import S3 from "aws-sdk/clients/s3";
Expand All @@ -19,6 +20,7 @@ import { PromiseResult } from "aws-sdk/lib/request";
import { Service } from "../models/injector/ServiceDecorator";
import { LambdaService } from "./LambdaService";
import {
ATF_COUNTRIES,
CERTIFICATE_DATA,
ERRORS,
HGV_TRL_ROADWORTHINESS_TEST_TYPES,
Expand Down Expand Up @@ -57,7 +59,8 @@ class CertificateGenerationService {
const testType: any = testResult.testTypes;

// Find out if Welsh certificate is needed
const testStations = await this.getTestStations(testResult.testStationPNumber);
const testStations = await this.getTestStations();
const welshTestStation = this.isTestStationWelsh(testStations, testResult.testStationPNumber);

const payload: string = JSON.stringify(
await this.generatePayload(testResult)
Expand Down Expand Up @@ -141,13 +144,9 @@ class CertificateGenerationService {
}

/**
* Method to retrieve defects from API
* Method to retrieve Test Station details from API
*/
public async getTestStations(testStationPNumber: string) {

console.log(`In get test stations`);
console.log(`PNumber parameter is ${testStationPNumber}`);

public async getTestStations() {
const config: IInvokeConfig = this.config.getInvokeConfig();
const invokeParams: any = {
FunctionName: config.functions.testStations.name,
Expand All @@ -160,33 +159,58 @@ class CertificateGenerationService {
};
let testStations: ITestStation[] = [];
return this.lambdaClient
.invoke(invokeParams)
.then(
(response: PromiseResult<Lambda.Types.InvocationResponse, AWSError>) => {
const payload: any = this.lambdaClient.validateInvocationResponse(response);
testStations = JSON.parse(payload.body);
.invoke(invokeParams)
.then(
(
response: PromiseResult<Lambda.Types.InvocationResponse, AWSError>
) => {
const payload: any =
this.lambdaClient.validateInvocationResponse(response);
testStations = JSON.parse(payload.body);

if (!testStations || testStations.length === 0) {
throw new HTTPError(
400,
`${ERRORS.LAMBDA_INVOCATION_BAD_DATA} ${JSON.stringify(payload)}.`
);
}
if (!testStations || testStations.length === 0) {
throw new HTTPError(
400,
`${ERRORS.LAMBDA_INVOCATION_BAD_DATA} ${JSON.stringify(payload)}.`
);
}
console.log(`There are ${testStations.length} test stations`);
return testStations;
}
)
.catch((error: AWSError | Error) => {
console.error(
`There was an error retrieving the test stations: ${error}`
);
return testStations;
});
}

console.log(`There are ${testStations.length} test stations`);
/**
* Check if the specific test station is in Wales
* @param testStations list of all test stations
* @param testStationPNumber pNumber from the test result
* @returns boolean
*/
public async isTestStationWelsh(testStations: ITestStation[], testStationPNumber: string) {
// default parameter so that if ATF cannot be determined, processing will continue
let isWelsh = false;

const thisATF = testStations.filter((x) => {
return x.testStationPNumber === testStationPNumber;
});
// find the specific test station by the PNumber used on the test result
const pNumberTestStation = testStations.filter((x) => {
return x.testStationPNumber === testStationPNumber;
});

console.log(`This is ATF ${thisATF[0].testStationPNumber} ${thisATF[0].testStationName} in ${thisATF[0].testStationCountry}`);
if ((pNumberTestStation) && (pNumberTestStation.length > 0)) {
const thisTestStation = pNumberTestStation[0];
console.log(`This test result was done at ATF ${thisTestStation.testStationPNumber} ${thisTestStation.testStationName} in ${thisTestStation.testStationCountry}`);
// @ts-ignore
if (thisTestStation.testStationCountry.toUpperCase() === ATF_COUNTRIES.WALES) {
isWelsh = true;
}
}

return thisATF;
}
).catch((error: AWSError | Error) => {
console.error(`There was an error retrieving the test stations: ${error}`);
return testStations;
});
return isWelsh;
}

/**
Expand Down

0 comments on commit 99ce798

Please sign in to comment.