Skip to content

Commit

Permalink
Feature/cb2 10594 (#80)
Browse files Browse the repository at this point in the history
* rectifying data type mismatches, add un-defined Enums and attributes, adding in-line comments

* add AdrCertificateDetails interface and parsing function

* adding guidanceNotes Enum

* adding m145 attribute as per documentation change

* feat: adr details added, test resource for technoical record added, unit test added

* style: rearrange enums

* fix: replace ! with ? for optional attributes

* fix: memosApplyEnum value updated

* fix: 2 new attributes added to adrDetails, as per documentation

* feat: tab le definition

* fix: enum updated

* feat: adr tables added to the tech record list of tables

* feat: new function added for partial upsert based on condition attribute

* feat: some adr table detail updated

* feat: upsert fun ctionality added for adr-details attributes in tech record

* feat: adr parts added to tech record integration test

* feat: docker's mysql image updated to version 8 - consistent with recent RDS engine upgarde for NOP

* feat: adr attribute values updated

* feat: test updated as adr attribute values updated in json file

* fix: changes reverted back to original

* fix: changes reverted back to original

* fix: changes reverted back to original

* feat: cleaning and bringing in adr pass certificate

* feat: cleaning and bringing in adr pass certificate

* feat: cleaning and bringing in adr pass certificate

* fix: removed async keyword to avoid error when running the test

* fix: bringing in to be able to run integration tests on my mac and be able to push changes into repo

* fix: bringing in to be able to run integration tests on my mac and be able to push changes into repo

* fix: bringing in to be able to run integration tests on my mac and be able to push changes into repo

* fix: updating adr pass certificate function

* fix: updating adr pass certificate field name

* fix: updating adr pass certificate var name

* feat: adding integration tests for additional test scenarios

* feat: adding adr pass certificate attribute

* feat: adding adr pass certificate attribute test to unit test

* fix: syntax fixed

---------

Co-authored-by: Meys Torkaman <meys.torkaman@MacBook-Pro.local>
Co-authored-by: meys-bjss <140601718+meys-bjss@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 12, 2024
1 parent 88d3f69 commit 577351f
Show file tree
Hide file tree
Showing 13 changed files with 2,361 additions and 41 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ For the full field-to-column mapping, see `tech-record-document-conversion.ts`.
* `microfilm`
* `plate`
* `axle`
* `adr_details`
* `adr_memos_apply`
* `adr_permitted_dangerous_goods`
* `adr_productListUnNo`
* `adr_additional_examiner_notes`
* `adr_additional_notes_number`


## Test Result conversion
For the full field-to-column mapping, see `test-result-record-conversion.ts`.
Expand Down
45 changes: 45 additions & 0 deletions src/models/adr-certificate-details.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { DynamoDbImage } from "../services/dynamodb-images";
import { Maybe } from "./optionals";

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

export type AdrPassCertificateDetails = AdrPassCertificateDetailsItems[];

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

export const parseAdrCertificateDetails = (
adrPassCertificateDetailsImage?: DynamoDbImage
): Maybe<AdrPassCertificateDetails> => {
if (!adrPassCertificateDetailsImage) {
return undefined;
}

const adrPassCertificateDetails: AdrPassCertificateDetails = [];

for (const key of adrPassCertificateDetailsImage.getKeys()) {
const adrPassCertificateDetailsItemImage = adrPassCertificateDetailsImage.getMap(
key
)!;
adrPassCertificateDetails.push({
createdByName: adrPassCertificateDetailsItemImage.getString(
"createdByName"
),
certificateType: adrPassCertificateDetailsItemImage.getString(
"certificateType"
) as AdrPassCertificateTypeEnum,
generatedTimestamp: adrPassCertificateDetailsItemImage.getDate(
"generatedTimestamp"
),
certificateId: adrPassCertificateDetailsItemImage.getString(
"certificateId"
),
});
}
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;
compatibilityGroupJ?: compatibilityGroupJEnum;
documents?: string[];
permittedDangerousGoods?: string[];
additionalExaminerNotes?: string;
permittedDangerousGoods?: permittedDangerousGoodsEnum[];
additionalExaminerNotes?: AdditionalExaminerNotes;
applicantDetails?: ApplicantDetails;
memosApply?: string[];
dangerousGoods?: boolean;
memosApply?: memosApplyEnum[];
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;
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[];
// 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
12 changes: 10 additions & 2 deletions src/models/tech-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ 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 {
AdrPassCertificateDetails,
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 +118,7 @@ export interface TechRecord {
noOfAxles?: number;
brakeCode?: string;
adrDetails?: AdrDetails;
adrPassCertificateDetails?: AdrPassCertificateDetails;
createdByName?: string;
createdById?: string;
lastUpdatedByName?: string;
Expand Down Expand Up @@ -270,7 +275,10 @@ 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")),
adrPassCertificateDetails: parseAdrCertificateDetails(
image.getList("adrPassCertificateDetails")
),
createdByName: image.getString("createdByName"),
createdById: image.getString("createdById"),
lastUpdatedByName: image.getString("lastUpdatedByName"),
Expand Down
Loading

0 comments on commit 577351f

Please sign in to comment.