Skip to content

Commit

Permalink
feat(CB2-12693): remved any type
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Searle committed Jul 8, 2024
1 parent 9e482e6 commit ed0d66d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 125 deletions.
95 changes: 31 additions & 64 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@aws-sdk/types": "^3.535.0",
"@aws-sdk/util-dynamodb": "^3.609.0",
"@dvsa/cvs-microservice-common": "^1.1.0",
"@dvsa/cvs-type-definitions": "7.1.0",
"@dvsa/cvs-type-definitions": "7.2.0",
"@smithy/util-utf8": "^2.3.0",
"aws-sdk-client-mock": "^4.0.0",
"aws-xray-sdk": "^3.3.4",
Expand Down
27 changes: 12 additions & 15 deletions src/functions/retroGen.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { unmarshall } from "@aws-sdk/util-dynamodb";
import { LambdaClient } from "@aws-sdk/client-lambda";
import {unmarshall} from "@aws-sdk/util-dynamodb";
import {LambdaClient} from "@aws-sdk/client-lambda";
import * as rp from "request-promise";
import { ERRORS } from "../assets/Enum";
import { RetroGenerationService } from "../services/RetroGenerationService";
import { SharePointAuthenticationService } from "../services/SharePointAuthenticationService";
import { SharePointService } from "../services/SharePointService";
import { TestResultsService } from "../services/TestResultsService";
import { ActivitiesService } from "../services/ActivitiesService";
import { LambdaService } from "../services/LambdaService";
import { PutObjectCommandOutput } from "@aws-sdk/client-s3";
import { credentials } from "../handler";
import {ERRORS} from "../assets/Enum";
import {RetroGenerationService} from "../services/RetroGenerationService";
import {SharePointAuthenticationService} from "../services/SharePointAuthenticationService";
import {SharePointService} from "../services/SharePointService";
import {TestResultsService} from "../services/TestResultsService";
import {ActivitiesService} from "../services/ActivitiesService";
import {LambdaService} from "../services/LambdaService";
import {PutObjectCommandOutput} from "@aws-sdk/client-s3";
import {credentials} from "../handler";

/**
* λ function to process a DynamoDB stream of test results into a queue for certificate generation.
* @param event - DynamoDB Stream event
* @param context - λ Context
* @param callback - callback function
*/
const retroGen = async (event: any): Promise<void | PutObjectCommandOutput[]> => {
if (!event || !event.Records || !Array.isArray(event.Records) || !event.Records.length) {
Expand All @@ -35,8 +33,7 @@ const retroGen = async (event: any): Promise<void | PutObjectCommandOutput[]> =>
const retroUploadPromise = retroService.generateRetroReport(visit).then(async (generationServiceResponse: { fileName: string; fileBuffer: Buffer }) => {
const tokenResponse = await sharepointAuthenticationService.getToken();
const accessToken = JSON.parse(tokenResponse).access_token;
const sharePointResponse = await sharePointService.upload(generationServiceResponse.fileName, generationServiceResponse.fileBuffer, accessToken);
return sharePointResponse;
return await sharePointService.upload(generationServiceResponse.fileName, generationServiceResponse.fileBuffer, accessToken);
});

retroUploadPromises.push(retroUploadPromise);
Expand Down
62 changes: 32 additions & 30 deletions src/services/RetroGenerationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { IActivitiesList } from "../models";
import { ActivitiesService } from "./ActivitiesService";
import { TestResultsService } from "./TestResultsService";
import moment = require("moment-timezone");
import {ActivitySchema} from "@dvsa/cvs-type-definitions/types/v1/activity";
import {TestResultSchema, TestTypeSchema} from "@dvsa/cvs-type-definitions/types/v1/test-result";
import { ActivitySchema} from "@dvsa/cvs-type-definitions/types/v1/activity";
import { TestResultSchema, TestTypeSchema} from "@dvsa/cvs-type-definitions/types/v1/test-result";
import { ModTypeSchema} from "@dvsa/cvs-type-definitions/types/v1/test-type";

class RetroGenerationService {
private readonly testResultsService: TestResultsService;
Expand Down Expand Up @@ -40,7 +41,7 @@ class RetroGenerationService {
testStationPNumber: activity.testStationPNumber,
activityType: "wait",
})
.then((waitActivities: any[]) => {
.then((waitActivities: ActivitySchema[]) => {
const totalActivitiesLen = testResults.length + waitActivities.length;
// Fetch and populate the Retrokey template
return this.fetchRetroTemplate(totalActivitiesLen).then((template: { workbook: Excel.Workbook; reportTemplate: any }) => {
Expand All @@ -66,18 +67,18 @@ class RetroGenerationService {
if (event.activityType === ActivityType.TEST) {
// Populate activity report
const detailsTemplate: any = template.reportTemplate.activityDetails[i];
const testResult: any = event.activity;
const testType: any = testResult.testTypes;
const additionalTestTypeNotes: string = testType.prohibitionIssued ? "Prohibition was issued" : "none";
const testResult: TestResultSchema = event.activity;
const testType: TestTypeSchema[] = testResult.testTypes;
const additionalTestTypeNotes: string = testType[0].prohibitionIssued ? "Prohibition was issued" : "none";
let defects: string = "";
let reasonForAbandoning: string = "";
let additionalCommentsAbandon: string = "";
let LECNotes: string = "";
let defectsDetails: string = "";
let prsString: string = "";

for (const key of Object.keys(testType.defects)) {
if (testType.defects[key].prs) {
for (const [, defectValue] of Object.entries(testType[0]?.defects || {})) {
if (defectValue.prs) {
prsString = ", PRS";
} else {
prsString = "";
Expand All @@ -86,36 +87,36 @@ class RetroGenerationService {
defectsDetails =
defectsDetails +
" " +
testType.defects[key].deficiencyRef +
testType[0].defects[0].deficiencyRef +
" (" +
testType.defects[key].deficiencyCategory +
testType[0].defects[0].deficiencyCategory +
prsString +
(testType.defects[key].additionalInformation.notes ? ", " + testType.defects[key].additionalInformation.notes : "") +
(testType.defects[key].prohibitionIssued ? ", Prohibition was issued" : ", Prohibition was not issued") +
(testType[0].defects[0].additionalInformation.notes ? ", " + testType[0].defects[0].additionalInformation.notes : "") +
(testType[0].defects[0].prohibitionIssued ? ", Prohibition was issued" : ", Prohibition was not issued") +
")";
}
if (defectsDetails) {
defects = `Defects: ${defectsDetails};\r\n`;
}
if (testType.reasonForAbandoning) {
reasonForAbandoning = `Reason for abandoning: ${testType.reasonForAbandoning};\r\n`;
if (testType[0].reasonForAbandoning) {
reasonForAbandoning = `Reason for abandoning: ${testType[0].reasonForAbandoning};\r\n`;
}
if (testType.additionalCommentsForAbandon) {
additionalCommentsAbandon = `Additional comments for abandon: ${testType.additionalCommentsForAbandon};\r\n`;
if (testType[0].additionalCommentsForAbandon) {
additionalCommentsAbandon = `Additional comments for abandon: ${testType[0].additionalCommentsForAbandon};\r\n`;
}
if (this.isPassingLECTestType(testType)) {
LECNotes = "Modification type: " + testType.modType.code.toUpperCase() + "\r\n" + "Fuel type: " + testType.fuelType + "\r\n" + "Emission standards: " + testType.emissionStandard + "\r\n";
LECNotes = "Modification type: " + (testType[0].modType! as ModTypeSchema).code.toUpperCase() + "\r\n" + "Fuel type: " + testType[0].fuelType + "\r\n" + "Emission standards: " + testType[0].emissionStandard + "\r\n";
}
detailsTemplate.activity.value = activity.activityType === "visit" ? ActivityType.TEST : ActivityType.WAIT_TIME;
detailsTemplate.startTime.value = moment(testType.testTypeStartTimestamp).tz(TimeZone.LONDON).format("HH:mm:ss");
detailsTemplate.finishTime.value = moment(testType.testTypeEndTimestamp).tz(TimeZone.LONDON).format("HH:mm:ss");
detailsTemplate.startTime.value = moment(testType[0].testTypeStartTimestamp).tz(TimeZone.LONDON).format("HH:mm:ss");
detailsTemplate.finishTime.value = moment(testType[0].testTypeEndTimestamp).tz(TimeZone.LONDON).format("HH:mm:ss");
detailsTemplate.vrm.value = testResult.vehicleType === VEHICLE_TYPES.TRL ? testResult.trailerId : testResult.vrm;
detailsTemplate.chassisNumber.value = testResult.vin;
detailsTemplate.testType.value = testType.testCode.toUpperCase();
detailsTemplate.testType.value = (testType[0] as TestTypeSchema).testCode?.toUpperCase();
detailsTemplate.seatsAndAxles.value = testResult.vehicleType === VEHICLE_TYPES.PSV ? testResult.numberOfSeats : testResult.noOfAxles;
detailsTemplate.result.value = testType.testResult;
detailsTemplate.certificateNumber.value = testType.certificateNumber;
detailsTemplate.expiryDate.value = testType.testExpiryDate ? moment(testType.testExpiryDate).tz(TimeZone.LONDON).format("DD/MM/YYYY") : "";
detailsTemplate.result.value = testType[0].testResult;
detailsTemplate.certificateNumber.value = testType[0].certificateNumber;
detailsTemplate.expiryDate.value = testType[0].testExpiryDate ? moment(testType[0].testExpiryDate).tz(TimeZone.LONDON).format("DD/MM/YYYY") : "";
detailsTemplate.preparerId.value = testResult.preparerId;
detailsTemplate.failureAdvisoryItemsQAIComments.value =
defects +
Expand All @@ -125,12 +126,12 @@ class RetroGenerationService {
"Additional test type notes: " +
additionalTestTypeNotes +
";\r\n" +
(testType.additionalNotesRecorded ? testType.additionalNotesRecorded + ";" : "");
(testType[0].additionalNotesRecorded ? testType[0].additionalNotesRecorded + ";" : "");
}
if (event.activityType === ActivityType.TIME_NOT_TESTING) {
// Populate wait activities in the report
const detailsTemplate: any = template.reportTemplate.activityDetails[i];
const waitActivityResult: any = event.activity;
const waitActivityResult: ActivitySchema = event.activity;
let waitReasons: string = "";
let additionalNotes: string = "";

Expand Down Expand Up @@ -171,16 +172,16 @@ class RetroGenerationService {
/**
* Method to collate testResults and waitActivities into a common list
* and then sort them on startTime to display the activities in a sequence.
* @param testResultsList: testResults list
* @param waitActivitiesList: wait activities list
* @param testResultsList
* @param waitActivitiesList
*/
public computeActivitiesList(testResultsList: TestResultSchema[], waitActivitiesList: ActivitySchema[]) {
const list: IActivitiesList[] = [];
// Adding Test results to the list
for (const testResult of testResultsList) {
const testResultTestType = testResult.testTypes as unknown as TestTypeSchema;
const testResultTestType = testResult.testTypes as TestTypeSchema[];
const act: IActivitiesList = {
startTime: testResultTestType.testTypeStartTimestamp!,
startTime: testResultTestType[0].testTypeStartTimestamp!,
activityType: ActivityType.TEST,
activity: testResult,
};
Expand All @@ -196,7 +197,8 @@ class RetroGenerationService {
list.push(act);
}
// Sorting the list by StartTime
const sortDateAsc = (date1: any, date2: any) => {
const sortDateAsc = (date1: IActivitiesList, date2: IActivitiesList) => {
console.log(date1)
const date = new Date(date1.startTime).toISOString();
const dateToCompare = new Date(date2.startTime).toISOString();
if (date > dateToCompare) {
Expand Down
Loading

0 comments on commit ed0d66d

Please sign in to comment.