Skip to content

Commit

Permalink
ORV2-2693 Add STOS permit templates to OnRouteBC (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Sep 24, 2024
1 parent 5986a0e commit 3fc25ed
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 16 deletions.
31 changes: 31 additions & 0 deletions database/mssql/scripts/versions/revert/v_43_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON

BEGIN TRY
BEGIN TRANSACTION

DELETE [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE DOCUMENT_ID IN (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-template-v1.docx')
DELETE [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE DOCUMENT_ID IN (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-void-template-v1.docx')
DELETE [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE DOCUMENT_ID IN (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-revoked-template-v1.docx')
DELETE [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-template-v1.docx'
DELETE [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-void-template-v1.docx'
DELETE [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-revoked-template-v1.docx'
COMMIT
END TRY

BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK;
THROW
END CATCH

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Revert STOS templates'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (42, @VersionDescription, getutcdate())
60 changes: 60 additions & 0 deletions database/mssql/scripts/versions/v_43_ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO

IF @@ERROR <> 0 SET NOEXEC ON
GO
INSERT [dops].[ORBC_DOCUMENT] ( [S3_OBJECT_ID], [S3_VERSION_ID], [S3_LOCATION], [OBJECT_MIME_TYPE], [FILE_NAME], [DMS_VERSION_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'273C4D93-544E-471B-ACB6-D79E51BE78DA', NULL, N'https://moti-int.objectstore.gov.bc.ca/tran_api_orbc_docs_dev/tran_api_orbc_docs_dev%40moti-int.objectstore.gov.bc.ca/273c4d93-544e-471b-acb6-d79e51be78da', N'application/vnd.openxmlformats-officedocument.wordprocessingml.document',N'stos-template-v1.docx',1, 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE())

IF @@ERROR <> 0 SET NOEXEC ON
GO
INSERT [dops].[ORBC_DOCUMENT] ( [S3_OBJECT_ID], [S3_VERSION_ID], [S3_LOCATION], [OBJECT_MIME_TYPE], [FILE_NAME], [DMS_VERSION_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'E28B476E-361E-45A8-A9A5-384C7F4CB8D8', NULL, N'https://moti-int.objectstore.gov.bc.ca/tran_api_orbc_docs_dev/tran_api_orbc_docs_dev%40moti-int.objectstore.gov.bc.ca/e28b476e-361e-45a8-a9a5-384c7f4cb8d8', N'application/vnd.openxmlformats-officedocument.wordprocessingml.document',N'stos-void-template-v1.docx',1, 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE())

IF @@ERROR <> 0 SET NOEXEC ON
GO
INSERT [dops].[ORBC_DOCUMENT] ( [S3_OBJECT_ID], [S3_VERSION_ID], [S3_LOCATION], [OBJECT_MIME_TYPE], [FILE_NAME], [DMS_VERSION_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'F5BAD4DC-A1AE-4ABF-98DC-17874871F882', NULL, N'https://moti-int.objectstore.gov.bc.ca/tran_api_orbc_docs_dev/tran_api_orbc_docs_dev%40moti-int.objectstore.gov.bc.ca/f5bad4dc-a1ae-4abf-98dc-17874871f882', N'application/vnd.openxmlformats-officedocument.wordprocessingml.document',N'stos-revoked-template-v1.docx',1, 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE())

IF @@ERROR <> 0 SET NOEXEC ON
GO
INSERT [dops].[ORBC_DOCUMENT_TEMPLATE] ( [TEMPLATE_NAME], [TEMPLATE_VERSION], [DOCUMENT_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'PERMIT_STOS', 1, (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-template-v1.docx'), 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE())
IF @@ERROR <> 0 SET NOEXEC ON
GO
INSERT [dops].[ORBC_DOCUMENT_TEMPLATE] ( [TEMPLATE_NAME], [TEMPLATE_VERSION], [DOCUMENT_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'PERMIT_STOS_VOID', 1, (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-void-template-v1.docx'), 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE())
IF @@ERROR <> 0 SET NOEXEC ON
GO
INSERT [dops].[ORBC_DOCUMENT_TEMPLATE] ( [TEMPLATE_NAME], [TEMPLATE_VERSION], [DOCUMENT_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'PERMIT_STOS_REVOKED', 1, (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-revoked-template-v1.docx'), 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE())

IF @@ERROR <> 0 SET NOEXEC ON
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'STOS permit templates.'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (43, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate())
IF @@ERROR <> 0 SET NOEXEC ON
GO

COMMIT TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @Success AS BIT
SET @Success = 1
SET NOEXEC OFF
IF (@Success = 1) PRINT 'The database update succeeded'
ELSE BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
PRINT 'The database update failed'
END
GO

5 changes: 5 additions & 0 deletions database/mssql/test/versions/v_43_1_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Test that the permit template have been configured correctly
SET NOCOUNT ON

SELECT COUNT(*) FROM $(DB_NAME).[dops].[ORBC_DOCUMENT_TEMPLATE]
WHERE TEMPLATE_NAME IN ('PERMIT','PERMIT_STOS_VOID','PERMIT_STOS_REVOKED')
6 changes: 6 additions & 0 deletions database/mssql/test/versions/v_43_2_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Test that the permit template have been configured correctly
SET NOCOUNT ON

SELECT COUNT(*) FROM $(DB_NAME).[dops].[ORBC_DOCUMENT]
WHERE ID IN (SELECT DOCUMENT_ID FROM $(DB_NAME).[dops].[ORBC_DOCUMENT_TEMPLATE]
WHERE TEMPLATE_NAME IN ('PERMIT','PERMIT_STOS_VOID','PERMIT_STOS_REVOKED'))
24 changes: 24 additions & 0 deletions database/mssql/test/versions/v_43_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Retrieve arguments
source ${SCRIPT_DIR}/utility/getopt.sh
USAGE="-u USER -p PASS -s SERVER -d DATABASE"
parse_options "${USAGE}" ${@}

# All database tests for database version 43 are run from this shell script.
# TESTS_DIR variable set by the calling test-runner script.

TEST_43_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_43_1_test.sql | xargs)
if [[ $TEST_43_1_RESULT -eq 3 ]]; then
echo "Test 43.1 passed: STOS templates setup successfully in ORBC_DOCUMENT_TEMPLATE"
else
echo "******** Test 43.1 failed: Failed to setup STOS permit templates"
fi


TEST_43_2_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_43_2_test.sql | xargs)
if [[ $TEST_43_2_RESULT -eq 3 ]]; then
echo "Test 43.2 passed: STOS templates setup successfully in ORBC_DOCUMENT"
else
echo "******** Test 43.2 failed: Failed to setup STOS permit templates"
fi
3 changes: 3 additions & 0 deletions dops/src/enum/template-name.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ export enum TemplateName {
PAYMENT_RECEIPT = 'PAYMENT_RECEIPT',
PERMIT_VOID = 'PERMIT_VOID',
PERMIT_REVOKED = 'PERMIT_REVOKED',
PERMIT_STOS = 'PERMIT_STOS',
PERMIT_STOS_VOID = 'PERMIT_STOS_VOID',
PERMIT_STOS_REVOKED = 'PERMIT_STOS_REVOKED',
}
12 changes: 12 additions & 0 deletions vehicles/src/common/enum/template-name.enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { ApplicationStatus } from './application-status.enum';
import { PermitType } from './permit-type.enum';

export enum TemplateName {
PERMIT = 'PERMIT',
PAYMENT_RECEIPT = 'PAYMENT_RECEIPT',
PERMIT_VOID = 'PERMIT_VOID',
PERMIT_REVOKED = 'PERMIT_REVOKED',
PERMIT_STOS = 'PERMIT_STOS',
PERMIT_STOS_VOID = 'PERMIT_STOS_VOID',
PERMIT_STOS_REVOKED = 'PERMIT_STOS_REVOKED',
}

export type PermitTemplateMapping = {
[K in ApplicationStatus]?: {
[T in PermitType | 'default']?: TemplateName;
};
};
45 changes: 45 additions & 0 deletions vehicles/src/common/helper/template.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { InternalServerErrorException } from '@nestjs/common';
import { ApplicationStatus } from '../enum/application-status.enum';
import { PermitType } from '../enum/permit-type.enum';
import {
PermitTemplateMapping,
TemplateName,
} from '../enum/template-name.enum';

/**
* Returns the appropriate template name based on the provided application status and permit type.
* Throws an error if the combination of status and type does not yield a valid template.
*
* @param {ApplicationStatus} status - The status of the application for which the template is required.
* @param {PermitType} type - The type of permit for which the template is required.
* @returns {TemplateName} - The template name corresponding to the status and type provided.
* @throws {InternalServerErrorException} - If no valid template is found for the given status.
*/
export const getPermitTemplateName = (
status: ApplicationStatus,
type: PermitType,
): TemplateName => {
const templateMapping: PermitTemplateMapping = {
[ApplicationStatus.ISSUED]: {
[PermitType.SINGLE_TRIP_OVERSIZE]: TemplateName.PERMIT_STOS,
default: TemplateName.PERMIT,
},
[ApplicationStatus.VOIDED]: {
[PermitType.SINGLE_TRIP_OVERSIZE]: TemplateName.PERMIT_STOS_VOID,
default: TemplateName.PERMIT_VOID,
},
[ApplicationStatus.REVOKED]: {
[PermitType.SINGLE_TRIP_OVERSIZE]: TemplateName.PERMIT_STOS_REVOKED,
default: TemplateName.PERMIT_REVOKED,
},
};

const template =
templateMapping[status]?.[type] || templateMapping[status]?.default;
if (!template) {
throw new InternalServerErrorException(
'Invalid status for document generation',
);
}
return template;
};
7 changes: 6 additions & 1 deletion vehicles/src/common/interface/permit.template.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface PermitData {
clientNumber: string;
vehicleConfiguration?: VehicleConfiguration;
applicationNotes?: string;
permittedCommodity?: string;
permittedCommodity?: PermittedCommodity;
permittedRoute?: PermittedRoute;
}

Expand All @@ -51,6 +51,11 @@ interface PermittedRoute {
manualRoute: ManualRoute;
}

interface PermittedCommodity {
commodityType: string;
loadDescription: string;
}

interface ManualRoute {
origin: string;
destination: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
generateFaxEmail,
validateEmailandFaxList,
} from '../../../common/helper/notification.helper';
import { getPermitTemplateName } from '../../../common/helper/template.helper';

@Injectable()
export class PermitReceiptDocumentService {
Expand Down Expand Up @@ -275,21 +276,10 @@ export class PermitReceiptDocumentService {
);

const dopsRequestData = {
templateName: (() => {
switch (fetchedPermit.permitStatus) {
case ApplicationStatus.ISSUED:
return TemplateName.PERMIT;
case ApplicationStatus.VOIDED:
return TemplateName.PERMIT_VOID;
case ApplicationStatus.REVOKED:
return TemplateName.PERMIT_REVOKED;
default:
// Handle the default case here, for example:
throw new InternalServerErrorException(
'Invalid status for document generation',
);
}
})(),
templateName: getPermitTemplateName(
fetchedPermit?.permitStatus,
fetchedPermit?.permitType,
),
generatedDocumentFileName: permitDataForTemplate.permitNumber,
templateData: permitDataForTemplate,
documentsToMerge: permitDataForTemplate.permitData.commodities.map(
Expand Down

0 comments on commit 3fc25ed

Please sign in to comment.