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

Feature/cb2 10593 - update parseAdrDetails function #78

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
49 changes: 49 additions & 0 deletions src/models/adr-certificate-details.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { DynamoDbImage } from "../services/dynamodb-images";
import { Maybe } from "./optionals";

// define AdrCertificateDetails' high-level attributes data types
export interface AdrCertificateDetails {
adrPassCertificateDetails?: AdrPassCertificateDetails;
}

// define Enums
export type certificateIdEnum =
| "PASS"
| "REPLACEMENT";

// define AdrCertificateDetails' sub-attributes data types
export type AdrPassCertificateDetails = AdrPassCertificateDetailsItems[];

export interface AdrPassCertificateDetailsItems {
createdByName?: string;
certificateType?: string;
generatedTimestamp?: string;
certificateId?: string;
}

// function to parse AdrCertificateDetails' high-level and sub attributes + return AdrCertificateDetails object
export const parseAdrCertificateDetails = (
certificateDetails?: DynamoDbImage
): Maybe<AdrCertificateDetails> => {
if (!certificateDetails) {
return undefined;
}

const adrPassCertificateDetailsImage: DynamoDbImage = certificateDetails.getList(
"adrPassCertificateDetails"
)!;
const adrPassCertificateDetails: AdrPassCertificateDetails = [];

for (const key of adrPassCertificateDetailsImage.getKeys()) {
const adrPassCertificateDetailsItemImage = adrPassCertificateDetailsImage.getMap(key)!;
adrPassCertificateDetails.push({
createdByName: adrPassCertificateDetailsItemImage.getString("createdByName"),
certificateType: adrPassCertificateDetailsItemImage.getString("certificateType"),
generatedTimestamp: adrPassCertificateDetailsItemImage.getString("generatedTimestamp"),
certificateId: adrPassCertificateDetailsItemImage.getString("certificateId") as certificateIdEnum,
});
}
return {
adrPassCertificateDetails
};
};
153 changes: 125 additions & 28 deletions src/models/adr-details.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DynamoDbImage, parseStringArray } from "../services/dynamodb-images";
import { Maybe } from "./optionals";

// define AdrDetails' high-level attributes data types
export interface AdrDetails {
vehicleDetails?: VehicleDetails;
listStatementApplicable?: boolean;
Expand All @@ -9,24 +10,101 @@ export interface AdrDetails {
brakeDeclarationsSeen?: boolean;
brakeDeclarationIssuer?: string;
brakeEndurance?: boolean;
weight?: string;
compatibilityGroupJ?: boolean;
weight?: number;
newCertificateRequested?: boolean;
Copy link

@simontindallbjss simontindallbjss Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required as it is a front end field for UX

Copy link
Contributor

@Nat-McCabe-BJSS Nat-McCabe-BJSS Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weight is listed as a number in ADR section, so I would presume that is required, it's how I've done it in Pydantic. CompatibilityGroupJ should still be listed though no? NewCertificateRequested is also in the ADR section documentation that should also be needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simontindallbjss, newCertificateRequested is removed from the final upsert function for now, so it wouldn't end up in NOP. we can always add it whenever needed. Note that all the attributes are defined as 'optional', so fine if they don't exist in the payload.

compatibilityGroupJ?: compatibilityGroupJEnum;
documents?: string[];
permittedDangerousGoods?: string[];
additionalExaminerNotes?: string;
permittedDangerousGoods?: permittedDangerousGoodsEnum[];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADR documentation states that this shouldn't be an enum in the backend due to the historic data containing erroneous values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As previously discussed with @reisedawson-bjss, at this stage, we are going to keep them as Enums. After the first round of remediation (hopefully in pre-prod), if this creates a massive issue, we can always turn them into
general "string" type.

additionalExaminerNotes?: AdditionalExaminerNotes;
applicantDetails?: ApplicantDetails;
memosApply?: string[];
dangerousGoods?: boolean;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required as it is a front end field for UX

Copy link
Author

@meys-bjss meys-bjss Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as newCertificateRequested case

memosApply?: memosApplyEnum[];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADR documentation states that this shouldn't be an enum in the backend due to the historic data containing erroneous values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as permittedDangerousGoodsEnum case

m145Statement?: boolean;
additionalNotes?: AdditionalNotes;
adrTypeApprovalNo?: string;
adrCertificateNotes?: string;
tank?: Tank;
}

// define Enums
export type VehicleDetailsTypeEnum =
| "Artic tractor"
| "Rigid box body"
| "Rigid sheeted load"
| "Rigid tank"
| "Rigid skeletal"
| "Rigid battery"
| "Full drawbar box body"
| "Full drawbar sheeted load"
| "Full drawbar tank"
| "Full drawbar skeletal"
| "Full drawbar battery"
| "Centre axle box body"
| "Centre axle sheeted load"
| "Centre axle tank"
| "Centre axle skeletal"
| "Centre axle battery"
| "Semi trailer box body"
| "Semi trailer sheeted load"
| "Semi trailer tank"
| "Semi trailer skeletal"
| "Semi trailer battery";

export type Tc2TypeEnum = "initial";

export type Tc3TypeEnum =
| "intermediate"
| "periodic"
| "exceptional";

export type permittedDangerousGoodsEnum =
| "FP <61 (FL)"
| "AT"
| "Class 5.1 Hydrogen Peroxide (OX)"
| "MEMU"
| "Carbon Disulphide"
| "Hydrogen"
| "Explosives (type 2)"
| "Explosives (type 3)";

export type compatibilityGroupJEnum =
| "I"
| "E";

export type additionalNotesNumberEnum =
| "1"
| "1A"
| "2"
| "3"
| "V1B"
| "T1B";

// export type additionalNotesguidanceNotesEnum = "New certificate requested" | "M145 Statement"

export type substancesPermittedEnum =
| "Substances permitted under the tank code and any special provisions specified in 9 may be carried"
| "Substances (Class UN number and if necessary packing group and proper shipping name) may be carried";

export type memosApplyEnum = "07/09 3mth leak ext ";

export type tankStatementSelectEnum =
| "Statement"
| "Product list";

// define AdrDetails' sub-attributes data types
export interface VehicleDetails {
type?: string;
type?: VehicleDetailsTypeEnum;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a string in the backend

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as permittedDangerousGoodsEnum case

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADR documentation states that this shouldn't be an enum in the backend due to the historic data containing erroneous values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as permittedDangerousGoodsEnum case

approvalDate?: string;
}

export type AdditionalExaminerNotes = AdditionalExaminerNotesItems[];

export interface AdditionalExaminerNotesItems {
note?: string;
createdAtDate?: string;
lastUpdatedBy?: string;
}

export interface ApplicantDetails {
name?: string;
street?: string;
Expand All @@ -36,8 +114,8 @@ export interface ApplicantDetails {
}

export interface AdditionalNotes {
number?: string[];
guidanceNotes?: string[];
number?: additionalNotesNumberEnum[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be array of strings in backend

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADR documentation states that this shouldn't be an enum in the backend due to the historic data containing erroneous values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as permittedDangerousGoodsEnum case

// guidanceNotes?: additionalNotesguidanceNotesEnum[];
}

export interface Tank {
Expand All @@ -57,31 +135,30 @@ export interface TankDetails {
}

export interface TankStatement {
substancesPermitted?: string;
select?: tankStatementSelectEnum;
substancesPermitted?: substancesPermittedEnum;
statement?: string;
productListRefNo?: string;
productListUnNo?: string[];
productList?: string;
}

export interface Tc2Details {
tc2Type?: Tc2Type;
tc2Type?: Tc2TypeEnum;
tc2IntermediateApprovalNo?: string;
tc2IntermediateExpiryDate?: string;
}

export type Tc2Type = "initial";

export type Tc3Details = Tc3DetailsItem[];

export interface Tc3DetailsItem {
tc3Type?: Tc3Type;
tc3Type?: Tc3TypeEnum;
tc3PeriodicNumber?: string;
tc3PeriodicExpiryDate?: string;
}

export type Tc3Type = "intermediate" | "periodic" | "exceptional";

// function to parse AdrDetails' high-level and sub attributes + return AdrDetails object
export const parseAdrDetails = (
adrDetails?: DynamoDbImage
): Maybe<AdrDetails> => {
Expand All @@ -93,10 +170,10 @@ export const parseAdrDetails = (
"additionalNotes"
)!;
const additionalNotes: AdditionalNotes = {
number: parseStringArray(additionalNotesImage.getList("number")),
guidanceNotes: parseStringArray(
additionalNotesImage.getList("guidanceNotes")
),
number: parseStringArray(additionalNotesImage.getList("number")) as additionalNotesNumberEnum[],
// guidanceNotes: parseStringArray(
// additionalNotesImage.getList("guidanceNotes")
// ) as additionalNotesguidanceNotesEnum[],
};

const applicantDetailsImage: DynamoDbImage = adrDetails.getMap(
Expand All @@ -114,7 +191,7 @@ export const parseAdrDetails = (
"vehicleDetails"
)!;
const vehicleDetails: VehicleDetails = {
type: vehicleDetailsImage.getString("type"),
type: vehicleDetailsImage.getString("type") as VehicleDetailsTypeEnum,
approvalDate: vehicleDetailsImage.getString("approvalDate"),
};

Expand All @@ -124,7 +201,7 @@ export const parseAdrDetails = (

const tc2DetailsImage: DynamoDbImage = tankDetailsImage.getMap("tc2Details")!;
const tc2Details: Tc2Details = {
tc2Type: tc2DetailsImage.getString("tc2Type") as Tc2Type,
tc2Type: tc2DetailsImage.getString("tc2Type") as Tc2TypeEnum,
tc2IntermediateApprovalNo: tc2DetailsImage.getString(
"tc2IntermediateApprovalNo"
),
Expand All @@ -141,7 +218,7 @@ export const parseAdrDetails = (
for (const key of tc3DetailsImage.getKeys()) {
const tc3DetailsItemImage = tc3DetailsImage.getMap(key)!;
tc3Details.push({
tc3Type: tc3DetailsItemImage.getString("tc3Type") as Tc3Type,
tc3Type: tc3DetailsItemImage.getString("tc3Type") as Tc3TypeEnum,
tc3PeriodicNumber: tc3DetailsItemImage.getString("tc3PeriodicNumber"),
tc3PeriodicExpiryDate: tc3DetailsItemImage.getString(
"tc3PeriodicExpiryDate"
Expand All @@ -151,7 +228,7 @@ export const parseAdrDetails = (

const tankDetails: TankDetails = {
tankManufacturer: tankDetailsImage.getString("tankManufacturer"),
yearOfManufacture: 0,
yearOfManufacture: tankDetailsImage.getNumber("yearOfManufacture"),
tankCode: tankDetailsImage.getString("tankCode"),
specialProvisions: tankDetailsImage.getString("specialProvisions"),
tankManufacturerSerialNo: tankDetailsImage.getString(
Expand All @@ -164,7 +241,8 @@ export const parseAdrDetails = (

const tankStatementImage: DynamoDbImage = tankImage.getMap("tankStatement")!;
const tankStatement: TankStatement = {
substancesPermitted: tankStatementImage.getString("substancesPermitted"),
substancesPermitted: tankStatementImage.getString("substancesPermitted") as substancesPermittedEnum,
select: tankStatementImage.getString("select") as tankStatementSelectEnum,
statement: tankStatementImage.getString("statement"),
productListRefNo: tankStatementImage.getString("productListRefNo"),
productListUnNo: parseStringArray(
Expand All @@ -178,6 +256,22 @@ export const parseAdrDetails = (
tankStatement,
};


const additionalExaminerNotesImage: DynamoDbImage = adrDetails.getList(
"additionalExaminerNotes"
)!;
const additionalExaminerNotes: AdditionalExaminerNotes = [];

for (const key of additionalExaminerNotesImage.getKeys()) {
const additionalExaminerNotesItemImage = additionalExaminerNotesImage.getMap(key)!;
additionalExaminerNotes.push({
note: additionalExaminerNotesItemImage.getString("note"),
createdAtDate: additionalExaminerNotesItemImage.getString("createdAtDate"),
lastUpdatedBy: additionalExaminerNotesItemImage.getString("lastUpdatedBy"),
});
}


return {
vehicleDetails,
listStatementApplicable: adrDetails.getBoolean("listStatementApplicable"),
Expand All @@ -186,15 +280,18 @@ export const parseAdrDetails = (
brakeDeclarationsSeen: adrDetails.getBoolean("brakeDeclarationsSeen"),
brakeDeclarationIssuer: adrDetails.getString("brakeDeclarationIssuer"),
brakeEndurance: adrDetails.getBoolean("brakeEndurance"),
weight: adrDetails.getString("weight"),
compatibilityGroupJ: adrDetails.getBoolean("compatibilityGroupJ"),
weight: adrDetails.getNumber("weight"),
newCertificateRequested: adrDetails.getBoolean("newCertificateRequested"),
compatibilityGroupJ: adrDetails.getString("compatibilityGroupJ") as compatibilityGroupJEnum,
documents: parseStringArray(adrDetails.getList("documents")),
permittedDangerousGoods: parseStringArray(
adrDetails.getList("permittedDangerousGoods")
),
additionalExaminerNotes: adrDetails.getString("additionalExaminerNotes"),
) as permittedDangerousGoodsEnum[],
additionalExaminerNotes,
applicantDetails,
memosApply: parseStringArray(adrDetails.getList("memosApply")),
dangerousGoods: adrDetails.getBoolean("dangerousGoods"),
memosApply: parseStringArray(adrDetails.getList("memosApply")) as memosApplyEnum[],
m145Statement: adrDetails.getBoolean("m145Statement"),
additionalNotes,
adrTypeApprovalNo: adrDetails.getString("adrTypeApprovalNo"),
adrCertificateNotes: adrDetails.getString("adrCertificateNotes"),
Expand Down
7 changes: 5 additions & 2 deletions src/models/tech-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { Microfilm, parseMicrofilm } from "./microfilm";
import { parsePlates, Plates } from "./plates";
import { BodyType, parseBodyType } from "./body-type";
import { Dimensions, parseDimensions } from "./dimensions";
import { AdrDetails } from "./adr-details";
import { AdrDetails, parseAdrDetails } from "./adr-details";
import { AdrCertificateDetails, parseAdrCertificateDetails } from "./adr-certificate-details";
import { parseVehicleClass, VehicleClass } from "./vehicle-class";
import { Brakes, parseBrakes } from "./brakes";
import { Axles, parseAxles } from "./axles";
Expand Down Expand Up @@ -114,6 +115,7 @@ export interface TechRecord {
noOfAxles?: number;
brakeCode?: string;
adrDetails?: AdrDetails;
adrCertificateDetails?: AdrCertificateDetails;
createdByName?: string;
createdById?: string;
lastUpdatedByName?: string;
Expand Down Expand Up @@ -270,7 +272,8 @@ const parseTechRecord = (image: DynamoDbImage): TechRecord => {
notes: image.getString("notes"),
noOfAxles: image.getNumber("noOfAxles"),
brakeCode: image.getString("brakeCode"),
adrDetails: undefined, // intentional - not implemented. parseAdrDetails(image.getMap("adrDetails"))
adrDetails: parseAdrDetails(image.getMap("adrDetails")),
adrCertificateDetails: parseAdrCertificateDetails(image.getMap("certificateDetails")),
createdByName: image.getString("createdByName"),
createdById: image.getString("createdById"),
lastUpdatedByName: image.getString("lastUpdatedByName"),
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Match Aurora MySQL version as closely as possible
FROM mysql:5.7.12
FROM mysql:8.0.32

ENV MYSQL_DATABASE=CVSBNOP \
MYSQL_ROOT_PASSWORD=12345
Expand Down
Loading
Loading