Skip to content

Commit

Permalink
BE: Special Auth Changes (#1529)
Browse files Browse the repository at this point in the history
Co-authored-by: praju-aot <[email protected]>
  • Loading branch information
gchauhan-aot and praju-aot authored Aug 16, 2024
1 parent bef3f6d commit b4be18a
Show file tree
Hide file tree
Showing 28 changed files with 563 additions and 26 deletions.
33 changes: 33 additions & 0 deletions database/mssql/scripts/versions/revert/v_39_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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_SPECIAL_AUTH] DROP CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_CREATE_USERID]
ALTER TABLE [permit].[ORBC_SPECIAL_AUTH] DROP CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_CREATE_TIMESTAMP]
ALTER TABLE [permit].[ORBC_SPECIAL_AUTH] DROP CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_LAST_UPDATE_USERID]
ALTER TABLE [permit].[ORBC_SPECIAL_AUTH] DROP CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_LAST_UPDATE_TIMESTAMP]
ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] DROP CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_CREATE_USERID]
ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] DROP CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_CREATE_TIMESTAMP]
ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] DROP CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_LAST_UPDATE_USERID]
ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] DROP CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_LAST_UPDATE_TIMESTAMP]
ALTER TABLE [permit].[ORBC_SPECIAL_AUTH_HIST] ALTER COLUMN NO_FEE_TYPE VARCHAR(12) NOT NULL
COMMIT
END TRY

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

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Deleting constraint from DB related coulmns form special authorization and no fee tables'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (38, @VersionDescription, getutcdate())
66 changes: 66 additions & 0 deletions database/mssql/scripts/versions/v_39_ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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_SPECIAL_AUTH] ADD CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_CREATE_USERID] DEFAULT(user_name())
FOR [DB_CREATE_USERID]

ALTER TABLE [permit].[ORBC_SPECIAL_AUTH] ADD CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_CREATE_TIMESTAMP] DEFAULT(getutcdate())
FOR [DB_CREATE_TIMESTAMP]

ALTER TABLE [permit].[ORBC_SPECIAL_AUTH] ADD CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_LAST_UPDATE_USERID] DEFAULT(user_name())
FOR [DB_LAST_UPDATE_USERID]

ALTER TABLE [permit].[ORBC_SPECIAL_AUTH] ADD CONSTRAINT [DF_ORBC_SPECIAL_AUTH_DB_LAST_UPDATE_TIMESTAMP] DEFAULT(getutcdate())
FOR [DB_LAST_UPDATE_TIMESTAMP]

ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] ADD CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_CREATE_USERID] DEFAULT(user_name())
FOR [DB_CREATE_USERID]

ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] ADD CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_CREATE_TIMESTAMP] DEFAULT(getutcdate())
FOR [DB_CREATE_TIMESTAMP]

ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] ADD CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_LAST_UPDATE_USERID] DEFAULT(user_name())
FOR [DB_LAST_UPDATE_USERID]

ALTER TABLE [permit].[ORBC_NO_FEE_TYPE] ADD CONSTRAINT [DF_ORBC_NO_FEE_TYPE_DB_LAST_UPDATE_TIMESTAMP] DEFAULT(getutcdate())
FOR [DB_LAST_UPDATE_TIMESTAMP]
GO
ALTER TABLE [permit].[ORBC_SPECIAL_AUTH_HIST] ALTER COLUMN NO_FEE_TYPE VARCHAR(12) NULL
GO

IF @@ERROR <> 0 SET NOEXEC ON
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Default values for ORBC_SPECIAL_AUTH for Db related columns.'

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

14 changes: 14 additions & 0 deletions database/mssql/test/versions/v_39_1_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Test that the role types have been inserted correctly against user auth groups
SET NOCOUNT ON

IF (OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_SPECIAL_AUTH_DB_CREATE_USERID]','D') IS NOT NULL)
AND OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_SPECIAL_AUTH_DB_CREATE_TIMESTAMP]','D') IS NOT NULL
AND (OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_SPECIAL_AUTH_DB_LAST_UPDATE_USERID]','D') IS NOT NULL)
AND (OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_SPECIAL_AUTH_DB_LAST_UPDATE_TIMESTAMP]','D') IS NOT NULL)
AND (OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_NO_FEE_TYPE_DB_CREATE_USERID]','D') IS NOT NULL)
AND OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_NO_FEE_TYPE_DB_CREATE_TIMESTAMP]','D') IS NOT NULL
AND (OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_NO_FEE_TYPE_DB_LAST_UPDATE_USERID]','D') IS NOT NULL)
AND (OBJECT_ID('[$(DB_NAME)].[permit].[DF_ORBC_NO_FEE_TYPE_DB_LAST_UPDATE_TIMESTAMP]','D') IS NOT NULL)
SELECT 1
ELSE
SELECT 0
16 changes: 16 additions & 0 deletions database/mssql/test/versions/v_39_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 39 are run from this shell script.
# TESTS_DIR variable set by the calling test-runner script.

TEST_39_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_39_1_test.sql | xargs)
if [[ $TEST_39_1_RESULT -eq 1 ]]; then
echo "Test 39.1 passed: Db column constaints for special auth and no fee table are added correctly"
else
echo "******** Test 39.1 failed: Db column constaints for special auth and no fee table are not added correctly"
fi
4 changes: 2 additions & 2 deletions vehicles/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { PaymentModule } from './modules/permit-application-payment/payment/paym
import { PermitReceiptDocumentModule } from './modules/permit-application-payment/permit-receipt-document/permit-receipt-document.module';
import { ShoppingCartModule } from './modules/shopping-cart/shopping-cart.module';
import { CreditAccountModule } from './modules/credit-account/credit-account.module';
import { LoaModule } from './modules/loa/loa.module';
import { SpecialAuthModule } from './modules/special-auth/special-auth.module';

const envPath = path.resolve(process.cwd() + '/../');

Expand Down Expand Up @@ -101,7 +101,7 @@ const envPath = path.resolve(process.cwd() + '/../');
PermitModule,
CreditAccountModule,
FeatureFlagsModule,
LoaModule,
SpecialAuthModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
7 changes: 7 additions & 0 deletions vehicles/src/common/enum/no-fee-type.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum NoFeeType {
CA_GOVT = 'CA_GOVT',
MUNICPALITY = 'MUNICPALITY',
SCHOOL = 'SCHOOL',
USA_GOVT = 'USA_GOVT',
ANY_USA_GOVT = 'ANY_USA_GOVT',
}
15 changes: 0 additions & 15 deletions vehicles/src/modules/loa/loa.module.ts

This file was deleted.

17 changes: 17 additions & 0 deletions vehicles/src/modules/special-auth/dto/request/create-lcv.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsBoolean } from 'class-validator';

export class CreateLcvDto {
@ApiProperty({
type: 'boolean',
example: false,
description:
'Indicates whether the company is permitted to operate long combination vehicles',
})
@Transform(({ obj, key }: { obj: Record<string, unknown>; key: string }) => {
return obj[key] === 'true' ? true : obj[key] === 'false' ? false : obj[key];
})
@IsBoolean()
isLcvAllowed: boolean;
}
14 changes: 14 additions & 0 deletions vehicles/src/modules/special-auth/dto/request/create-no-fee.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsOptional } from 'class-validator';
import { NoFeeType } from 'src/common/enum/no-fee-type.enum';

export class CreateNoFeeDto {
@ApiProperty({
enum: NoFeeType,
example: NoFeeType.CA_GOVT,
description: 'Detailed reason of no fee type permit.',
})
@IsOptional()
@IsEnum(NoFeeType)
noFeeType: NoFeeType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { AutoMap } from '@automapper/classes';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsOptional } from 'class-validator';
import { NoFeeType } from 'src/common/enum/no-fee-type.enum';

export class ReadSpecialAuthDto {
@AutoMap()
@ApiProperty({
example: 1,
description: 'Unique Identifier for special authorization.',
})
specialAuthId: number;

@AutoMap()
@ApiProperty({
description: 'Id of the company requesting the LoA.',
example: 74,
required: false,
})
companyId: number;

@AutoMap()
@ApiProperty({
type: 'boolean',
example: false,
description:
'Indicates whether the company is permitted to operate long combination vehicles',
required: false,
})
@Transform(({ obj, key }: { obj: Record<string, unknown>; key: string }) => {
return obj[key] === 'true' ? true : obj[key] === 'false' ? false : obj[key];
})
@IsOptional()
isLcvAllowed: boolean;

@AutoMap()
@ApiProperty({
enum: NoFeeType,
example: NoFeeType.CA_GOVT,
description: 'Detailed reason of no fee type permit.',
required: false,
})
@IsOptional()
noFeeType: NoFeeType;
}
54 changes: 54 additions & 0 deletions vehicles/src/modules/special-auth/entities/special-auth.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
Entity,
Column,
PrimaryGeneratedColumn,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { AutoMap } from '@automapper/classes';
import { Base } from 'src/modules/common/entities/base.entity';
import { Company } from 'src/modules/company-user-management/company/entities/company.entity';
import { IsOptional } from 'class-validator';
import { NoFeeType } from 'src/common/enum/no-fee-type.enum';
import { ApiProperty } from '@nestjs/swagger';

@Entity({ name: 'permit.ORBC_SPECIAL_AUTH' })
export class SpecialAuth extends Base {
@AutoMap()
@PrimaryGeneratedColumn({ type: 'int', name: 'ID' })
specialAuthId: number;

@AutoMap()
@ManyToOne(() => Company, { eager: true, cascade: false })
@JoinColumn({ name: 'COMPANY_ID' })
company: Company;

@AutoMap()
@Column({
type: 'char',
name: 'LCV',
nullable: false,
default: false,
transformer: {
to: (value: boolean): string => (value ? 'Y' : 'N'), // Converts the boolean value to 'Y' or 'N' for storage.
from: (value: string): boolean => value === 'Y', // Converts the stored string back to a boolean.
},
})
isLcvAllowed: boolean;

@AutoMap()
@ApiProperty({
enum: NoFeeType,
example: NoFeeType.CA_GOVT,
description: 'No Fee Type Id',
})
@IsOptional()
@Column({
type: 'simple-enum',
enum: NoFeeType,
length: 12,
name: 'NO_FEE_TYPE',
nullable: true,
})
noFeeType: NoFeeType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ import {
ApiUnprocessableEntityResponse,
} from '@nestjs/swagger';
import { ExceptionDto } from 'src/common/exception/exception.dto';
import { ReadLoaDto } from './dto/response/read-loa.dto';
import { IUserJWT } from 'src/common/interface/user-jwt.interface';
import { LoaService } from './loa.service';
import { Request, Response } from 'express';
import { GetLoaQueryParamsDto } from './dto/request/queryParam/get-loa.query-params.dto';
import { FileInterceptor } from '@nestjs/platform-express';
import { FileDownloadModes } from 'src/common/enum/file-download-modes.enum';
import { setResHeaderCorrelationId } from 'src/common/helper/response-header.helper';
import { JsonReqBodyInterceptor } from '../../common/interceptor/json-req-body.interceptor';
import { CreateLoaFileDto } from './dto/request/create-loa-file.dto';
import { Roles } from 'src/common/decorator/roles.decorator';
import { Role } from 'src/common/enum/roles.enum';
import { IsFeatureFlagEnabled } from 'src/common/decorator/is-feature-flag-enabled.decorator';
import { ReadLoaDto } from './dto/response/read-loa.dto';
import { JsonReqBodyInterceptor } from 'src/common/interceptor/json-req-body.interceptor';
import { CompanyIdPathParamDto } from '../common/dto/request/pathParam/companyId.path-param.dto';
import { UpdateLoaFileDto } from './dto/request/update-loa-file.dto';
import { CreateLoaFileDto } from './dto/request/create-loa-file.dto';
import { GetLoaQueryParamsDto } from './dto/request/queryParam/get-loa.query-params.dto';
import { LoaIdPathParamDto } from './dto/request/pathParam/loa-Id.path-params.dto';
import { UpdateLoaFileDto } from './dto/request/update-loa-file.dto';
import { GetDocumentQueryParamsDto } from '../common/dto/request/queryParam/getDocument.query-params.dto';
import { IsFeatureFlagEnabled } from '../../common/decorator/is-feature-flag-enabled.decorator';
import { Roles } from 'src/common/decorator/roles.decorator';
import { Role } from 'src/common/enum/roles.enum';

@ApiBearerAuth()
@ApiTags('Letter of Authorization (LoA)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ export class LoaService {
LoaDetail,
{
extraArgs: () => ({
companyId,
loaId,
isActive,
documentId,
Expand Down
28 changes: 28 additions & 0 deletions vehicles/src/modules/special-auth/profile/special-auth.profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Mapper, createMap, forMember, mapFrom } from '@automapper/core';
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs';
import { Injectable } from '@nestjs/common';
import { SpecialAuth } from '../entities/special-auth.entity';
import { ReadSpecialAuthDto } from '../dto/response/read-special-auth.dto';

@Injectable()
export class SpecialAuthProfile extends AutomapperProfile {
constructor(@InjectMapper() mapper: Mapper) {
super(mapper);
}

override get profile() {
return (mapper: Mapper) => {
createMap(
mapper,
SpecialAuth,
ReadSpecialAuthDto,
forMember(
(d) => d.companyId,
mapFrom((s) => {
return s.company?.companyId;
}),
),
);
};
}
}
Loading

0 comments on commit b4be18a

Please sign in to comment.