Skip to content

Commit

Permalink
feat(CB2-12690): added activities and test results types
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Searle committed Jul 4, 2024
1 parent 12926f8 commit ba07b1f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 47 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@dvsa/cvs-type-definitions": "7.1.0",
"@aws-sdk/client-lambda": "^3.549.0",
"@aws-sdk/client-s3": "^3.550.0",
"@aws-sdk/client-secrets-manager": "^3.549.0",
Expand Down
72 changes: 36 additions & 36 deletions src/models/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,42 @@ interface IMOTConfig {
templateId: string;
}

interface IActivity {
id: string;
activityType: "visit" | "wait";
testStationName: string;
testStationPNumber: string;
testStationEmail: string;
testStationType: StationType;
testerName: string;
testerStaffId: string;
startTime: string;
endTime: string;
waitReason: [string];
notes: string;
}
// interface IActivity {
// id: string;
// activityType: "visit" | "wait";
// testStationName: string;
// testStationPNumber: string;
// testStationEmail: string;
// testStationType: StationType;
// testerName: string;
// testerStaffId: string;
// startTime: string;
// endTime: string;
// waitReason: [string];
// notes: string;
// }

interface ITestType {
testTypeStartTimestamp: string;
testTypeName: string;
testResult: string;
certificateNumber: string;
testExpiryDate: number;
testTypeEndTimeStamp: string;
}

interface ITestResults {
testerStaffId: string;
vrm: string;
testStationPNumber: string;
preparerId: string;
numberOfSeats: number;
testStartTimestamp: string;
testEndTimestamp: string;
testTypes: ITestType;
vin: string;
vehicleType: string;
}
// interface ITestType {
// testTypeStartTimestamp: string;
// testTypeName: string;
// testResult: string;
// certificateNumber: string;
// testExpiryDate: number;
// testTypeEndTimeStamp: string;
// }
//
// interface ITestResults {
// testerStaffId: string;
// vrm: string;
// testStationPNumber: string;
// preparerId: string;
// numberOfSeats: number;
// testStartTimestamp: string;
// testEndTimestamp: string;
// testTypes: ITestType;
// vin: string;
// vehicleType: string;
// }

interface IInvokeConfig {
params: { apiVersion: string; endpoint?: string };
Expand Down Expand Up @@ -102,4 +102,4 @@ interface IConfig {
invoke: IIndexInvokeConfig;
}

export { IS3Config, IActivity, IInvokeConfig, IMOTConfig, ITestResults, IActivitiesList, ISecretConfig, IConfig };
export { IS3Config, IInvokeConfig, IMOTConfig, IActivitiesList, ISecretConfig, IConfig };
5 changes: 3 additions & 2 deletions src/services/ActivitiesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import moment from "moment";
import { IInvokeConfig } from "../models";
import { Configuration } from "../utils/Configuration";
import { LambdaService } from "./LambdaService";
import { ActivitySchema } from "@dvsa/cvs-type-definitions/types/v1/activity";

class ActivitiesService {
private readonly lambdaClient: LambdaService;
Expand All @@ -18,7 +19,7 @@ class ActivitiesService {
* Retrieves Activities based on the provided parameters
* @param params - getActivities query parameters
*/
public getActivities(params: any): Promise<any> {
public getActivities(params: any): Promise<ActivitySchema[]> {
console.log(`getActivities called with params: ${JSON.stringify(params)}`);
const config: IInvokeConfig = this.config.getInvokeConfig();
const invokeParams: InvocationRequest = {
Expand All @@ -41,7 +42,7 @@ class ActivitiesService {

return this.lambdaClient.invoke(invokeParams).then((response: InvocationResponse) => {
const payload: any = this.lambdaClient.validateInvocationResponse(response); // Response validation
const activityResults: any[] = JSON.parse(payload.body); // Response conversion
const activityResults: ActivitySchema[] = JSON.parse(payload.body); // Response conversion
console.log(`Activities: ${activityResults.length}`);

// Sort results by startTime
Expand Down
4 changes: 2 additions & 2 deletions src/services/ReportGenerationService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ERRORS, STATUSES } from "../assets/enum";
import { IActivity } from "../models";
import { HTTPError } from "../models/HTTPError";
import { ActivitiesService } from "./ActivitiesService";
import { TestResultsService } from "./TestResultsService";
import { ActivitySchema } from "@dvsa/cvs-type-definitions/types/v1/activity";

class ReportGenerationService {
private readonly testResultsService: TestResultsService;
Expand All @@ -17,7 +17,7 @@ class ReportGenerationService {
* Generates the ATF report for a given activity
* @param activity - activity for which to generate the report
*/
public async generateATFReport(activity: IActivity): Promise<any> {
public async generateATFReport(activity: ActivitySchema): Promise<any> {
console.debug("Inside generateATFReport");
try {
const testResults = await this.testResultsService
Expand Down
15 changes: 10 additions & 5 deletions src/services/SendATFReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { LambdaClient } from "@aws-sdk/client-lambda";
// @ts-ignore
import { NotifyClient } from "notifications-node-client";
import { ACTIVITY_TYPE } from "../assets/enum";
import { IActivitiesList, IActivity, ITestResults } from "../models";
import { IActivitiesList } from "../models";
import { Configuration } from "../utils/Configuration";
import { NotificationData } from "../utils/generateNotificationData";
import { LambdaService } from "./LambdaService";
import { NotificationService } from "./NotificationService";
import { TestStationsService } from "./TestStationsService";
import { TestResultSchema, TestTypeSchema } from "@dvsa/cvs-type-definitions/types/v1/test-result";
import { ActivitySchema } from "@dvsa/cvs-type-definitions/types/v1/activity";

class SendATFReport {
public testStationsService: TestStationsService;
Expand Down Expand Up @@ -53,15 +55,18 @@ class SendATFReport {
/**
* 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: ITestResults[], waitActivitiesList: IActivity[]) {
public computeActivitiesList(testResultsList: TestResultSchema[], waitActivitiesList: ActivitySchema[]) {
const list: IActivitiesList[] = [];

// Adding Test activities to the list
for (const testResult of testResultsList) {
const testResultTestType = testResult.testTypes as unknown as TestTypeSchema;

const act: IActivitiesList = {
startTime: testResult.testTypes.testTypeStartTimestamp,
startTime: testResultTestType.testTypeStartTimestamp!,
activityType: ACTIVITY_TYPE.TEST,
activity: testResult,
};
Expand Down
5 changes: 3 additions & 2 deletions src/services/TestResultsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import moment from "moment";
import { IInvokeConfig } from "../models";
import { Configuration } from "../utils/Configuration";
import { LambdaService } from "./LambdaService";
import { TestResultSchema } from "@dvsa/cvs-type-definitions/types/v1/test-result";

class TestResultsService {
private readonly lambdaClient: LambdaService;
Expand All @@ -18,7 +19,7 @@ class TestResultsService {
* Retrieves test results based on the provided parameters
* @param params - getTestResultsByTesterStaffId query parameters
*/
public getTestResults(params: any): Promise<any> {
public getTestResults(params: any): Promise<TestResultSchema[]> {
console.debug(`inside get test results: ${JSON.stringify(params)}`);
const config: IInvokeConfig = this.config.getInvokeConfig();
const invokeParams: InvocationRequest = {
Expand All @@ -36,7 +37,7 @@ class TestResultsService {

return this.lambdaClient.invoke(invokeParams).then((response: InvocationResponse) => {
const payload: any = this.lambdaClient.validateInvocationResponse(response); // Response validation
const testResults: any[] = JSON.parse(payload.body); // Response conversion
const testResults: TestResultSchema[] = JSON.parse(payload.body); // Response conversion

console.debug(`test result response is: ${JSON.stringify(testResults)}`);
// Sort results by testTypeEndTimeStamp
Expand Down

0 comments on commit ba07b1f

Please sign in to comment.