Skip to content

Commit

Permalink
feat(CB2-11360): cherished transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Searle committed May 24, 2024
1 parent 75cb292 commit d8462a9
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions src/handler/mot-update-vrm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ export const handler = async (event: SQSEvent): Promise<void> => {
};

const processRecord = async (cherishedTransfer: SQSRecord): Promise<SNSMessageBody[]> => {
console.log('processing record...');
const parsedRecord = JSON.parse(cherishedTransfer.body) as MotCherishedTransfer;
const allRecords = await searchByCriteria(SearchCriteria.VIN, parsedRecord.vin);

if (!allRecords.length) {
logger.info(`No record found for VIN: ${parsedRecord.vin}`);
return [];
}
logger.info('records found from search');

const allCurrentRecords = allRecords.filter(({ techRecord_statusCode }) => techRecord_statusCode === StatusCode.CURRENT);

Expand All @@ -65,9 +63,6 @@ const processRecord = async (cherishedTransfer: SQSRecord): Promise<SNSMessageBo
logger.info(`Duplicate current records found for VIN ${parsedRecord.vin}`);
return [];
}

logger.info('current record found for vin');

const currentRecord = allCurrentRecords[0];
if (currentRecord.primaryVrm === parsedRecord.vrm) {
logger.info(`No update needed for VRM ${parsedRecord.vrm} and VIN ${parsedRecord.vin}`);
Expand All @@ -79,9 +74,6 @@ const processRecord = async (cherishedTransfer: SQSRecord): Promise<SNSMessageBo
currentRecord.createdTimestamp,
);

logger.info('completeTechRecord found for VIN');
logger.info(completeTechRecord);

const { recordsToArchive, recordsToUpdate } = processCherishedTransfer(
{
msOid: SYSTEM_USER,
Expand All @@ -91,48 +83,28 @@ const processRecord = async (cherishedTransfer: SQSRecord): Promise<SNSMessageBo
parsedRecord.vrm,
completeTechRecord,
);

logger.info('processed cherished transfer');

await updateVehicle(recordsToArchive, recordsToUpdate);
logger.info(`Updated systemNumber ${currentRecord.systemNumber} with VRM ${parsedRecord.vrm}`);

logger.info('creating new adr cert');
const newAdrCertificate = createAdrCertificate(currentRecord.systemNumber);

logger.info('newAdrCertificate');
logger.info(newAdrCertificate);

const adrCertificateDetailsErrors = validateAdrCertificateDetails(newAdrCertificate);
if (adrCertificateDetailsErrors) {
logger.info(`error adr certificate details: ${adrCertificateDetailsErrors.body}`);
addHttpHeaders(adrCertificateDetailsErrors);
return [];
}
logger.info('no adr certificate errors');

logger.info('formatting technical record');

const formattedTechRecord = formatTechRecord<TechRecordTypeByVehicle<'hgv' | 'trl' | 'lgv'>>(completeTechRecord);
formattedTechRecord.techRecord_adrPassCertificateDetails = formattedTechRecord.techRecord_adrPassCertificateDetails
? [...formattedTechRecord.techRecord_adrPassCertificateDetails, newAdrCertificate]
: [newAdrCertificate];

logger.info(formattedTechRecord);
logger.info('formatting technical record completed');

const adrCertSqsPayload: SQSRequestBody = {
techRecord: formattedTechRecord,
adrCertificate: newAdrCertificate,
documentName: DocumentName.ADR_PASS_CERTIFICATE,
recipientEmailAddress: '',
};

logger.info('adr cert payload');
logger.info(adrCertSqsPayload);

await addToSqs(adrCertSqsPayload, process.env.DOC_GEN_SQS_QUEUE ?? '');
logger.info('added to sqs queue');
return recordsToUpdate.map((record) => ({ ...record, userEmail: SYSTEM_USER }));
};

Expand Down

0 comments on commit d8462a9

Please sign in to comment.