Skip to content

Commit

Permalink
feat(cb2-12692): Implement Types Definition into cert-gen (#197)
Browse files Browse the repository at this point in the history
* feat(cb2-12692): use types definition and common constants

* feat(cb2-12692): use types definition and common constants
  • Loading branch information
cb-cs authored Nov 18, 2024
1 parent 76a4635 commit 87449da
Show file tree
Hide file tree
Showing 21 changed files with 1,053 additions and 518 deletions.
30 changes: 22 additions & 8 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"@aws-sdk/client-s3": "^3.564.0",
"@aws-sdk/client-secrets-manager": "^3.564.0",
"@dvsa/cvs-feature-flags": "^0.13.0",
"@dvsa/cvs-type-definitions": "^2.1.11",
"@dvsa/cvs-type-definitions": "^7.6.3",
"@dvsa/cvs-microservice-common": "^1.2.4",
"@smithy/types": "^2.12.0",
"@smithy/util-utf8": "^2.3.0",
"aws-lambda": "^1.0.5",
Expand Down
3 changes: 1 addition & 2 deletions src/certificate/commands/DefectsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Service } from 'typedi';
import { DefectRepository } from '../../defect/DefectRepository';
import { DefectService } from '../../defect/DefectService';
import { ITestResult } from '../../models';
import { IFlatDefect, ITestResult } from '../../models';
import { ICertificatePayload } from '../../models';
import { ITestType } from '../../models';
import { CERTIFICATE_DATA, TEST_RESULTS } from '../../models/Enums';
import { IFlatDefect } from '../../models/IFlatDefect';
import { BasePayloadCommand } from '../ICertificatePayloadCommand';

@Service()
Expand Down
3 changes: 1 addition & 2 deletions src/defect/DefectRepository.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { InvocationRequest, InvocationResponse } from '@aws-sdk/client-lambda';
import { toUint8Array } from '@smithy/util-utf8';
import { Service } from 'typedi';
import { IInvokeConfig } from '../models';
import { IDefectParent, IInvokeConfig } from '../models';
import { ERRORS } from '../models/Enums';
import { HTTPError } from '../models/HTTPError';
import { IDefectParent } from '../models/IDefectParent';
import { LambdaService } from '../services/LambdaService';
import { Configuration } from '../utils/Configuration';

Expand Down
6 changes: 1 addition & 5 deletions src/defect/DefectService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Service } from 'typedi';
import { ICustomDefect } from '../models';
import { ICustomDefect, IDefectChild, IDefectParent, IFlatDefect, IItem } from '../models';
import { CERTIFICATE_DATA, IVA_30, LOCATION_ENGLISH, LOCATION_WELSH, TEST_RESULTS } from '../models/Enums';
import { IDefectChild } from '../models/IDefectChild';
import { IDefectParent } from '../models/IDefectParent';
import { IFlatDefect } from '../models/IFlatDefect';
import { IItem } from '../models/IItem';
import { TestResultService } from '../test-result/TestResultService';

@Service()
Expand Down
5 changes: 3 additions & 2 deletions src/functions/CertificateRequestProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DeleteObjectCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
import { TestStatus } from '@dvsa/cvs-type-definitions/types/v1/enums/testStatus.enum';
import { Service } from 'typedi';
import { validate as uuidValidate } from 'uuid';
import { ITestResult } from '../models';
import { ERRORS, TEST_RESULT_STATUS } from '../models/Enums';
import { ERRORS } from '../models/Enums';
import { CertificateGenerationService } from '../services/CertificateGenerationService';
import { CertificateUploadService } from '../services/CertificateUploadService';

Expand All @@ -16,7 +17,7 @@ export class CertificateRequestProcessor {
) {}

public async process(testResult: ITestResult): Promise<CertGenReturn> {
const isCancelled = testResult.testStatus === TEST_RESULT_STATUS.CANCELLED;
const isCancelled = testResult.testStatus === TestStatus.CANCELLED;
if (isCancelled) {
return this.remove(testResult);
}
Expand Down
52 changes: 0 additions & 52 deletions src/models/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export enum TEST_RESULTS {
PRS = 'prs',
}

export enum TEST_RESULT_STATUS {
SUBMITTED = 'submitted',
CANCELLED = 'cancelled',
}

export enum CERTIFICATE_DATA {
RWT_DATA = 'RWT_DATA',
PASS_DATA = 'PASS_DATA',
Expand Down Expand Up @@ -68,53 +63,6 @@ export enum IVA_30 {
EMPTY_CUSTOM_DEFECTS = 'N/A',
}

export const ADR_TEST = {
IDS: ['50', '59', '60'],
};

export const BASIC_IVA_TEST = {
IDS: ['125', '129', '154', '158', '159', '185'],
};

export const IVA30_TEST = {
IDS: [
'125',
'126',
'128',
'129',
'130',
'153',
'154',
'158',
'159',
'161',
'162',
'163',
'184',
'185',
'186',
'187',
'188',
'189',
'190',
'191',
'192',
'193',
'194',
'195',
'196',
'197',
],
};

export const MSVA30_TEST = {
IDS: ['133', '134', '135', '136', '138', '139', '140', '166', '167', '169', '170', '172', '173'],
};

export const HGV_TRL_ROADWORTHINESS_TEST_TYPES = {
IDS: ['62', '63', '91', '101', '122'],
};

export const AVAILABLE_WELSH = {
CERTIFICATES: [
'hgv_pass',
Expand Down
6 changes: 0 additions & 6 deletions src/models/IDefectChild.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/models/IDefectParent.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/models/IFlatDefect.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/models/IItem.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/models/ISecret.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/models/ITestStations.ts

This file was deleted.

73 changes: 29 additions & 44 deletions src/models/Types.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
import { TechRecordCompleteCarSchema } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/car/complete';
import { TechRecordSkeletonCarSchema } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/car/skeleton';
import { GETHGVTechnicalRecordV3Complete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete';
import { GETHGVTechnicalRecordV3Skeleton } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/skeleton';
import { GETHGVTechnicalRecordV3Testable } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/testable';
import { TechRecordCompleteMotorcycleSchema } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/motorcycle/complete';
import { GETPSVTechnicalRecordV3Complete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/psv/complete';
import { GETPSVTechnicalRecordV3Skeleton } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/psv/skeleton';
import { GETPSVTechnicalRecordV3Testable } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/psv/testable';
import { GETTRLTechnicalRecordV3Complete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/trl/complete';
import { GETTRLTechnicalRecordV3Skeleton } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/trl/skeleton';
import { GETTRLTechnicalRecordV3Testable } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/trl/testable';
import { TechRecordGETCarComplete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/car/complete';
import { TechRecordGETCarSkeleton } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/car/skeleton';
import { TechRecordGETHGVComplete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete';
import { TechRecordGETHGVSkeleton } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/skeleton';
import { TechRecordGETHGVTestable } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/testable';
import { TechRecordGETMotorcycleComplete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/motorcycle/complete';
import { TechRecordGETPSVComplete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/psv/complete';
import { TechRecordGETPSVSkeleton } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/psv/skeleton';
import { TechRecordGETPSVTestable } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/psv/testable';
import { TechRecordGETTRLComplete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/trl/complete';
import { TechRecordGETTRLSkeleton } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/trl/skeleton';
import { TechRecordGETTRLTestable } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/trl/testable';

export type TechRecordGet =
| TechRecordCompleteCarSchema
| TechRecordSkeletonCarSchema
| GETHGVTechnicalRecordV3Complete
| GETHGVTechnicalRecordV3Testable
| GETHGVTechnicalRecordV3Skeleton
| TechRecordCompleteMotorcycleSchema
| GETPSVTechnicalRecordV3Complete
| GETPSVTechnicalRecordV3Testable
| GETPSVTechnicalRecordV3Skeleton
| GETTRLTechnicalRecordV3Complete
| GETTRLTechnicalRecordV3Testable
| GETTRLTechnicalRecordV3Skeleton;
| TechRecordGETCarComplete
| TechRecordGETCarSkeleton
| TechRecordGETHGVComplete
| TechRecordGETHGVTestable
| TechRecordGETHGVSkeleton
| TechRecordGETMotorcycleComplete
| TechRecordGETPSVComplete
| TechRecordGETPSVTestable
| TechRecordGETPSVSkeleton
| TechRecordGETTRLComplete
| TechRecordGETTRLTestable
| TechRecordGETTRLSkeleton;

export type TechRecordType<T extends TechRecordGet['techRecord_vehicleType']> = T extends 'car' | 'lgv'
? TechRecordCompleteCarSchema
? TechRecordGETCarComplete
: T extends 'hgv'
? GETHGVTechnicalRecordV3Complete | GETHGVTechnicalRecordV3Testable
? TechRecordGETHGVComplete | TechRecordGETHGVTestable
: T extends 'motorcycle'
? TechRecordCompleteMotorcycleSchema
? TechRecordGETMotorcycleComplete
: T extends 'psv'
? GETPSVTechnicalRecordV3Complete | GETPSVTechnicalRecordV3Testable
? TechRecordGETPSVComplete | TechRecordGETPSVTestable
: T extends 'trl'
? GETTRLTechnicalRecordV3Complete | GETTRLTechnicalRecordV3Testable
? TechRecordGETTRLComplete | TechRecordGETTRLTestable
: never;

export interface ISearchResult {
systemNumber: string;
createdTimestamp: string;
vin: string;
primaryVrm?: string;
trailerId?: string;
techRecord_vehicleType: string;
techRecord_manufactureYear?: number | null;
techRecord_chassisMake?: string;
techRecord_chassisModel?: string;
techRecord_make?: string;
techRecord_model?: string;
techRecord_statusCode?: string;
}
Loading

0 comments on commit 87449da

Please sign in to comment.