Skip to content

Commit

Permalink
feat:ORV2-2922: GL Code Update (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Oct 9, 2024
1 parent 2ef35fe commit a2d5b14
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SET NOCOUNT ON
GO
UPDATE [permit].[ORBC_PAYMENT_METHOD_TYPE] SET GL_PROJ_CODE='$(GL_PROJ_CODE)' WHERE PAYMENT_METHOD_TYPE= '$(PAYMENT_METHOD_TYPE)'
GO
18 changes: 16 additions & 2 deletions database/mssql/scripts/utility/refresh-paybc-gl-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ source ${SCRIPT_DIR}/utility/getopt.sh
USAGE="-u ORBC_USER -p ORBC_PASS -s ORBC_SERVER -d ORBC_DATABASE"
parse_options "${USAGE}" ${@}

# Clear out all records from the pending IDIR users table
# Clear out GL Codes from the permit type table
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; UPDATE permit.ORBC_PERMIT_TYPE SET GL_CODE=NULL"
# Clear out GL Proj Codes from the payment method type table
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; UPDATE permit.ORBC_PAYMENT_METHOD_TYPE SET GL_PROJ_CODE=NULL"

(
# PAYBC_GL_CODE environment variable must be a string representing an array
# of tuples in the format PERMIT_TUPE,GL_CODE separated by single space characters.
# of tuples in the format PERMIT_TYPE,GL_CODE separated by single space characters.
# For example "TROS,000.00000.00000.0000.0000000.000000.0000 TROW,EOF000.00000.00000.0000.0000000.000000.0000"
for i in ${PAYBC_GL_CODE}
do
Expand All @@ -19,3 +21,15 @@ do
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -v PERMIT_TYPE=${1} GL_CODE=${2} -i ${SCRIPT_DIR}/sampledata/permit.ORBC_PERMIT_TYPE.Table.sql
done
)

(
# GL_PROJ_CODE environment variable must be a string representing an array
# of tuples in the format PAYMENT_METHOD_TYPE,GL_PROJ_CODE separated by single space characters.
# For example "WEB,0000000 ICEPAY,0000000"
for i in ${GL_PROJ_CODE}
do
IFS=","; set -- $i
echo "Updating payment method type ${1} with GL_PROJ_CODE ${2}"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -v PAYMENT_METHOD_TYPE=${1} GL_PROJ_CODE=${2} -i ${SCRIPT_DIR}/sampledata/permit.ORBC_PAYMENT_METHOD_TYPE.Table.sql
done
)
27 changes: 27 additions & 0 deletions database/mssql/scripts/versions/revert/v_45_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON

BEGIN TRY
BEGIN TRANSACTION

ALTER TABLE [permit].[ORBC_PAYMENT_METHOD_TYPE] DROP COLUMN [GL_PROJ_CODE];

COMMIT
END TRY

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

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Reverting addition of GL_PROJ_CODE to ORBC_PAYMENT_METHOD_TYPE.'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (44, @VersionDescription, getutcdate())
45 changes: 45 additions & 0 deletions database/mssql/scripts/versions/v_45_ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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
ALTER TABLE [permit].[ORBC_PAYMENT_METHOD_TYPE] ADD [GL_PROJ_CODE] [char] (7) NULL
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'GL Project Code' , @level0type=N'SCHEMA',@level0name=N'permit', @level1type=N'TABLE',@level1name=N'ORBC_PAYMENT_METHOD_TYPE', @level2type=N'COLUMN',@level2name=N'GL_PROJ_CODE'
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Add GL_PROJ_CODE col to ORBC_PAYMENT_METHOD_TYPE'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (45, @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

4 changes: 4 additions & 0 deletions database/mssql/test/versions/v_45_1_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Test that the GL_PROJ_CODE column has been added correctly
SET NOCOUNT ON

select COL_LENGTH('$(DB_NAME).[permit].[ORBC_PAYMENT_METHOD_TYPE]', 'GL_PROJ_CODE')
16 changes: 16 additions & 0 deletions database/mssql/test/versions/v_45_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/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 45 are run from this shell script.
# TESTS_DIR variable set by the calling test-runner script.

TEST_45_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_45_1_test.sql | xargs)
if [[ $TEST_45_1_RESULT -eq 7 ]]; then
echo "Test 45.1 passed: GL_PROJ_CODE column created in ORBC_PAYMENT_METHOD_TYPE"
else
echo "******** Test 45.1 failed: GL_PROJ_CODE column missing in ORBC_PAYMENT_METHOD_TYPE"
fi
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
MSSQL_RUN_TESTS: ${MSSQL_RUN_TESTS}
SAMPLE_PENDING_IDIR_USERS: ${SAMPLE_PENDING_IDIR_USERS}
PAYBC_GL_CODE: ${PAYBC_GL_CODE}
GL_PROJ_CODE: ${GL_PROJ_CODE}
MSSQL_LOAD_SAMPLE_DATA: ${MSSQL_LOAD_SAMPLE_DATA}
MSSQL_MOTI_HOST: ${MSSQL_MOTI_HOST}
MSSQL_MOTI_DB: ${MSSQL_MOTI_DB}
Expand Down
6 changes: 6 additions & 0 deletions vehicles/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export class AppService {
createCacheMap(paymentMethods, 'paymentMethodTypeCode', 'name'),
);

await addToCache(
this.cacheManager,
CacheKey.PAYMENT_METHOD_TYPE_GL_PROJ_CODE,
createCacheMap(paymentMethods, 'paymentMethodTypeCode', 'glProjCode'),
);

const paymentTypes =
await this.paymentService.findAllPaymentCardTypeEntities();
await addToCache(
Expand Down
1 change: 1 addition & 0 deletions vehicles/src/common/constants/api.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const CRYPTO_ALGORITHM_MD5 = 'md5';
export const CRYPTO_ALGORITHM_SHA256 = 'sha256';
export const TOKEN_EXPIRY_BUFFER = 15;
export const PERMISSIONS_KEY = 'permissions';
export const GL_PROJ_CODE_PLACEHOLDER = 'PROJECT';
1 change: 1 addition & 0 deletions vehicles/src/common/enum/cache-key.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum CacheKey {
PROVINCE = 'PROVINCE',
PERMIT_TYPE = 'PERMIT_TYPE',
PERMIT_TYPE_GL_CODE = 'PERMIT_TYPE_GL_CODE',
PAYMENT_METHOD_TYPE_GL_PROJ_CODE = 'PAYMENT_METHOD_TYPE_GL_PROJ_CODE',
VEHICLE_TYPE = 'VEHICLE_TYPE',
POWER_UNIT_TYPE = 'POWER_UNIT_TYPE',
TRAILER_TYPE = 'TRAILER_TYPE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export class PaymentMethodType {
@AutoMap()
@Column({ name: 'DESCRIPTION', nullable: true, length: 50 })
description: string;

@AutoMap()
@Column({ name: 'GL_PROJ_CODE', nullable: true, length: 7 })
glProjCode: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
PAYBC_PAYMENT_METHOD,
PAYMENT_CURRENCY,
CRYPTO_ALGORITHM_MD5,
GL_PROJ_CODE_PLACEHOLDER,
} from '../../../common/constants/api.constant';
import { convertToHash } from 'src/common/helper/crypto.helper';
import { UpdatePaymentGatewayTransactionDto } from './dto/request/update-payment-gateway-transaction.dto';
Expand Down Expand Up @@ -106,15 +107,24 @@ export class PaymentService {
private queryHash = async (transaction: Transaction) => {
const redirectUrl = process.env.PAYBC_REDIRECT;
const date = new Date().toISOString().split('T')[0];
const glProjCode = await getFromCache(
this.cacheManager,
CacheKey.PAYMENT_METHOD_TYPE_GL_PROJ_CODE,
transaction.paymentMethodTypeCode,
);

const glCodeDetails = await Promise.all(
transaction.permitTransactions.map(
async ({ permit: { permitType }, transactionAmount }) => ({
glCode: await getFromCache(
this.cacheManager,
CacheKey.PERMIT_TYPE_GL_CODE,
permitType,
),
glCode: (
await getFromCache(
this.cacheManager,
CacheKey.PERMIT_TYPE_GL_CODE,
permitType,
)
)
?.replace(GL_PROJ_CODE_PLACEHOLDER, glProjCode)
?.trim(),
amount: transactionAmount,
}),
),
Expand Down

0 comments on commit a2d5b14

Please sign in to comment.