diff --git a/dops/package-lock.json b/dops/package-lock.json index c45ddef21..0566e69b2 100644 --- a/dops/package-lock.json +++ b/dops/package-lock.json @@ -7855,9 +7855,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", diff --git a/tps-migration/package-lock.json b/tps-migration/package-lock.json index fc2523d9d..af8eb5d5c 100644 --- a/tps-migration/package-lock.json +++ b/tps-migration/package-lock.json @@ -7440,9 +7440,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", @@ -19219,9 +19219,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "peer": true }, "for-each": { diff --git a/vehicles/package-lock.json b/vehicles/package-lock.json index 0b3f24989..00484ab99 100644 --- a/vehicles/package-lock.json +++ b/vehicles/package-lock.json @@ -6205,9 +6205,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", diff --git a/vehicles/src/app.module.ts b/vehicles/src/app.module.ts index c73ee9e09..1beaccd84 100644 --- a/vehicles/src/app.module.ts +++ b/vehicles/src/app.module.ts @@ -23,9 +23,7 @@ import { UsersModule } from './modules/company-user-management/users/users.modul import { CompanyModule } from './modules/company-user-management/company/company.module'; import { PendingUsersModule } from './modules/company-user-management/pending-users/pending-users.module'; import { AuthModule } from './modules/auth/auth.module'; -import { PermitModule } from './modules/permit/permit.module'; import { EmailModule } from './modules/email/email.module'; -import { PaymentModule } from './modules/payment/payment.module'; import { FeatureFlagsModule } from './modules/feature-flags/feature-flags.module'; import { HTTPLoggerMiddleware } from './common/middleware/req.res.logger'; import { TypeormCustomLogger } from './common/logger/typeorm-logger.config'; @@ -34,6 +32,9 @@ import { ClsModule } from 'nestjs-cls'; import { Request } from 'express'; import { v4 as uuidv4 } from 'uuid'; import { CompanySuspendModule } from './modules/company-user-management/company-suspend/company-suspend.module'; +import { PermitModule } from './modules/permit-application-payment/permit/permit.module'; +import { ApplicationModule } from './modules/permit-application-payment/application/application.module'; +import { PaymentModule } from './modules/permit-application-payment/payment/payment.module'; const envPath = path.resolve(process.cwd() + '/../'); @@ -91,8 +92,9 @@ const envPath = path.resolve(process.cwd() + '/../'); CommonModule, PendingUsersModule, AuthModule, - PermitModule, PaymentModule, + ApplicationModule, //! Application Module should be imported before PermitModule to avoid URI conflict + PermitModule, FeatureFlagsModule, ], controllers: [AppController], diff --git a/vehicles/src/app.service.ts b/vehicles/src/app.service.ts index 90240f6b3..81a6c885b 100644 --- a/vehicles/src/app.service.ts +++ b/vehicles/src/app.service.ts @@ -4,13 +4,14 @@ import { Cache } from 'cache-manager'; import { PowerUnitTypesService } from './modules/vehicles/power-unit-types/power-unit-types.service'; import { TrailerTypesService } from './modules/vehicles/trailer-types/trailer-types.service'; import { CommonService } from './modules/common/common.service'; -import { PermitService } from './modules/permit/permit.service'; +import { PermitService } from './modules/permit-application-payment/permit/permit.service'; import * as fs from 'fs'; import { CacheKey } from './common/enum/cache-key.enum'; import { addToCache, createCacheMap } from './common/helper/cache.helper'; -import { PaymentService } from './modules/payment/payment.service'; +import { PaymentService } from './modules/permit-application-payment/payment/payment.service'; import { LogAsyncMethodExecution } from './common/decorator/log-async-method-execution.decorator'; import { FeatureFlagsService } from './modules/feature-flags/feature-flags.service'; +import { ApplicationService } from './modules/permit-application-payment/application/application.service'; @Injectable() export class AppService { @@ -25,6 +26,7 @@ export class AppService { private commonService: CommonService, private paymentService: PaymentService, private featureFlagsService: FeatureFlagsService, + private applicationService: ApplicationService, ) {} getHello(): string { @@ -130,6 +132,22 @@ export class AppService { ), ); + const permitApplicationOrigins = + await this.applicationService.findAllPermitApplicationOrigin(); + await addToCache( + this.cacheManager, + CacheKey.PERMIT_APPLICATION_ORIGIN, + createCacheMap(permitApplicationOrigins, 'id', 'code'), + ); + + const permitApprovalSource = + await this.applicationService.findAllPermitApprovalSource(); + await addToCache( + this.cacheManager, + CacheKey.PERMIT_APPROVAL_SOURCE, + createCacheMap(permitApprovalSource, 'id', 'code'), + ); + const endDateTime = new Date(); const processingTime = endDateTime.getTime() - startDateTime.getTime(); this.logger.log( diff --git a/vehicles/src/common/enum/application-status.enum.ts b/vehicles/src/common/enum/application-status.enum.ts index 651308041..83558f8ba 100644 --- a/vehicles/src/common/enum/application-status.enum.ts +++ b/vehicles/src/common/enum/application-status.enum.ts @@ -16,22 +16,23 @@ export enum ApplicationStatus { } /** - * Apllication statuses to be considered for Application In Progress (AIP) from IDIR User POV. + * Application statuses to be considered for Application In Progress (AIP) at time of issuance. */ -export const IDIR_ACTIVE_APPLICATION_STATUS: ReadonlyArray = - [ - ApplicationStatus.IN_PROGRESS, - ApplicationStatus.WAITING_PAYMENT, - ApplicationStatus.CANCELLED, - ApplicationStatus.UNDER_REVIEW, - ]; +export const ACTIVE_APPLICATION_STATUS_FOR_ISSUANCE: ReadonlyArray = + [ApplicationStatus.IN_PROGRESS, ApplicationStatus.WAITING_PAYMENT]; /** - * Apllication statuses to be considered for Application In Progress (AIP) from CV Client POV. + * Application statuses to be considered for Application In Progress (AIP) Tab for Cv Client Users. */ export const CVCLIENT_ACTIVE_APPLICATION_STATUS: ReadonlyArray = + [ApplicationStatus.IN_PROGRESS, ApplicationStatus.WAITING_PAYMENT]; + +/** + * Application statuses to be considered for Application In Progress (AIP) Tab for Staff Users. + */ +export const IDIR_ACTIVE_APPLICATION_STATUS: ReadonlyArray = [ ApplicationStatus.IN_PROGRESS, ApplicationStatus.WAITING_PAYMENT, - ApplicationStatus.UNDER_REVIEW, + //ApplicationStatus.CANCELLED, //! Discovery Pending ]; diff --git a/vehicles/src/common/enum/cache-key.enum.ts b/vehicles/src/common/enum/cache-key.enum.ts index b70e1961e..6df590f1b 100644 --- a/vehicles/src/common/enum/cache-key.enum.ts +++ b/vehicles/src/common/enum/cache-key.enum.ts @@ -15,4 +15,6 @@ export enum CacheKey { PAYMENT_CARD_TYPE = 'PAYMENT_CARD_TYPE', PAYMENT_METHOD_TYPE = 'PAYMENT_METHOD_TYPE', FEATURE_FLAG_TYPE = 'FEATURE_FLAG_TYPE', + PERMIT_APPLICATION_ORIGIN = 'PERMIT_APPLICATION_ORIGIN', + PERMIT_APPROVAL_SOURCE = 'PERMIT_APPROVAL_SOURCE', } diff --git a/vehicles/src/common/helper/application.status.helper.ts b/vehicles/src/common/helper/application.status.helper.ts deleted file mode 100644 index 01e841dbf..000000000 --- a/vehicles/src/common/helper/application.status.helper.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { IUserJWT } from '../interface/user-jwt.interface'; -import { - ApplicationStatus, - CVCLIENT_ACTIVE_APPLICATION_STATUS, - IDIR_ACTIVE_APPLICATION_STATUS, -} from '../enum/application-status.enum'; -import { IDIR_USER_AUTH_GROUP_LIST } from '../enum/user-auth-group.enum'; -import { doesUserHaveAuthGroup } from './auth.helper'; - -export const getActiveApplicationStatus = (currentUser: IUserJWT) => { - const applicationStatus: Readonly = - doesUserHaveAuthGroup( - currentUser.orbcUserAuthGroup, - IDIR_USER_AUTH_GROUP_LIST, - ) - ? IDIR_ACTIVE_APPLICATION_STATUS - : CVCLIENT_ACTIVE_APPLICATION_STATUS; - - return applicationStatus; -}; diff --git a/vehicles/src/common/helper/database.helper.ts b/vehicles/src/common/helper/database.helper.ts index aec9bbaca..d86513083 100644 --- a/vehicles/src/common/helper/database.helper.ts +++ b/vehicles/src/common/helper/database.helper.ts @@ -5,10 +5,16 @@ export const callDatabaseSequence = async ( dataSource: DataSource, ): Promise => { const queryRunner = dataSource.createQueryRunner(); - const query = - 'Select NEXT VALUE FOR ' + databaseSequenceName + ' as Next_Value;'; - const sequence = (await queryRunner.query(query)) as [{ Next_Value: string }]; - return sequence[0].Next_Value; + let sequence: string; + try { + const query = + 'Select NEXT VALUE FOR ' + databaseSequenceName + ' as Next_Value;'; + const result = (await queryRunner.query(query)) as [{ Next_Value: string }]; + sequence = result?.at(0).Next_Value; + } finally { + await queryRunner.release(); + } + return sequence; }; /** diff --git a/vehicles/src/modules/permit/helpers/formatTemplateData.helper.ts b/vehicles/src/common/helper/format-template-data.helper.ts similarity index 83% rename from vehicles/src/modules/permit/helpers/formatTemplateData.helper.ts rename to vehicles/src/common/helper/format-template-data.helper.ts index e1fdca3ae..e612d0464 100644 --- a/vehicles/src/modules/permit/helpers/formatTemplateData.helper.ts +++ b/vehicles/src/common/helper/format-template-data.helper.ts @@ -1,17 +1,15 @@ -import { Permit } from 'src/modules/permit/entities/permit.entity'; +import * as constants from '../constants/api.constant'; +import { convertUtcToPt, dateFormat } from '../helper/date-time.helper'; +import { ApplicationStatus } from '../enum/application-status.enum'; +import { PermitIssuedBy } from '../enum/permit-issued-by.enum'; +import { Company } from '../../modules/company-user-management/company/entities/company.entity'; +import { Permit } from '../../modules/permit-application-payment/permit/entities/permit.entity'; import { PermitData, PermitTemplateData, -} from '../../../common/interface/permit.template.interface'; -import { FullNames } from '../interface/fullNames.interface'; -import { - convertUtcToPt, - dateFormat, -} from '../../../common/helper/date-time.helper'; -import { ApplicationStatus } from '../../../common/enum/application-status.enum'; -import { PermitIssuedBy } from '../../../common/enum/permit-issued-by.enum'; -import * as constants from '../../../common/constants/api.constant'; -import { Company } from '../../company-user-management/company/entities/company.entity'; +} from '../interface/permit.template.interface'; +import { FullNamesForDgen } from '../interface/full-names-for-dgen.interface'; + /** * Formats the permit data so that it can be used in the templated word documents * @param permit @@ -21,7 +19,7 @@ import { Company } from '../../company-user-management/company/entities/company. */ export const formatTemplateData = ( permit: Permit, - fullNames: FullNames, + fullNames: FullNamesForDgen, companyInfo: Company, revisitionHisotry: Permit[], ) => { diff --git a/vehicles/src/common/helper/permit-application.helper.ts b/vehicles/src/common/helper/permit-application.helper.ts new file mode 100644 index 000000000..eb7fdea81 --- /dev/null +++ b/vehicles/src/common/helper/permit-application.helper.ts @@ -0,0 +1,211 @@ +import { Permit } from '../../modules/permit-application-payment/permit/entities/permit.entity'; +import { PermitData } from '../interface/permit.template.interface'; +import { getFromCache } from './cache.helper'; +import { FullNamesForDgen } from '../interface/full-names-for-dgen.interface'; +import { Cache } from 'cache-manager'; +import { CacheKey } from '../enum/cache-key.enum'; +import { DataSource } from 'typeorm'; +import { InternalServerErrorException } from '@nestjs/common'; +import { callDatabaseSequence } from './database.helper'; +import { PermitApplicationOrigin as PermitApplicationOriginEnum } from '../enum/permit-application-origin.enum'; +import { PermitApprovalSource as PermitApprovalSourceEnum } from '../enum/permit-approval-source.enum'; +import { randomInt } from 'crypto'; +import { + ApplicationStatus, + IDIR_ACTIVE_APPLICATION_STATUS, + CVCLIENT_ACTIVE_APPLICATION_STATUS, +} from '../enum/application-status.enum'; +import { IDIR_USER_AUTH_GROUP_LIST } from '../enum/user-auth-group.enum'; +import { IUserJWT } from '../interface/user-jwt.interface'; +import { doesUserHaveAuthGroup } from './auth.helper'; + +/** + * Fetches and resolves various types of names associated with a permit using cache. + * It converts coded names (e.g., type codes, country codes) into their full descriptive names + * for both vehicle and mailing address. Also resolves permit name based on its type. + * - Vehicle type and subtype names are resolved based on their codes. + * - Country and province/state names for both the vehicle registration and mailing address. + * - Permit type name is also resolved to its full descriptive name. + * Example of conversion: 'TROS' to 'Oversize: Term' + * @param cacheManager An instance of Cache used for fetching data. + * @param permit The permit object containing information about the permit. + * @returns a Promise that resolves to an object containing the full descriptive names. + */ +export const fetchPermitDataDescriptionValuesFromCache = async ( + cacheManager: Cache, + permit: Permit, +): Promise => { + const permitData = JSON.parse(permit.permitData.permitData) as PermitData; + + const vehicleTypeName = await getFromCache( + cacheManager, + CacheKey.VEHICLE_TYPE, + permitData.vehicleDetails.vehicleType, + ); + + const vehicleSubTypeName = await getFromCache( + cacheManager, + vehicleTypeName === 'Trailer' + ? CacheKey.TRAILER_TYPE + : CacheKey.POWER_UNIT_TYPE, + permitData.vehicleDetails.vehicleSubType, + ); + + const mailingCountryName = await getFromCache( + cacheManager, + CacheKey.COUNTRY, + permitData.vehicleDetails.countryCode, + ); + const mailingProvinceName = permitData.vehicleDetails.provinceCode + ? await getFromCache( + cacheManager, + CacheKey.PROVINCE, + permitData.vehicleDetails.provinceCode, + ) + : null; + + const vehicleCountryName = await getFromCache( + cacheManager, + CacheKey.COUNTRY, + permitData.mailingAddress.countryCode, + ); + const vehicleProvinceName = permitData.mailingAddress.provinceCode + ? await getFromCache( + cacheManager, + CacheKey.PROVINCE, + permitData.mailingAddress.provinceCode, + ) + : null; + + const permitName = await getFromCache( + cacheManager, + CacheKey.PERMIT_TYPE, + permit.permitType, + ); + + return { + vehicleTypeName, + vehicleSubTypeName, + mailingCountryName, + mailingProvinceName, + vehicleCountryName, + vehicleProvinceName, + permitName, + }; +}; + +/** + * Generate Application Number + * @param applicationSource to get the source code + * @param permitId if permit id is present then it is a permit amendment + * and application number will be generated from exisitng permit number. + * Generates an application number for a new or existing permit application. For an existing permit (amendment), + * it generates the application number based on the existing permit's number with incremented revision. + * For a new application, it generates a new sequence and random number. + * @param dataSource DataSource connection to interact with the database. + * @param cacheManager Cache manager to retrieve cached data. + * @param permitApplicationOrigin Origin of the permit application (e.g., online, offline). + * @param existingPermit Optional. The existing permit, if this is an amendment. + * @returns A promise that resolves to the generated application number string. + */ +export const generateApplicationNumber = async ( + dataSource: DataSource, + cacheManager: Cache, + permitApplicationOrigin: PermitApplicationOriginEnum, + existingPermit?: Permit, +): Promise => { + let sequence: string; + let source; + let randomNumber; + let revision = '-A00'; + if (existingPermit) { + //Format revision id + revision = `-A${String(existingPermit.revision + 1).padStart(2, '0')}`; + if (existingPermit.permitNumber) { + sequence = existingPermit.permitNumber.substring(3, 11); + randomNumber = existingPermit.permitNumber.substring(12, 15); + } else { + throw new InternalServerErrorException('Permit number does not exist'); + } + // Fetching existing permit source from cache + source = await getFromCache( + cacheManager, + CacheKey.PERMIT_APPLICATION_ORIGIN, + existingPermit.permitApplicationOrigin, + ); + } else { + // Fetching sequence number for new permit application + sequence = await callDatabaseSequence( + 'permit.ORBC_PERMIT_NUMBER_SEQ', + dataSource, + ); + + // Generating random number for new permit + randomNumber = randomInt(100, 1000); + + // Fetching permit application origin source from cache for new permit + source = await getFromCache( + cacheManager, + CacheKey.PERMIT_APPLICATION_ORIGIN, + permitApplicationOrigin, + ); + } + // Compiling application number from source, sequence, random number, and revision + const applicationNumber = `A${source}-${sequence.padStart(8, '0')}-${randomNumber}${revision}`; + + return applicationNumber; +}; + +/** + * Generate permit number for a permit application. This function creates a formatted permit number + * by combining an approval source ID with a sequence derived from either the permit's number + * (Amending existing permits) or its application number (for new applications), along with an increment + * or random set of characters to ensure uniqueness. The approval source is determined by caching or + * set to a default value if not found. + * @param cacheManager The cache manager interface for retrieving approval source. + * @param permit The permit object, which must contain either a permit number (for amendments) + * or an application number (for new applications). + * @returns A promise that resolves to the newly generated permit number as a string. + */ +export const generatePermitNumber = async ( + cacheManager: Cache, + permit: Permit, +): Promise => { + // Retrieve the approval source from cache. AUTO is hardcoded for release 1 + const approvalSource = await getFromCache( + cacheManager, + CacheKey.PERMIT_APPROVAL_SOURCE, + PermitApprovalSourceEnum.AUTO, //TODO : Hardcoding for release 1 + ); + const approvalSourceId = approvalSource ? +approvalSource : 9; // Assuming 9 is a default value + + let sequence: string; + let randomNumber: string; + let revision: string = ''; // Initialize as empty string + + // Use permitNumber for amendments and applicationNumber for new applications + if (permit.permitNumber) { + sequence = permit.permitNumber.substring(3, 11); + randomNumber = permit.permitNumber.substring(12, 15); + revision = `-A${String(permit.revision + 1).padStart(2, '0')}`; + } else { + sequence = permit.applicationNumber.substring(3, 11); + randomNumber = permit.applicationNumber.substring(12, 15); + } + + // Format and return the permit number + const permitNumber = `P${approvalSourceId}-${sequence}-${randomNumber}${revision}`; + return permitNumber; +}; + +export const getActiveApplicationStatus = (currentUser: IUserJWT) => { + const applicationStatus: Readonly = + doesUserHaveAuthGroup( + currentUser.orbcUserAuthGroup, + IDIR_USER_AUTH_GROUP_LIST, + ) + ? IDIR_ACTIVE_APPLICATION_STATUS + : CVCLIENT_ACTIVE_APPLICATION_STATUS; + + return applicationStatus; +}; diff --git a/vehicles/src/modules/permit/interface/fullNames.interface.ts b/vehicles/src/common/interface/full-names-for-dgen.interface.ts similarity index 84% rename from vehicles/src/modules/permit/interface/fullNames.interface.ts rename to vehicles/src/common/interface/full-names-for-dgen.interface.ts index 0034a9fb3..0659e6a9f 100644 --- a/vehicles/src/modules/permit/interface/fullNames.interface.ts +++ b/vehicles/src/common/interface/full-names-for-dgen.interface.ts @@ -1,4 +1,4 @@ -export interface FullNames { +export interface FullNamesForDgen { vehicleTypeName: string; vehicleSubTypeName: string; mailingCountryName: string; diff --git a/vehicles/src/modules/company-user-management/company/company.service.ts b/vehicles/src/modules/company-user-management/company/company.service.ts index 362f5bd58..46fe2a119 100644 --- a/vehicles/src/modules/company-user-management/company/company.service.ts +++ b/vehicles/src/modules/company-user-management/company/company.service.ts @@ -51,7 +51,7 @@ import { v4 as uuidv4 } from 'uuid'; import { UserStatus } from 'src/common/enum/user-status.enum'; import { VerifyClientDto } from './dto/request/verify-client.dto'; import { ReadVerifyClientDto } from './dto/response/read-verify-client.dto'; -import { Permit } from '../../permit/entities/permit.entity'; +import { Permit } from '../../permit-application-payment/permit/entities/permit.entity'; @Injectable() export class CompanyService { diff --git a/vehicles/src/modules/permit/application.controller.ts b/vehicles/src/modules/permit-application-payment/application/application.controller.ts similarity index 97% rename from vehicles/src/modules/permit/application.controller.ts rename to vehicles/src/modules/permit-application-payment/application/application.controller.ts index 1a1e6b1d7..3d7aa8c59 100644 --- a/vehicles/src/modules/permit/application.controller.ts +++ b/vehicles/src/modules/permit-application-payment/application/application.controller.ts @@ -27,7 +27,7 @@ import { CreateApplicationDto } from './dto/request/create-application.dto'; import { ReadApplicationDto } from './dto/response/read-application.dto'; import { ApplicationService } from './application.service'; import { Request } from 'express'; -import { ExceptionDto } from '../../common/exception/exception.dto'; +import { ExceptionDto } from '../../../common/exception/exception.dto'; import { UpdateApplicationDto } from './dto/request/update-application.dto'; import { DataNotFoundException } from 'src/common/exception/data-not-found.exception'; import { ResultDto } from './dto/response/result.dto'; @@ -42,10 +42,10 @@ import { import { ApiPaginatedResponse } from 'src/common/decorator/api-paginate-response'; import { GetApplicationQueryParamsDto } from './dto/request/queryParam/getApplication.query-params.dto'; import { DeleteApplicationDto } from './dto/request/delete-application.dto'; -import { DeleteDto } from '../common/dto/response/delete.dto'; -import { PermitApplicationOrigin } from '../../common/enum/permit-application-origin.enum'; +import { DeleteDto } from '../../common/dto/response/delete.dto'; +import { PermitApplicationOrigin } from '../../../common/enum/permit-application-origin.enum'; import { ReadApplicationMetadataDto } from './dto/response/read-application-metadata.dto'; -import { doesUserHaveAuthGroup } from '../../common/helper/auth.helper'; +import { doesUserHaveAuthGroup } from '../../../common/helper/auth.helper'; @ApiBearerAuth() @ApiTags('Permit Application') diff --git a/vehicles/src/modules/permit-application-payment/application/application.module.ts b/vehicles/src/modules/permit-application-payment/application/application.module.ts new file mode 100644 index 000000000..6e2c33388 --- /dev/null +++ b/vehicles/src/modules/permit-application-payment/application/application.module.ts @@ -0,0 +1,28 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { ApplicationController } from './application.controller'; +import { ApplicationService } from './application.service'; +import { ApplicationProfile } from './profile/application.profile'; +import { PermitApplicationOrigin } from './entities/permit-application-origin.entity'; +import { PermitApprovalSource } from './entities/permit-approval-source.entity'; +import { PaymentModule } from '../payment/payment.module'; +import { PermitData } from '../permit/entities/permit-data.entity'; +import { PermitType } from '../permit/entities/permit-type.entity'; +import { Permit } from '../permit/entities/permit.entity'; + +@Module({ + imports: [ + TypeOrmModule.forFeature([ + Permit, + PermitData, + PermitType, + PermitApplicationOrigin, + PermitApprovalSource, + ]), + PaymentModule, + ], + controllers: [ApplicationController], + providers: [ApplicationService, ApplicationProfile], + exports: [ApplicationService], +}) +export class ApplicationModule {} diff --git a/vehicles/src/modules/permit/application.service.ts b/vehicles/src/modules/permit-application-payment/application/application.service.ts similarity index 74% rename from vehicles/src/modules/permit/application.service.ts rename to vehicles/src/modules/permit-application-payment/application/application.service.ts index 4ccdb52e4..110089dd4 100644 --- a/vehicles/src/modules/permit/application.service.ts +++ b/vehicles/src/modules/permit-application-payment/application/application.service.ts @@ -8,67 +8,62 @@ import { InternalServerErrorException, Logger, NotFoundException, - forwardRef, } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { ApplicationStatus } from 'src/common/enum/application-status.enum'; import { DataSource, Repository, SelectQueryBuilder } from 'typeorm'; import { CreateApplicationDto } from './dto/request/create-application.dto'; import { ReadApplicationDto } from './dto/response/read-application.dto'; -import { Permit } from './entities/permit.entity'; +import { Permit } from '../permit/entities/permit.entity'; import { UpdateApplicationDto } from './dto/request/update-application.dto'; import { ResultDto } from './dto/response/result.dto'; import { PermitApplicationOrigin } from './entities/permit-application-origin.entity'; import { PermitApprovalSource } from './entities/permit-approval-source.entity'; -import { IDP } from 'src/common/enum/idp.enum'; -import { PermitApplicationOrigin as PermitApplicationOriginEnum } from 'src/common/enum/permit-application-origin.enum'; -import { IUserJWT } from 'src/common/interface/user-jwt.interface'; -import { PermitApprovalSource as PermitApprovalSourceEnum } from 'src/common/enum/permit-approval-source.enum'; -import { - callDatabaseSequence, - paginate, - sortQuery, -} from 'src/common/helper/database.helper'; -import { randomInt } from 'crypto'; +import { PermitApplicationOrigin as PermitApplicationOriginEnum } from '../../../common/enum/permit-application-origin.enum'; +import { PermitApprovalSource as PermitApprovalSourceEnum } from '../../../common/enum/permit-approval-source.enum'; +import { paginate, sortQuery } from '../../../common/helper/database.helper'; import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { Cache } from 'cache-manager'; -import { FullNames } from './interface/fullNames.interface'; -import { PermitData } from 'src/common/interface/permit.template.interface'; -import { getFromCache } from 'src/common/helper/cache.helper'; -import { CompanyService } from '../company-user-management/company/company.service'; -import { formatTemplateData } from './helpers/formatTemplateData.helper'; -import { EmailService } from '../email/email.service'; -import { PermitService } from './permit.service'; -import { EmailTemplate } from '../../common/enum/email-template.enum'; -import { IssuePermitEmailData } from '../../common/interface/issue-permit-email-data.interface'; -import { AttachementEmailData } from '../../common/interface/attachment-email-data.interface'; -import { CacheKey } from '../../common/enum/cache-key.enum'; -import { DopsService } from '../common/dops.service'; -import { DopsGeneratedDocument } from '../../common/interface/dops-generated-document.interface'; -import { TemplateName } from '../../common/enum/template-name.enum'; -import { IFile } from '../../common/interface/file.interface'; -import { ReadTransactionDto } from '../payment/dto/response/read-transaction.dto'; -import { Transaction } from '../payment/entities/transaction.entity'; +import { EmailService } from '../../email/email.service'; +import { EmailTemplate } from '../../../common/enum/email-template.enum'; +import { IssuePermitEmailData } from '../../../common/interface/issue-permit-email-data.interface'; +import { AttachementEmailData } from '../../../common/interface/attachment-email-data.interface'; +import { DopsService } from '../../common/dops.service'; +import { DopsGeneratedDocument } from '../../../common/interface/dops-generated-document.interface'; +import { TemplateName } from '../../../common/enum/template-name.enum'; +import { IFile } from '../../../common/interface/file.interface'; import { Receipt } from '../payment/entities/receipt.entity'; -import { convertUtcToPt } from '../../common/helper/date-time.helper'; -import { Directory } from 'src/common/enum/directory.enum'; -import { PermitIssuedBy } from '../../common/enum/permit-issued-by.enum'; +import { convertUtcToPt } from '../../../common/helper/date-time.helper'; +import { Directory } from '../../../common/enum/directory.enum'; +import { PermitIssuedBy } from '../../../common/enum/permit-issued-by.enum'; import { formatAmount, getPaymentCodeFromCache, -} from '../../common/helper/payment.helper'; -import * as constants from '../../common/constants/api.constant'; -import { LogAsyncMethodExecution } from '../../common/decorator/log-async-method-execution.decorator'; -import { PageMetaDto } from 'src/common/dto/paginate/page-meta'; -import { PaginationDto } from 'src/common/dto/paginate/pagination'; -import { getActiveApplicationStatus } from 'src/common/helper/application.status.helper'; +} from '../../../common/helper/payment.helper'; +import * as constants from '../../../common/constants/api.constant'; +import { LogAsyncMethodExecution } from '../../../common/decorator/log-async-method-execution.decorator'; +import { PageMetaDto } from '../../../common/dto/paginate/page-meta'; +import { PaginationDto } from '../../../common/dto/paginate/pagination'; + import { ClientUserAuthGroup, IDIR_USER_AUTH_GROUP_LIST, -} from 'src/common/enum/user-auth-group.enum'; -import { DeleteDto } from '../common/dto/response/delete.dto'; +} from '../../../common/enum/user-auth-group.enum'; +import { DeleteDto } from '../../common/dto/response/delete.dto'; import { ReadApplicationMetadataDto } from './dto/response/read-application-metadata.dto'; -import { doesUserHaveAuthGroup } from '../../common/helper/auth.helper'; +import { doesUserHaveAuthGroup } from '../../../common/helper/auth.helper'; +import { formatTemplateData } from '../../../common/helper/format-template-data.helper'; +import { + ACTIVE_APPLICATION_STATUS_FOR_ISSUANCE, + ApplicationStatus, +} from '../../../common/enum/application-status.enum'; +import { IDP } from '../../../common/enum/idp.enum'; +import { IUserJWT } from '../../../common/interface/user-jwt.interface'; +import { + fetchPermitDataDescriptionValuesFromCache, + generateApplicationNumber, + generatePermitNumber, + getActiveApplicationStatus, +} from '../../../common/helper/permit-application.helper'; @Injectable() export class ApplicationService { @@ -85,14 +80,7 @@ export class ApplicationService { private permitApprovalSourceRepository: Repository, @Inject(CACHE_MANAGER) private readonly cacheManager: Cache, - private companyService: CompanyService, private readonly emailService: EmailService, - @Inject(forwardRef(() => PermitService)) - private readonly permitService: PermitService, - @InjectRepository(Transaction) - private transactionRepository: Repository, - @InjectRepository(Receipt) - private receiptRepository: Repository, ) {} /** @@ -107,13 +95,14 @@ export class ApplicationService { currentUser: IUserJWT, ): Promise { const id = createApplicationDto.permitId; + let fetchExistingApplication: Permit; //If permit id exists assign it to null to create new application. //Existing permit id also implies that this new application is an amendment. if (id) { - const permit = await this.findOne(id); + fetchExistingApplication = await this.findOne(id); //to check if there is already an appliation in database const count = await this.checkApplicationInProgress( - permit.originalPermitId, + fetchExistingApplication.originalPermitId, ); // If an application already exists throw error. //As there should not be multiple amendment applications for one permit @@ -121,33 +110,23 @@ export class ApplicationService { throw new InternalServerErrorException( 'An application already exists for this permit.', ); - createApplicationDto.revision = permit.revision + 1; + createApplicationDto.revision = fetchExistingApplication.revision + 1; createApplicationDto.previousRevision = id; createApplicationDto.permitId = null; - createApplicationDto.originalPermitId = permit.originalPermitId; + createApplicationDto.originalPermitId = + fetchExistingApplication.originalPermitId; } - createApplicationDto.permitStatus = ApplicationStatus.IN_PROGRESS; - //Assign Permit Application Origin - if (currentUser.identity_provider == IDP.IDIR) - createApplicationDto.permitApplicationOrigin = - PermitApplicationOriginEnum.PPC; - else - createApplicationDto.permitApplicationOrigin = - PermitApplicationOriginEnum.ONLINE; - - //Generate appliction number for the application to be created in database. - const applicationNumber = await this.generateApplicationNumber( - currentUser.identity_provider, - id, - ); - createApplicationDto.applicationNumber = applicationNumber; const permitApplication = this.classMapper.map( createApplicationDto, CreateApplicationDto, Permit, { extraArgs: () => ({ + permitApplicationOrigin: + currentUser.identity_provider === IDP.IDIR + ? PermitApplicationOriginEnum.PPC + : PermitApplicationOriginEnum.ONLINE, userName: currentUser.userName, userGUID: currentUser.userGUID, timestamp: new Date(), @@ -156,6 +135,17 @@ export class ApplicationService { }, ); + //Generate appliction number for the application to be created in database. + const applicationNumber = await generateApplicationNumber( + this.dataSource, + this.cacheManager, + permitApplication.permitApplicationOrigin, + fetchExistingApplication, + ); + + permitApplication.applicationNumber = applicationNumber; + permitApplication.permitStatus = ApplicationStatus.IN_PROGRESS; + const savedPermitEntity = await this.permitRepository.save(permitApplication); // In case of new application assign original permit ID @@ -263,7 +253,6 @@ export class ApplicationService { findAllApplicationsOptions.companyId, findAllApplicationsOptions.userGUID, ); - // total number of items const totalItems = await applicationsQB.getCount(); @@ -455,6 +444,9 @@ export class ApplicationService { if (!fetchedApplication) { throw new NotFoundException('Application not found for issuance!'); } + if (fetchedApplication.permitNumber) { + throw new NotFoundException('Application has already been issued!'); + } if (fetchedApplication.documentId) { throw new HttpException('Document already exists', 409); } else if ( @@ -465,30 +457,25 @@ export class ApplicationService { ); } - const isApplicationIdEqualToOriginalPermitId = - applicationId === fetchedApplication.originalPermitId; - - const newApplicationId = isApplicationIdEqualToOriginalPermitId - ? applicationId - : null; - const prevApplicationId = isApplicationIdEqualToOriginalPermitId - ? null - : fetchedApplication.previousRevision.toString(); - - const permitNumber = await this.generatePermitNumber( - newApplicationId, - prevApplicationId, + const permitNumber = await generatePermitNumber( + this.cacheManager, + applicationId !== fetchedApplication.originalPermitId + ? await this.findOne(fetchedApplication.previousRevision.toString()) + : fetchedApplication, ); //Generate receipt number for the permit to be created in database. const receiptNumber = - fetchedApplication.permitTransactions[0].transaction.receipt + fetchedApplication.permitTransactions?.at(0).transaction.receipt .receiptNumber; fetchedApplication.permitNumber = permitNumber; fetchedApplication.permitStatus = ApplicationStatus.ISSUED; const companyInfo = fetchedApplication.company; - const fullNames = await this.getFullNamesFromCache(fetchedApplication); + const fullNames = await fetchPermitDataDescriptionValuesFromCache( + this.cacheManager, + fetchedApplication, + ); const revisionHistory = await this.permitRepository.find({ where: [{ originalPermitId: fetchedApplication.originalPermitId }], @@ -715,192 +702,24 @@ export class ApplicationService { ); } - /** - * Converts code names to full names by calling the cache manager. - * Example: 'TROS' to 'Oversize: Term' - * @param permit - * @returns a json object of the full names - */ - @LogAsyncMethodExecution() - async getFullNamesFromCache(permit: Permit): Promise { - const permitData = JSON.parse(permit.permitData.permitData) as PermitData; - - const vehicleTypeName = await getFromCache( - this.cacheManager, - CacheKey.VEHICLE_TYPE, - permitData.vehicleDetails.vehicleType, - ); - - const vehicleSubTypeName = await getFromCache( - this.cacheManager, - vehicleTypeName === 'Trailer' - ? CacheKey.TRAILER_TYPE - : CacheKey.POWER_UNIT_TYPE, - permitData.vehicleDetails.vehicleSubType, - ); - - const mailingCountryName = await getFromCache( - this.cacheManager, - CacheKey.COUNTRY, - permitData.vehicleDetails.countryCode, - ); - const mailingProvinceName = permitData.vehicleDetails.provinceCode - ? await getFromCache( - this.cacheManager, - CacheKey.PROVINCE, - permitData.vehicleDetails.provinceCode, - ) - : null; - - const vehicleCountryName = await getFromCache( - this.cacheManager, - CacheKey.COUNTRY, - permitData.mailingAddress.countryCode, - ); - const vehicleProvinceName = permitData.mailingAddress.provinceCode - ? await getFromCache( - this.cacheManager, - CacheKey.PROVINCE, - permitData.mailingAddress.provinceCode, - ) - : null; - - const permitName = await getFromCache( - this.cacheManager, - CacheKey.PERMIT_TYPE, - permit.permitType, - ); - - return { - vehicleTypeName, - vehicleSubTypeName, - mailingCountryName, - mailingProvinceName, - vehicleCountryName, - vehicleProvinceName, - permitName, - }; - } - - /** - * Generate Application Number - * @param applicationSource to get the source code - * @param permitId if permit id is present then it is a permit amendment - * and application number will be generated from exisitng permit number. - */ - @LogAsyncMethodExecution() - async generateApplicationNumber( - permitApplicationOrigin: IDP, - permitId: string, - ): Promise { - let seq: string; - let source; - let rnd; - let rev = '-A00'; - let permit: Permit; - if (permitId) { - //Amendment to existing permit.//Get revision Id from database. - permit = await this.findOne(permitId); - //Format revision id - rev = '-A' + String(permit.revision + 1).padStart(2, '0'); - if (permit.permitNumber) { - seq = permit.permitNumber.substring(3, 11); - rnd = permit.permitNumber.substring(12, 15); - } else { - throw new InternalServerErrorException('Permit number does not exist'); - } - source = await this.getPermitApplicationOrigin( - permit.permitApplicationOrigin, - ); - } else { - //New permit application. - seq = await callDatabaseSequence( - 'permit.ORBC_PERMIT_NUMBER_SEQ', - this.dataSource, - ); - source = await this.getPermitApplicationOrigin( - permitApplicationOrigin == IDP.IDIR - ? PermitApplicationOriginEnum.PPC - : PermitApplicationOriginEnum.ONLINE, - ); - rnd = randomInt(100, 1000); - } - - const applicationNumber = String( - 'A' + - String(source) + - '-' + - String(seq.padStart(8, '0')) + - '-' + - String(rnd) + - String(rev), - ); - - return applicationNumber; - } - /** * Get Application Origin Code from database lookup table ORBC_VT_PERMIT_APPLICATION_ORIGIN - * @param permitApplicationOrigin - * + * Retrieves all application origin records from the database. + * @returns A promise that resolves with an array of PermitApplicationOrigin objects. */ - private async getPermitApplicationOrigin( - permitApplicationOrigin: PermitApplicationOriginEnum, - ): Promise { - const applicationOrigin = - await this.permitApplicationOriginRepository.findOne({ - where: [{ id: permitApplicationOrigin }], - }); - - return String(applicationOrigin.code); + @LogAsyncMethodExecution() + async findAllPermitApplicationOrigin(): Promise { + return await this.permitApplicationOriginRepository.find(); } /** - * Generate permit number for a permit application. only one (i.e. permitId or oldPermitId) should be present at a time. - * @param permitId - * @param oldPermitId - * @returns permitNumber + * Get Approval Source Code from database lookup table ORBC_VT_PERMIT_APPROVAL_SOURCE + * Retrieves all permit approval source records from the database. + * @returns A promise that resolves with an array of PermitApprovalSource objects. */ @LogAsyncMethodExecution() - async generatePermitNumber( - permitId: string, - oldPermitId: string, - ): Promise { - const id = !permitId ? oldPermitId : permitId; - const permit = await this.findOne(id); - let seq: string; - const approvalSource = await this.permitApprovalSourceRepository.findOne({ - where: [{ id: PermitApprovalSourceEnum.AUTO }], //TODO : Hardcoding for release 1 - }); - let approvalSourceId: number; - if (approvalSource.code) approvalSourceId = approvalSource.code; - else approvalSourceId = 9; - let rnd: number | string; - if (permitId) { - seq = permit.applicationNumber.substring(3, 11); - rnd = permit.applicationNumber.substring(12, 15); - } else { - seq = permit.permitNumber.substring(3, 15); - rnd = 'A' + String(permit.revision + 1).padStart(2, '0'); - } - const permitNumber = - 'P' + String(approvalSourceId) + '-' + String(seq) + '-' + String(rnd); - return permitNumber; - } - - @LogAsyncMethodExecution() - async findOneTransactionByOrderNumber( - transactionOrderNumber: string, - ): Promise { - return this.classMapper.mapAsync( - await this.transactionRepository.findOne({ - where: { - transactionOrderNumber: transactionOrderNumber, - }, - }), - Transaction, - ReadTransactionDto, - ); + async findAllPermitApprovalSource(): Promise { + return await this.permitApprovalSourceRepository.find(); } @LogAsyncMethodExecution() @@ -955,16 +774,7 @@ export class ApplicationService { originalPermitId: originalPermitId, }) .andWhere('permit.permitStatus IN (:...applicationStatus)', { - applicationStatus: Object.values(ApplicationStatus).filter( - (x) => - x != ApplicationStatus.DELETED && - x != ApplicationStatus.CANCELLED && - x != ApplicationStatus.REJECTED && - x != ApplicationStatus.ISSUED && - x != ApplicationStatus.REVOKED && - x != ApplicationStatus.VOIDED && - x != ApplicationStatus.SUPERSEDED, - ), + applicationStatus: ACTIVE_APPLICATION_STATUS_FOR_ISSUANCE, }) .getCount(); return count; diff --git a/vehicles/src/modules/permit/dto/request/create-application.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/request/create-application.dto.ts similarity index 100% rename from vehicles/src/modules/permit/dto/request/create-application.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/request/create-application.dto.ts diff --git a/vehicles/src/modules/permit/dto/request/delete-application.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/request/delete-application.dto.ts similarity index 100% rename from vehicles/src/modules/permit/dto/request/delete-application.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/request/delete-application.dto.ts diff --git a/vehicles/src/modules/permit/dto/request/issue-permit.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/request/issue-permit.dto.ts similarity index 89% rename from vehicles/src/modules/permit/dto/request/issue-permit.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/request/issue-permit.dto.ts index 7fcae6f54..3f53e5b1f 100644 --- a/vehicles/src/modules/permit/dto/request/issue-permit.dto.ts +++ b/vehicles/src/modules/permit-application-payment/application/dto/request/issue-permit.dto.ts @@ -6,7 +6,7 @@ import { ArrayMinSize, IsOptional, } from 'class-validator'; -import { IDIR_USER_AUTH_GROUP_LIST } from '../../../../common/enum/user-auth-group.enum'; +import { IDIR_USER_AUTH_GROUP_LIST } from '../../../../../common/enum/user-auth-group.enum'; export class IssuePermitDto { @AutoMap() diff --git a/vehicles/src/modules/permit/dto/request/queryParam/getApplication.query-params.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/request/queryParam/getApplication.query-params.dto.ts similarity index 80% rename from vehicles/src/modules/permit/dto/request/queryParam/getApplication.query-params.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/request/queryParam/getApplication.query-params.dto.ts index 1e7efb60c..6029eccec 100644 --- a/vehicles/src/modules/permit/dto/request/queryParam/getApplication.query-params.dto.ts +++ b/vehicles/src/modules/permit-application-payment/application/dto/request/queryParam/getApplication.query-params.dto.ts @@ -6,11 +6,11 @@ import { IsNumber, Validate, } from 'class-validator'; -import { PageOptionsDto } from '../../../../../common/dto/paginate/page-options'; import { Type } from 'class-transformer'; -import { OrderByConstraint } from '../../../../../common/constraint/orderby.constraint'; -import { ApplicationOrderBy } from '../../../../../common/enum/orderBy.enum'; -import { IDIR_USER_AUTH_GROUP_LIST } from '../../../../../common/enum/user-auth-group.enum'; +import { OrderByConstraint } from '../../../../../../common/constraint/orderby.constraint'; +import { PageOptionsDto } from '../../../../../../common/dto/paginate/page-options'; +import { ApplicationOrderBy } from '../../../../../../common/enum/orderBy.enum'; +import { IDIR_USER_AUTH_GROUP_LIST } from '../../../../../../common/enum/user-auth-group.enum'; export class GetApplicationQueryParamsDto extends PageOptionsDto { @ApiProperty({ diff --git a/vehicles/src/modules/permit/dto/request/update-application-status.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/request/update-application-status.dto.ts similarity index 100% rename from vehicles/src/modules/permit/dto/request/update-application-status.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/request/update-application-status.dto.ts diff --git a/vehicles/src/modules/permit/dto/request/update-application.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/request/update-application.dto.ts similarity index 50% rename from vehicles/src/modules/permit/dto/request/update-application.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/request/update-application.dto.ts index 06e68bf18..687317034 100644 --- a/vehicles/src/modules/permit/dto/request/update-application.dto.ts +++ b/vehicles/src/modules/permit-application-payment/application/dto/request/update-application.dto.ts @@ -8,9 +8,6 @@ import { IsString, MaxLength, } from 'class-validator'; -import { ApplicationStatus } from 'src/common/enum/application-status.enum'; -import { PermitApplicationOrigin } from 'src/common/enum/permit-application-origin.enum'; -import { PermitStatus } from 'src/common/enum/permit-status.enum'; import { PermitType } from 'src/common/enum/permit-type.enum'; export class UpdateApplicationDto { @@ -34,30 +31,6 @@ export class UpdateApplicationDto { @IsEnum(PermitType) permitType?: PermitType; - //ToDo: remove PermitStatus, update application should not change PermitStatus. there is an existing endpoint to change status. - @AutoMap() - @ApiProperty({ - enum: PermitStatus, - description: 'Friendly name for the permit type.', - required: false, - example: ApplicationStatus.IN_PROGRESS, - }) - @IsOptional() - @IsEnum(PermitStatus) - permitStatus?: PermitStatus; - - //ToDo: remove permitApplicationOrigin, update application should not change permitApplicationOrigin - @AutoMap() - @ApiProperty({ - enum: PermitApplicationOrigin, - example: PermitApplicationOrigin.ONLINE, - required: false, - description: 'Unique identifier for the application origin.', - }) - @IsOptional() - @IsEnum(PermitApplicationOrigin) - permitApplicationOrigin?: PermitApplicationOrigin; - @AutoMap() @ApiProperty({ description: 'Permit Application JSON.', diff --git a/vehicles/src/modules/permit/dto/response/read-application-metadata.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/response/read-application-metadata.dto.ts similarity index 100% rename from vehicles/src/modules/permit/dto/response/read-application-metadata.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/response/read-application-metadata.dto.ts diff --git a/vehicles/src/modules/permit/dto/response/read-application.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/response/read-application.dto.ts similarity index 100% rename from vehicles/src/modules/permit/dto/response/read-application.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/response/read-application.dto.ts diff --git a/vehicles/src/modules/permit/dto/response/result.dto.ts b/vehicles/src/modules/permit-application-payment/application/dto/response/result.dto.ts similarity index 100% rename from vehicles/src/modules/permit/dto/response/result.dto.ts rename to vehicles/src/modules/permit-application-payment/application/dto/response/result.dto.ts diff --git a/vehicles/src/modules/permit/entities/permit-application-origin.entity.ts b/vehicles/src/modules/permit-application-payment/application/entities/permit-application-origin.entity.ts similarity index 100% rename from vehicles/src/modules/permit/entities/permit-application-origin.entity.ts rename to vehicles/src/modules/permit-application-payment/application/entities/permit-application-origin.entity.ts diff --git a/vehicles/src/modules/permit/entities/permit-approval-source.entity.ts b/vehicles/src/modules/permit-application-payment/application/entities/permit-approval-source.entity.ts similarity index 100% rename from vehicles/src/modules/permit/entities/permit-approval-source.entity.ts rename to vehicles/src/modules/permit-application-payment/application/entities/permit-approval-source.entity.ts diff --git a/vehicles/src/modules/permit/profile/application.profile.ts b/vehicles/src/modules/permit-application-payment/application/profile/application.profile.ts similarity index 94% rename from vehicles/src/modules/permit/profile/application.profile.ts rename to vehicles/src/modules/permit-application-payment/application/profile/application.profile.ts index dea082c65..d0aeb408b 100644 --- a/vehicles/src/modules/permit/profile/application.profile.ts +++ b/vehicles/src/modules/permit-application-payment/application/profile/application.profile.ts @@ -7,18 +7,18 @@ import { mapWithArguments, } from '@automapper/core'; import { Injectable } from '@nestjs/common'; -import { Permit } from '../entities/permit.entity'; import { CreateApplicationDto } from '../dto/request/create-application.dto'; import { ReadApplicationDto } from '../dto/response/read-application.dto'; import { UpdateApplicationDto } from '../dto/request/update-application.dto'; -import { Directory } from '../../../common/enum/directory.enum'; -import { PPC_FULL_TEXT } from '../../../common/constants/api.constant'; +import { ReadApplicationMetadataDto } from '../dto/response/read-application-metadata.dto'; +import { PPC_FULL_TEXT } from '../../../../common/constants/api.constant'; +import { Directory } from '../../../../common/enum/directory.enum'; import { - IDIR_USER_AUTH_GROUP_LIST, UserAuthGroup, -} from '../../../common/enum/user-auth-group.enum'; -import { ReadApplicationMetadataDto } from '../dto/response/read-application-metadata.dto'; -import { doesUserHaveAuthGroup } from '../../../common/helper/auth.helper'; + IDIR_USER_AUTH_GROUP_LIST, +} from '../../../../common/enum/user-auth-group.enum'; +import { doesUserHaveAuthGroup } from '../../../../common/helper/auth.helper'; +import { Permit } from '../../permit/entities/permit.entity'; @Injectable() export class ApplicationProfile extends AutomapperProfile { @@ -36,6 +36,12 @@ export class ApplicationProfile extends AutomapperProfile { (d) => d.company.companyId, mapFrom((s) => s.companyId), ), + forMember( + (permit) => permit.permitApplicationOrigin, + mapWithArguments((_, { permitApplicationOrigin }) => { + return permitApplicationOrigin; + }), + ), forMember( (permit) => permit.applicationOwner?.userGUID, mapWithArguments((_, { userGUID }) => { diff --git a/vehicles/src/modules/payment/dto/common/payment-codes.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/common/payment-codes.dto.ts similarity index 78% rename from vehicles/src/modules/payment/dto/common/payment-codes.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/common/payment-codes.dto.ts index 453689395..88a123925 100644 --- a/vehicles/src/modules/payment/dto/common/payment-codes.dto.ts +++ b/vehicles/src/modules/permit-application-payment/payment/dto/common/payment-codes.dto.ts @@ -1,8 +1,8 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; import { IsEnum, IsOptional } from 'class-validator'; -import { PaymentMethodTypeReport } from '../../../../common/enum/payment-method-type.enum'; -import { PaymentCardType } from '../../../../common/enum/payment-card-type.enum'; +import { PaymentMethodTypeReport } from '../../../../../common/enum/payment-method-type.enum'; +import { PaymentCardType } from '../../../../../common/enum/payment-card-type.enum'; export class PaymentCodesDto { @AutoMap() diff --git a/vehicles/src/modules/payment/dto/common/payment-gateway-transaction.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/common/payment-gateway-transaction.dto.ts similarity index 100% rename from vehicles/src/modules/payment/dto/common/payment-gateway-transaction.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/common/payment-gateway-transaction.dto.ts diff --git a/vehicles/src/modules/payment/dto/request/create-application-transaction.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/request/create-application-transaction.dto.ts similarity index 100% rename from vehicles/src/modules/payment/dto/request/create-application-transaction.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/request/create-application-transaction.dto.ts diff --git a/vehicles/src/modules/payment/dto/request/create-payment-detailed-report.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/request/create-payment-detailed-report.dto.ts similarity index 90% rename from vehicles/src/modules/payment/dto/request/create-payment-detailed-report.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/request/create-payment-detailed-report.dto.ts index 7d0cc4202..9ef8dd970 100644 --- a/vehicles/src/modules/payment/dto/request/create-payment-detailed-report.dto.ts +++ b/vehicles/src/modules/permit-application-payment/payment/dto/request/create-payment-detailed-report.dto.ts @@ -8,11 +8,11 @@ import { IsOptional, ValidateNested, } from 'class-validator'; -import { PermitTypeReport } from '../../../../common/enum/permit-type.enum'; +import { PermitTypeReport } from '../../../../../common/enum/permit-type.enum'; import { Type } from 'class-transformer'; import { PaymentCodesDto } from '../common/payment-codes.dto'; -import { PermitIssuedBy } from '../../../../common/enum/permit-issued-by.enum'; -import { IsDateTimeAfter } from '../../../../common/decorator/is-date-time-after'; +import { PermitIssuedBy } from '../../../../../common/enum/permit-issued-by.enum'; +import { IsDateTimeAfter } from '../../../../../common/decorator/is-date-time-after'; export class CreatePaymentDetailedReportDto { @AutoMap() diff --git a/vehicles/src/modules/payment/dto/request/create-payment-summary-report.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/request/create-payment-summary-report.dto.ts similarity index 87% rename from vehicles/src/modules/payment/dto/request/create-payment-summary-report.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/request/create-payment-summary-report.dto.ts index e8f5529d6..dedeb0438 100644 --- a/vehicles/src/modules/payment/dto/request/create-payment-summary-report.dto.ts +++ b/vehicles/src/modules/permit-application-payment/payment/dto/request/create-payment-summary-report.dto.ts @@ -1,8 +1,8 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; import { ArrayMinSize, IsDateString, IsEnum } from 'class-validator'; -import { PermitIssuedBy } from '../../../../common/enum/permit-issued-by.enum'; -import { IsDateTimeAfter } from '../../../../common/decorator/is-date-time-after'; +import { PermitIssuedBy } from '../../../../../common/enum/permit-issued-by.enum'; +import { IsDateTimeAfter } from '../../../../../common/decorator/is-date-time-after'; export class CreatePaymentSummaryReportDto { @AutoMap() diff --git a/vehicles/src/modules/payment/dto/request/create-transaction.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/request/create-transaction.dto.ts similarity index 86% rename from vehicles/src/modules/payment/dto/request/create-transaction.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/request/create-transaction.dto.ts index 5be55402a..f7530c672 100644 --- a/vehicles/src/modules/payment/dto/request/create-transaction.dto.ts +++ b/vehicles/src/modules/permit-application-payment/payment/dto/request/create-transaction.dto.ts @@ -7,11 +7,11 @@ import { IsOptional, ValidateNested, } from 'class-validator'; -import { TransactionType } from '../../../../common/enum/transaction-type.enum'; -import { PaymentMethodType } from '../../../../common/enum/payment-method-type.enum'; +import { TransactionType } from '../../../../../common/enum/transaction-type.enum'; +import { PaymentMethodType } from '../../../../../common/enum/payment-method-type.enum'; import { Type } from 'class-transformer'; import { PaymentGatewayTransactionDto } from '../common/payment-gateway-transaction.dto'; -import { PaymentCardType } from '../../../../common/enum/payment-card-type.enum'; +import { PaymentCardType } from '../../../../../common/enum/payment-card-type.enum'; import { CreateApplicationTransactionDto } from './create-application-transaction.dto'; export class CreateTransactionDto extends PaymentGatewayTransactionDto { diff --git a/vehicles/src/modules/payment/dto/request/update-payment-gateway-transaction.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/request/update-payment-gateway-transaction.dto.ts similarity index 100% rename from vehicles/src/modules/payment/dto/request/update-payment-gateway-transaction.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/request/update-payment-gateway-transaction.dto.ts diff --git a/vehicles/src/modules/payment/dto/response/read-application-transaction.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/response/read-application-transaction.dto.ts similarity index 100% rename from vehicles/src/modules/payment/dto/response/read-application-transaction.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/response/read-application-transaction.dto.ts diff --git a/vehicles/src/modules/payment/dto/response/read-payment-gateway-transaction.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/response/read-payment-gateway-transaction.dto.ts similarity index 100% rename from vehicles/src/modules/payment/dto/response/read-payment-gateway-transaction.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/response/read-payment-gateway-transaction.dto.ts diff --git a/vehicles/src/modules/payment/dto/response/read-transaction.dto.ts b/vehicles/src/modules/permit-application-payment/payment/dto/response/read-transaction.dto.ts similarity index 89% rename from vehicles/src/modules/payment/dto/response/read-transaction.dto.ts rename to vehicles/src/modules/permit-application-payment/payment/dto/response/read-transaction.dto.ts index 0fe0f2643..5ff6e83f5 100644 --- a/vehicles/src/modules/payment/dto/response/read-transaction.dto.ts +++ b/vehicles/src/modules/permit-application-payment/payment/dto/response/read-transaction.dto.ts @@ -1,11 +1,11 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { TransactionType } from '../../../../common/enum/transaction-type.enum'; -import { PaymentMethodType } from '../../../../common/enum/payment-method-type.enum'; +import { TransactionType } from '../../../../../common/enum/transaction-type.enum'; +import { PaymentMethodType } from '../../../../../common/enum/payment-method-type.enum'; import { ReadApplicationTransactionDto } from './read-application-transaction.dto'; import { Type } from 'class-transformer'; import { PaymentGatewayTransactionDto } from '../common/payment-gateway-transaction.dto'; -import { PaymentCardType } from '../../../../common/enum/payment-card-type.enum'; +import { PaymentCardType } from '../../../../../common/enum/payment-card-type.enum'; export class ReadTransactionDto extends PaymentGatewayTransactionDto { @AutoMap() diff --git a/vehicles/src/modules/payment/entities/payment-card-type.entity.ts b/vehicles/src/modules/permit-application-payment/payment/entities/payment-card-type.entity.ts similarity index 100% rename from vehicles/src/modules/payment/entities/payment-card-type.entity.ts rename to vehicles/src/modules/permit-application-payment/payment/entities/payment-card-type.entity.ts diff --git a/vehicles/src/modules/payment/entities/payment-method-type.entity.ts b/vehicles/src/modules/permit-application-payment/payment/entities/payment-method-type.entity.ts similarity index 100% rename from vehicles/src/modules/payment/entities/payment-method-type.entity.ts rename to vehicles/src/modules/permit-application-payment/payment/entities/payment-method-type.entity.ts diff --git a/vehicles/src/modules/payment/entities/permit-transaction.entity.ts b/vehicles/src/modules/permit-application-payment/payment/entities/permit-transaction.entity.ts similarity index 94% rename from vehicles/src/modules/payment/entities/permit-transaction.entity.ts rename to vehicles/src/modules/permit-application-payment/payment/entities/permit-transaction.entity.ts index 20094ba87..b9f315688 100644 --- a/vehicles/src/modules/payment/entities/permit-transaction.entity.ts +++ b/vehicles/src/modules/permit-application-payment/payment/entities/permit-transaction.entity.ts @@ -6,7 +6,7 @@ import { PrimaryGeneratedColumn, } from 'typeorm'; import { AutoMap } from '@automapper/classes'; -import { Base } from 'src/modules/common/entities/base.entity'; +import { Base } from '../../../common/entities/base.entity'; import { Permit } from '../../permit/entities/permit.entity'; import { Transaction } from './transaction.entity'; import { ApiProperty } from '@nestjs/swagger'; diff --git a/vehicles/src/modules/payment/entities/receipt.entity.ts b/vehicles/src/modules/permit-application-payment/payment/entities/receipt.entity.ts similarity index 95% rename from vehicles/src/modules/payment/entities/receipt.entity.ts rename to vehicles/src/modules/permit-application-payment/payment/entities/receipt.entity.ts index 340713eed..73e2bd31c 100644 --- a/vehicles/src/modules/payment/entities/receipt.entity.ts +++ b/vehicles/src/modules/permit-application-payment/payment/entities/receipt.entity.ts @@ -7,7 +7,7 @@ import { JoinColumn, } from 'typeorm'; import { AutoMap } from '@automapper/classes'; -import { Base } from '../../common/entities/base.entity'; +import { Base } from '../../../common/entities/base.entity'; import { Transaction } from './transaction.entity'; @Entity({ name: 'permit.ORBC_RECEIPT' }) diff --git a/vehicles/src/modules/payment/entities/transaction.entity.ts b/vehicles/src/modules/permit-application-payment/payment/entities/transaction.entity.ts similarity index 94% rename from vehicles/src/modules/payment/entities/transaction.entity.ts rename to vehicles/src/modules/permit-application-payment/payment/entities/transaction.entity.ts index 0ab61ad5f..fef49f994 100644 --- a/vehicles/src/modules/payment/entities/transaction.entity.ts +++ b/vehicles/src/modules/permit-application-payment/payment/entities/transaction.entity.ts @@ -7,12 +7,12 @@ import { OneToMany, } from 'typeorm'; import { AutoMap } from '@automapper/classes'; -import { Base } from '../../common/entities/base.entity'; +import { Base } from '../../../common/entities/base.entity'; import { Receipt } from './receipt.entity'; -import { PaymentMethodType } from '../../../common/enum/payment-method-type.enum'; -import { TransactionType } from '../../../common/enum/transaction-type.enum'; +import { PaymentMethodType } from '../../../../common/enum/payment-method-type.enum'; +import { TransactionType } from '../../../../common/enum/transaction-type.enum'; import { PermitTransaction } from './permit-transaction.entity'; -import { PaymentCardType } from '../../../common/enum/payment-card-type.enum'; +import { PaymentCardType } from '../../../../common/enum/payment-card-type.enum'; @Entity({ name: 'permit.ORBC_TRANSACTION' }) export class Transaction extends Base { diff --git a/vehicles/src/modules/payment/payment-report.service.ts b/vehicles/src/modules/permit-application-payment/payment/payment-report.service.ts similarity index 95% rename from vehicles/src/modules/payment/payment-report.service.ts rename to vehicles/src/modules/permit-application-payment/payment/payment-report.service.ts index 2672e42b4..53053b6a4 100644 --- a/vehicles/src/modules/payment/payment-report.service.ts +++ b/vehicles/src/modules/permit-application-payment/payment/payment-report.service.ts @@ -5,26 +5,26 @@ import { Transaction } from './entities/transaction.entity'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository, SelectQueryBuilder } from 'typeorm'; import { IUserJWT } from 'src/common/interface/user-jwt.interface'; -import { PaymentMethodTypeReport } from '../../common/enum/payment-method-type.enum'; -import { PaymentCardType as PaymentCardTypeEnum } from '../../common/enum/payment-card-type.enum'; -import { TransactionType } from '../../common/enum/transaction-type.enum'; +import { PaymentMethodTypeReport } from '../../../common/enum/payment-method-type.enum'; +import { PaymentCardType as PaymentCardTypeEnum } from '../../../common/enum/payment-card-type.enum'; +import { TransactionType } from '../../../common/enum/transaction-type.enum'; import { Response } from 'express'; import { CreatePaymentDetailedReportDto } from './dto/request/create-payment-detailed-report.dto'; -import { DopsService } from '../common/dops.service'; -import { DopsGeneratedReport } from '../../common/interface/dops-generated-report.interface'; -import { ReportTemplate } from '../../common/enum/report-template.enum'; -import { convertUtcToPt } from '../../common/helper/date-time.helper'; +import { DopsService } from '../../common/dops.service'; +import { DopsGeneratedReport } from '../../../common/interface/dops-generated-report.interface'; +import { ReportTemplate } from '../../../common/enum/report-template.enum'; +import { convertUtcToPt } from '../../../common/helper/date-time.helper'; import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { Cache } from 'cache-manager'; -import { IPaymentCode } from '../../common/interface/payment-code.interface'; -import { PermitTypeReport } from '../../common/enum/permit-type.enum'; +import { IPaymentCode } from '../../../common/interface/payment-code.interface'; +import { PermitTypeReport } from '../../../common/enum/permit-type.enum'; import { CreatePaymentSummaryReportDto } from './dto/request/create-payment-summary-report.dto'; -import { PermitIssuedBy } from '../../common/enum/permit-issued-by.enum'; +import { PermitIssuedBy } from '../../../common/enum/permit-issued-by.enum'; import { PaymentMethodType } from './entities/payment-method-type.entity'; import { PaymentCardType } from './entities/payment-card-type.entity'; -import { getPaymentCodeFromCache } from '../../common/helper/payment.helper'; -import { LogAsyncMethodExecution } from '../../common/decorator/log-async-method-execution.decorator'; -import { Directory } from '../../common/enum/directory.enum'; +import { getPaymentCodeFromCache } from '../../../common/helper/payment.helper'; +import { LogAsyncMethodExecution } from '../../../common/decorator/log-async-method-execution.decorator'; +import { Directory } from '../../../common/enum/directory.enum'; @Injectable() export class PaymentReportService { diff --git a/vehicles/src/modules/payment/payment.controller.ts b/vehicles/src/modules/permit-application-payment/payment/payment.controller.ts similarity index 94% rename from vehicles/src/modules/payment/payment.controller.ts rename to vehicles/src/modules/permit-application-payment/payment/payment.controller.ts index 50bd572c2..3e3b9decd 100644 --- a/vehicles/src/modules/payment/payment.controller.ts +++ b/vehicles/src/modules/permit-application-payment/payment/payment.controller.ts @@ -19,7 +19,7 @@ import { ApiQuery, ApiTags, } from '@nestjs/swagger'; -import { ExceptionDto } from '../../common/exception/exception.dto'; +import { ExceptionDto } from '../../../common/exception/exception.dto'; import { PaymentService } from './payment.service'; import { CreateTransactionDto } from './dto/request/create-transaction.dto'; import { ReadTransactionDto } from './dto/response/read-transaction.dto'; @@ -28,11 +28,11 @@ import { Request, Response } from 'express'; import { UpdatePaymentGatewayTransactionDto } from './dto/request/update-payment-gateway-transaction.dto'; import { ReadPaymentGatewayTransactionDto } from './dto/response/read-payment-gateway-transaction.dto'; import { CreatePaymentDetailedReportDto } from './dto/request/create-payment-detailed-report.dto'; -import { ReadFileDto } from '../common/dto/response/read-file.dto'; +import { ReadFileDto } from '../../common/dto/response/read-file.dto'; import { CreatePaymentSummaryReportDto } from './dto/request/create-payment-summary-report.dto'; import { PaymentReportService } from './payment-report.service'; -import { Roles } from '../../common/decorator/roles.decorator'; -import { Role } from '../../common/enum/roles.enum'; +import { Roles } from '../../../common/decorator/roles.decorator'; +import { Role } from '../../../common/enum/roles.enum'; @ApiBearerAuth() @ApiTags('Payment') diff --git a/vehicles/src/modules/payment/payment.module.ts b/vehicles/src/modules/permit-application-payment/payment/payment.module.ts similarity index 100% rename from vehicles/src/modules/payment/payment.module.ts rename to vehicles/src/modules/permit-application-payment/payment/payment.module.ts diff --git a/vehicles/src/modules/payment/payment.service.ts b/vehicles/src/modules/permit-application-payment/payment/payment.service.ts similarity index 97% rename from vehicles/src/modules/payment/payment.service.ts rename to vehicles/src/modules/permit-application-payment/payment/payment.service.ts index 95b09b4cc..d29f100d0 100644 --- a/vehicles/src/modules/payment/payment.service.ts +++ b/vehicles/src/modules/permit-application-payment/payment/payment.service.ts @@ -16,9 +16,9 @@ import { PermitTransaction } from './entities/permit-transaction.entity'; import { IUserJWT } from 'src/common/interface/user-jwt.interface'; import { callDatabaseSequence } from 'src/common/helper/database.helper'; import { Permit } from '../permit/entities/permit.entity'; -import { ApplicationStatus } from '../../common/enum/application-status.enum'; -import { PaymentMethodType as PaymentMethodTypeEnum } from '../../common/enum/payment-method-type.enum'; -import { TransactionType } from '../../common/enum/transaction-type.enum'; +import { ApplicationStatus } from '../../../common/enum/application-status.enum'; +import { PaymentMethodType as PaymentMethodTypeEnum } from '../../../common/enum/payment-method-type.enum'; +import { TransactionType } from '../../../common/enum/transaction-type.enum'; import { ReadPaymentGatewayTransactionDto } from './dto/response/read-payment-gateway-transaction.dto'; import { Receipt } from './entities/receipt.entity'; @@ -27,13 +27,13 @@ import { PAYBC_PAYMENT_METHOD, PAYMENT_CURRENCY, CRYPTO_ALGORITHM_MD5, -} from '../../common/constants/api.constant'; +} from '../../../common/constants/api.constant'; import { convertToHash } from 'src/common/helper/crypto.helper'; import { UpdatePaymentGatewayTransactionDto } from './dto/request/update-payment-gateway-transaction.dto'; import { PaymentCardType } from './entities/payment-card-type.entity'; import { PaymentMethodType } from './entities/payment-method-type.entity'; -import { LogMethodExecution } from '../../common/decorator/log-method-execution.decorator'; -import { LogAsyncMethodExecution } from '../../common/decorator/log-async-method-execution.decorator'; +import { LogMethodExecution } from '../../../common/decorator/log-method-execution.decorator'; +import { LogAsyncMethodExecution } from '../../../common/decorator/log-async-method-execution.decorator'; @Injectable() export class PaymentService { diff --git a/vehicles/src/modules/payment/profile/transaction.profile.ts b/vehicles/src/modules/permit-application-payment/payment/profile/transaction.profile.ts similarity index 100% rename from vehicles/src/modules/payment/profile/transaction.profile.ts rename to vehicles/src/modules/permit-application-payment/payment/profile/transaction.profile.ts diff --git a/vehicles/src/modules/permit/dto/request/queryParam/getPermit.query-params.dto.ts b/vehicles/src/modules/permit-application-payment/permit/dto/request/queryParam/getPermit.query-params.dto.ts similarity index 82% rename from vehicles/src/modules/permit/dto/request/queryParam/getPermit.query-params.dto.ts rename to vehicles/src/modules/permit-application-payment/permit/dto/request/queryParam/getPermit.query-params.dto.ts index bf882ddd9..2c84fcf64 100644 --- a/vehicles/src/modules/permit/dto/request/queryParam/getPermit.query-params.dto.ts +++ b/vehicles/src/modules/permit-application-payment/permit/dto/request/queryParam/getPermit.query-params.dto.ts @@ -1,4 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; +import { Type, Transform } from 'class-transformer'; import { IsOptional, IsBoolean, @@ -8,13 +9,12 @@ import { Validate, IsEnum, } from 'class-validator'; -import { PageOptionsDto } from '../../../../../common/dto/paginate/page-options'; -import { Transform, Type } from 'class-transformer'; -import { PermitSearchByConstraint } from '../../../../../common/constraint/permit-search.constraint'; -import { PermitSearch } from '../../../../../common/enum/permit-search.enum'; -import { OrderByConstraint } from '../../../../../common/constraint/orderby.constraint'; -import { PermitOrderBy } from '../../../../../common/enum/orderBy.enum'; -import { IDIR_USER_AUTH_GROUP_LIST } from '../../../../../common/enum/user-auth-group.enum'; +import { OrderByConstraint } from '../../../../../../common/constraint/orderby.constraint'; +import { PermitSearchByConstraint } from '../../../../../../common/constraint/permit-search.constraint'; +import { PageOptionsDto } from '../../../../../../common/dto/paginate/page-options'; +import { PermitOrderBy } from '../../../../../../common/enum/orderBy.enum'; +import { PermitSearch } from '../../../../../../common/enum/permit-search.enum'; +import { IDIR_USER_AUTH_GROUP_LIST } from '../../../../../../common/enum/user-auth-group.enum'; export class GetPermitQueryParamsDto extends PageOptionsDto { @ApiProperty({ diff --git a/vehicles/src/modules/permit/dto/request/void-permit.dto.ts b/vehicles/src/modules/permit-application-payment/permit/dto/request/void-permit.dto.ts similarity index 91% rename from vehicles/src/modules/permit/dto/request/void-permit.dto.ts rename to vehicles/src/modules/permit-application-payment/permit/dto/request/void-permit.dto.ts index d6a3ef297..4011ce200 100644 --- a/vehicles/src/modules/permit/dto/request/void-permit.dto.ts +++ b/vehicles/src/modules/permit-application-payment/permit/dto/request/void-permit.dto.ts @@ -12,9 +12,9 @@ import { MinLength, } from 'class-validator'; import { ApplicationStatus } from 'src/common/enum/application-status.enum'; -import { PaymentMethodType } from '../../../../common/enum/payment-method-type.enum'; -import { TransactionType } from '../../../../common/enum/transaction-type.enum'; -import { PaymentCardType } from '../../../../common/enum/payment-card-type.enum'; +import { PaymentMethodType } from '../../../../../common/enum/payment-method-type.enum'; +import { TransactionType } from '../../../../../common/enum/transaction-type.enum'; +import { PaymentCardType } from '../../../../../common/enum/payment-card-type.enum'; export class VoidPermitDto { @AutoMap() diff --git a/vehicles/src/modules/permit/dto/response/permit-history.dto.ts b/vehicles/src/modules/permit-application-payment/permit/dto/response/permit-history.dto.ts similarity index 97% rename from vehicles/src/modules/permit/dto/response/permit-history.dto.ts rename to vehicles/src/modules/permit-application-payment/permit/dto/response/permit-history.dto.ts index 4a2ceacad..c8caa90b5 100644 --- a/vehicles/src/modules/permit/dto/response/permit-history.dto.ts +++ b/vehicles/src/modules/permit-application-payment/permit/dto/response/permit-history.dto.ts @@ -1,6 +1,6 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { TransactionType } from '../../../../common/enum/transaction-type.enum'; +import { TransactionType } from '../../../../../common/enum/transaction-type.enum'; import { PaymentMethodType } from 'src/common/enum/payment-method-type.enum'; import { PaymentCardType } from 'src/common/enum/payment-card-type.enum'; diff --git a/vehicles/src/modules/permit/dto/response/read-permit-metadata.dto.ts b/vehicles/src/modules/permit-application-payment/permit/dto/response/read-permit-metadata.dto.ts similarity index 92% rename from vehicles/src/modules/permit/dto/response/read-permit-metadata.dto.ts rename to vehicles/src/modules/permit-application-payment/permit/dto/response/read-permit-metadata.dto.ts index c173d6b6d..e12f6b7ac 100644 --- a/vehicles/src/modules/permit/dto/response/read-permit-metadata.dto.ts +++ b/vehicles/src/modules/permit-application-payment/permit/dto/response/read-permit-metadata.dto.ts @@ -1,8 +1,8 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { PermitType } from '../../../../common/enum/permit-type.enum'; -import { PermitApprovalSource } from '../../../../common/enum/permit-approval-source.enum'; -import { PermitApplicationOrigin } from '../../../../common/enum/permit-application-origin.enum'; +import { PermitType } from '../../../../../common/enum/permit-type.enum'; +import { PermitApprovalSource } from '../../../../../common/enum/permit-approval-source.enum'; +import { PermitApplicationOrigin } from '../../../../../common/enum/permit-application-origin.enum'; import { PermitStatus } from 'src/common/enum/permit-status.enum'; export class ReadPermitMetadataDto { diff --git a/vehicles/src/modules/permit/dto/response/read-permit.dto.ts b/vehicles/src/modules/permit-application-payment/permit/dto/response/read-permit.dto.ts similarity index 91% rename from vehicles/src/modules/permit/dto/response/read-permit.dto.ts rename to vehicles/src/modules/permit-application-payment/permit/dto/response/read-permit.dto.ts index 0d9d84c3a..0d2db70d3 100644 --- a/vehicles/src/modules/permit/dto/response/read-permit.dto.ts +++ b/vehicles/src/modules/permit-application-payment/permit/dto/response/read-permit.dto.ts @@ -1,8 +1,8 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { PermitType } from '../../../../common/enum/permit-type.enum'; -import { PermitApprovalSource } from '../../../../common/enum/permit-approval-source.enum'; -import { PermitApplicationOrigin } from '../../../../common/enum/permit-application-origin.enum'; +import { PermitType } from '../../../../../common/enum/permit-type.enum'; +import { PermitApprovalSource } from '../../../../../common/enum/permit-approval-source.enum'; +import { PermitApplicationOrigin } from '../../../../../common/enum/permit-application-origin.enum'; import { PermitStatus } from 'src/common/enum/permit-status.enum'; export class ReadPermitDto { diff --git a/vehicles/src/modules/permit-application-payment/permit/dto/response/result.dto.ts b/vehicles/src/modules/permit-application-payment/permit/dto/response/result.dto.ts new file mode 100644 index 000000000..f415fe2d8 --- /dev/null +++ b/vehicles/src/modules/permit-application-payment/permit/dto/response/result.dto.ts @@ -0,0 +1,5 @@ +export class ResultDto { + success: string[]; + + failure: string[]; +} diff --git a/vehicles/src/modules/permit/entities/permit-data.entity.ts b/vehicles/src/modules/permit-application-payment/permit/entities/permit-data.entity.ts similarity index 95% rename from vehicles/src/modules/permit/entities/permit-data.entity.ts rename to vehicles/src/modules/permit-application-payment/permit/entities/permit-data.entity.ts index 7b2c66d8a..9dd6ff90d 100644 --- a/vehicles/src/modules/permit/entities/permit-data.entity.ts +++ b/vehicles/src/modules/permit-application-payment/permit/entities/permit-data.entity.ts @@ -8,7 +8,7 @@ import { Index, } from 'typeorm'; import { AutoMap } from '@automapper/classes'; -import { Base } from '../../common/entities/base.entity'; +import { Base } from '../../../common/entities/base.entity'; import { Permit } from './permit.entity'; @Entity({ name: 'permit.ORBC_PERMIT_DATA' }) diff --git a/vehicles/src/modules/permit/entities/permit-type.entity.ts b/vehicles/src/modules/permit-application-payment/permit/entities/permit-type.entity.ts similarity index 100% rename from vehicles/src/modules/permit/entities/permit-type.entity.ts rename to vehicles/src/modules/permit-application-payment/permit/entities/permit-type.entity.ts diff --git a/vehicles/src/modules/permit/entities/permit.entity.ts b/vehicles/src/modules/permit-application-payment/permit/entities/permit.entity.ts similarity index 90% rename from vehicles/src/modules/permit/entities/permit.entity.ts rename to vehicles/src/modules/permit-application-payment/permit/entities/permit.entity.ts index aa8279c74..78624d4dc 100644 --- a/vehicles/src/modules/permit/entities/permit.entity.ts +++ b/vehicles/src/modules/permit-application-payment/permit/entities/permit.entity.ts @@ -9,16 +9,16 @@ import { JoinColumn, } from 'typeorm'; import { AutoMap } from '@automapper/classes'; -import { Base } from '../../common/entities/base.entity'; -import { PermitType } from '../../../common/enum/permit-type.enum'; +import { Base } from '../../../common/entities/base.entity'; +import { PermitType } from '../../../../common/enum/permit-type.enum'; import { PermitData } from './permit-data.entity'; -import { PermitApplicationOrigin } from '../../../common/enum/permit-application-origin.enum'; -import { PermitApprovalSource } from '../../../common/enum/permit-approval-source.enum'; +import { PermitApplicationOrigin } from '../../../../common/enum/permit-application-origin.enum'; +import { PermitApprovalSource } from '../../../../common/enum/permit-approval-source.enum'; import { ApplicationStatus } from 'src/common/enum/application-status.enum'; import { PermitTransaction } from '../../payment/entities/permit-transaction.entity'; -import { PermitIssuedBy } from '../../../common/enum/permit-issued-by.enum'; -import { User } from '../../company-user-management/users/entities/user.entity'; -import { Company } from '../../company-user-management/company/entities/company.entity'; +import { PermitIssuedBy } from '../../../../common/enum/permit-issued-by.enum'; +import { User } from '../../../company-user-management/users/entities/user.entity'; +import { Company } from '../../../company-user-management/company/entities/company.entity'; @Entity({ name: 'permit.ORBC_PERMIT' }) export class Permit extends Base { diff --git a/vehicles/src/modules/permit/permit.controller.ts b/vehicles/src/modules/permit-application-payment/permit/permit.controller.ts similarity index 93% rename from vehicles/src/modules/permit/permit.controller.ts rename to vehicles/src/modules/permit-application-payment/permit/permit.controller.ts index 11dd7f594..a531a86a9 100644 --- a/vehicles/src/modules/permit/permit.controller.ts +++ b/vehicles/src/modules/permit-application-payment/permit/permit.controller.ts @@ -10,7 +10,7 @@ import { BadRequestException, } from '@nestjs/common'; import { PermitService } from './permit.service'; -import { ExceptionDto } from '../../common/exception/exception.dto'; +import { ExceptionDto } from '../../../common/exception/exception.dto'; import { ApiTags, ApiNotFoundResponse, @@ -21,12 +21,12 @@ import { ApiOkResponse, ApiOperation, } from '@nestjs/swagger'; -import { AuthOnly } from '../../common/decorator/auth-only.decorator'; +import { AuthOnly } from '../../../common/decorator/auth-only.decorator'; import { ReadPermitDto } from './dto/response/read-permit.dto'; import { Request, Response } from 'express'; -import { IUserJWT } from '../../common/interface/user-jwt.interface'; -import { FileDownloadModes } from '../../common/enum/file-download-modes.enum'; -import { ReadFileDto } from '../common/dto/response/read-file.dto'; +import { IUserJWT } from '../../../common/interface/user-jwt.interface'; +import { FileDownloadModes } from '../../../common/enum/file-download-modes.enum'; +import { ReadFileDto } from '../../common/dto/response/read-file.dto'; import { Roles } from 'src/common/decorator/roles.decorator'; import { Role } from 'src/common/enum/roles.enum'; import { PaginationDto } from 'src/common/dto/paginate/pagination'; @@ -40,7 +40,7 @@ import { IDIR_USER_AUTH_GROUP_LIST, } from 'src/common/enum/user-auth-group.enum'; import { ReadPermitMetadataDto } from './dto/response/read-permit-metadata.dto'; -import { doesUserHaveAuthGroup } from '../../common/helper/auth.helper'; +import { doesUserHaveAuthGroup } from '../../../common/helper/auth.helper'; @ApiBearerAuth() @ApiTags('Permit') diff --git a/vehicles/src/modules/permit-application-payment/permit/permit.module.ts b/vehicles/src/modules/permit-application-payment/permit/permit.module.ts new file mode 100644 index 000000000..a101c8c3e --- /dev/null +++ b/vehicles/src/modules/permit-application-payment/permit/permit.module.ts @@ -0,0 +1,21 @@ +import { Module } from '@nestjs/common'; +import { PermitService } from './permit.service'; +import { PermitController } from './permit.controller'; + +import { TypeOrmModule } from '@nestjs/typeorm'; +import { PermitProfile } from './profile/permit.profile'; +import { PermitData } from './entities/permit-data.entity'; +import { Permit } from './entities/permit.entity'; +import { PermitType } from './entities/permit-type.entity'; +import { PaymentModule } from '../payment/payment.module'; + +@Module({ + imports: [ + TypeOrmModule.forFeature([Permit, PermitData, PermitType]), + PaymentModule, + ], + controllers: [PermitController], + providers: [PermitService, PermitProfile], + exports: [PermitService], +}) +export class PermitModule {} diff --git a/vehicles/src/modules/permit/permit.service.ts b/vehicles/src/modules/permit-application-payment/permit/permit.service.ts similarity index 89% rename from vehicles/src/modules/permit/permit.service.ts rename to vehicles/src/modules/permit-application-payment/permit/permit.service.ts index 4dc605bf4..c58bdd58b 100644 --- a/vehicles/src/modules/permit/permit.service.ts +++ b/vehicles/src/modules/permit-application-payment/permit/permit.service.ts @@ -5,7 +5,6 @@ import { InternalServerErrorException, Logger, NotFoundException, - forwardRef, } from '@nestjs/common'; import { Mapper } from '@automapper/core'; import { InjectMapper } from '@automapper/nestjs'; @@ -14,25 +13,25 @@ import { Brackets, DataSource, Repository, SelectQueryBuilder } from 'typeorm'; import { ReadPermitDto } from './dto/response/read-permit.dto'; import { Permit } from './entities/permit.entity'; import { PermitType } from './entities/permit-type.entity'; -import { DopsService } from '../common/dops.service'; -import { FileDownloadModes } from '../../common/enum/file-download-modes.enum'; -import { IUserJWT } from '../../common/interface/user-jwt.interface'; +import { DopsService } from '../../common/dops.service'; +import { FileDownloadModes } from '../../../common/enum/file-download-modes.enum'; +import { IUserJWT } from '../../../common/interface/user-jwt.interface'; import { Response } from 'express'; import { PermitStatus } from 'src/common/enum/permit-status.enum'; import { Receipt } from '../payment/entities/receipt.entity'; import { PaginationDto } from 'src/common/dto/paginate/pagination'; import { PermitHistoryDto } from './dto/response/permit-history.dto'; -import { ApplicationStatus } from 'src/common/enum/application-status.enum'; -import { ApplicationService } from './application.service'; -import { formatTemplateData } from './helpers/formatTemplateData.helper'; -import { CompanyService } from '../company-user-management/company/company.service'; +import { + ACTIVE_APPLICATION_STATUS_FOR_ISSUANCE, + ApplicationStatus, +} from 'src/common/enum/application-status.enum'; import { DopsGeneratedDocument } from 'src/common/interface/dops-generated-document.interface'; import { TemplateName } from 'src/common/enum/template-name.enum'; import { convertUtcToPt } from 'src/common/helper/date-time.helper'; import { IFile } from 'src/common/interface/file.interface'; import { IssuePermitEmailData } from 'src/common/interface/issue-permit-email-data.interface'; import { AttachementEmailData } from 'src/common/interface/attachment-email-data.interface'; -import { EmailService } from '../email/email.service'; +import { EmailService } from '../../email/email.service'; import { EmailTemplate } from 'src/common/enum/email-template.enum'; import { ResultDto } from './dto/response/result.dto'; import { VoidPermitDto } from './dto/request/void-permit.dto'; @@ -41,27 +40,35 @@ import { CreateTransactionDto } from '../payment/dto/request/create-transaction. import { Transaction } from '../payment/entities/transaction.entity'; import { Directory } from 'src/common/enum/directory.enum'; import { PermitData } from './entities/permit-data.entity'; -import { Base } from '../common/entities/base.entity'; +import { Base } from '../../common/entities/base.entity'; import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { CacheKey } from 'src/common/enum/cache-key.enum'; import { getMapFromCache } from 'src/common/helper/cache.helper'; import { Cache } from 'cache-manager'; -import { PermitIssuedBy } from '../../common/enum/permit-issued-by.enum'; +import { PermitIssuedBy } from '../../../common/enum/permit-issued-by.enum'; import { formatAmount, getPaymentCodeFromCache, -} from '../../common/helper/payment.helper'; +} from '../../../common/helper/payment.helper'; import { PaymentMethodType } from 'src/common/enum/payment-method-type.enum'; import { PageMetaDto } from 'src/common/dto/paginate/page-meta'; -import { LogAsyncMethodExecution } from '../../common/decorator/log-async-method-execution.decorator'; -import * as constants from '../../common/constants/api.constant'; -import { PermitApprovalSource } from '../../common/enum/permit-approval-source.enum'; -import { PermitSearch } from '../../common/enum/permit-search.enum'; -import { paginate, sortQuery } from '../../common/helper/database.helper'; -import { IDIR_USER_AUTH_GROUP_LIST } from '../../common/enum/user-auth-group.enum'; -import { User } from '../company-user-management/users/entities/user.entity'; +import { LogAsyncMethodExecution } from '../../../common/decorator/log-async-method-execution.decorator'; +import * as constants from '../../../common/constants/api.constant'; +import { PermitApprovalSource } from '../../../common/enum/permit-approval-source.enum'; +import { PermitSearch } from '../../../common/enum/permit-search.enum'; +import { paginate, sortQuery } from '../../../common/helper/database.helper'; +import { IDIR_USER_AUTH_GROUP_LIST } from '../../../common/enum/user-auth-group.enum'; +import { User } from '../../company-user-management/users/entities/user.entity'; import { ReadPermitMetadataDto } from './dto/response/read-permit-metadata.dto'; -import { doesUserHaveAuthGroup } from '../../common/helper/auth.helper'; +import { doesUserHaveAuthGroup } from '../../../common/helper/auth.helper'; +import { formatTemplateData } from '../../../common/helper/format-template-data.helper'; +import { + fetchPermitDataDescriptionValuesFromCache, + generateApplicationNumber, + generatePermitNumber, +} from '../../../common/helper/permit-application.helper'; +import { IDP } from '../../../common/enum/idp.enum'; +import { PermitApplicationOrigin as PermitApplicationOriginEnum } from '../../../common/enum/permit-application-origin.enum'; @Injectable() export class PermitService { @@ -74,10 +81,7 @@ export class PermitService { private permitTypeRepository: Repository, private dataSource: DataSource, private readonly dopsService: DopsService, - private companyService: CompanyService, private readonly emailService: EmailService, - @Inject(forwardRef(() => ApplicationService)) - private readonly applicationService: ApplicationService, private paymentService: PaymentService, @Inject(CACHE_MANAGER) private readonly cacheManager: Cache, @@ -495,6 +499,22 @@ export class PermitService { ) as PermitHistoryDto[]; } + @LogAsyncMethodExecution() + async checkApplicationInProgressForIssuance( + originalPermitId: string, + ): Promise { + const count = await this.permitRepository + .createQueryBuilder('permit') + .where('permit.originalPermitId = :originalPermitId', { + originalPermitId: originalPermitId, + }) + .andWhere('permit.permitStatus IN (:...applicationStatus)', { + applicationStatus: ACTIVE_APPLICATION_STATUS_FOR_ISSUANCE, + }) + .getCount(); + return count; + } + /** * * @param permitId ex: 1 @@ -523,24 +543,27 @@ export class PermitService { /** * If application in progress for permit then raise error. */ - const applicationCount = - await this.applicationService.checkApplicationInProgress( - permit.originalPermitId, - ); + const applicationCount = await this.checkApplicationInProgressForIssuance( + permit.originalPermitId, + ); if (applicationCount > 0) { throw new InternalServerErrorException( 'An application exists for this permit. Please cancel application before voiding permit.', ); } - const applicationNumber = - await this.applicationService.generateApplicationNumber( - currentUser.identity_provider, - permitId, - ); - const permitNumber = await this.applicationService.generatePermitNumber( - null, - permitId, + + //Generate appliction number for the application to be created in database. + const applicationNumber = await generateApplicationNumber( + this.dataSource, + this.cacheManager, + currentUser.identity_provider === IDP.IDIR + ? PermitApplicationOriginEnum.PPC + : PermitApplicationOriginEnum.ONLINE, + permit, ); + + const permitNumber = await generatePermitNumber(this.cacheManager, permit); + let success = ''; let failure = ''; @@ -642,8 +665,10 @@ export class PermitService { const companyInfo = newPermit.company; - const fullNames = - await this.applicationService.getFullNamesFromCache(newPermit); + const fullNames = await fetchPermitDataDescriptionValuesFromCache( + this.cacheManager, + newPermit, + ); const revisionHistory = await queryRunner.manager.find(Permit, { where: { originalPermitId: permit.originalPermitId }, @@ -673,12 +698,11 @@ export class PermitService { ), }; - const generatedPermitDocumentPromise = - this.applicationService.generateDocument( - currentUser, - dopsRequestData, - companyInfo.companyId, - ); + const generatedPermitDocumentPromise = this.generateDocument( + currentUser, + dopsRequestData, + companyInfo.companyId, + ); dopsRequestData = { templateName: TemplateName.PAYMENT_RECEIPT, @@ -721,12 +745,11 @@ export class PermitService { }, }; - const generatedReceiptDocumentPromise = - this.applicationService.generateDocument( - currentUser, - dopsRequestData, - companyInfo.companyId, - ); + const generatedReceiptDocumentPromise = this.generateDocument( + currentUser, + dopsRequestData, + companyInfo.companyId, + ); const generatedDocuments: IFile[] = await Promise.all([ generatedPermitDocumentPromise, @@ -830,4 +853,18 @@ export class PermitService { async getPermitType(): Promise> { return await getMapFromCache(this.cacheManager, CacheKey.PERMIT_TYPE); } + + @LogAsyncMethodExecution() + async generateDocument( + currentUser: IUserJWT, + dopsRequestData: DopsGeneratedDocument, + companyId?: number, + ) { + return await this.dopsService.generateDocument( + currentUser, + dopsRequestData, + undefined, + companyId, + ); + } } diff --git a/vehicles/src/modules/permit/profile/permit.profile.ts b/vehicles/src/modules/permit-application-payment/permit/profile/permit.profile.ts similarity index 94% rename from vehicles/src/modules/permit/profile/permit.profile.ts rename to vehicles/src/modules/permit-application-payment/permit/profile/permit.profile.ts index 3c7c46f56..578914331 100644 --- a/vehicles/src/modules/permit/profile/permit.profile.ts +++ b/vehicles/src/modules/permit-application-payment/permit/profile/permit.profile.ts @@ -9,14 +9,14 @@ import { import { Injectable } from '@nestjs/common'; import { Permit } from '../entities/permit.entity'; import { ReadPermitDto } from '../dto/response/read-permit.dto'; -import { Directory } from '../../../common/enum/directory.enum'; -import { PPC_FULL_TEXT } from '../../../common/constants/api.constant'; +import { PPC_FULL_TEXT } from '../../../../common/constants/api.constant'; +import { Directory } from '../../../../common/enum/directory.enum'; import { - IDIR_USER_AUTH_GROUP_LIST, UserAuthGroup, -} from '../../../common/enum/user-auth-group.enum'; + IDIR_USER_AUTH_GROUP_LIST, +} from '../../../../common/enum/user-auth-group.enum'; +import { doesUserHaveAuthGroup } from '../../../../common/helper/auth.helper'; import { ReadPermitMetadataDto } from '../dto/response/read-permit-metadata.dto'; -import { doesUserHaveAuthGroup } from '../../../common/helper/auth.helper'; @Injectable() export class PermitProfile extends AutomapperProfile { diff --git a/vehicles/src/modules/permit/permit.module.ts b/vehicles/src/modules/permit/permit.module.ts deleted file mode 100644 index 9b46ac22b..000000000 --- a/vehicles/src/modules/permit/permit.module.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { Module } from '@nestjs/common'; -import { PermitService } from './permit.service'; -import { PermitController } from './permit.controller'; - -import { TypeOrmModule } from '@nestjs/typeorm'; -import { PermitProfile } from './profile/permit.profile'; -import { PermitData } from './entities/permit-data.entity'; -import { Permit } from './entities/permit.entity'; -import { ApplicationController } from './application.controller'; -import { ApplicationService } from './application.service'; -import { ApplicationProfile } from './profile/application.profile'; -import { PermitType } from './entities/permit-type.entity'; -import { PermitApplicationOrigin } from './entities/permit-application-origin.entity'; -import { PermitApprovalSource } from './entities/permit-approval-source.entity'; -import { CompanyModule } from '../company-user-management/company/company.module'; -import { Receipt } from '../payment/entities/receipt.entity'; -import { Transaction } from '../payment/entities/transaction.entity'; -import { PaymentModule } from '../payment/payment.module'; - -@Module({ - imports: [ - TypeOrmModule.forFeature([ - Permit, - PermitData, - PermitType, - PermitApplicationOrigin, - PermitApprovalSource, - Transaction, - Receipt, - ]), - CompanyModule, - PaymentModule, - ], - controllers: [ApplicationController, PermitController], - providers: [ - PermitService, - ApplicationService, - PermitProfile, - ApplicationProfile, - ], - exports: [PermitService, ApplicationService], -}) -export class PermitModule {} diff --git a/vehicles/test/e2e/app.e2e-spec.ts b/vehicles/test/e2e/app.e2e-spec.ts index 86720a7ee..efd7fada6 100644 --- a/vehicles/test/e2e/app.e2e-spec.ts +++ b/vehicles/test/e2e/app.e2e-spec.ts @@ -8,12 +8,14 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { PowerUnitTypesService } from 'src/modules/vehicles/power-unit-types/power-unit-types.service'; import { TrailerTypesService } from 'src/modules/vehicles/trailer-types/trailer-types.service'; import { CommonService } from 'src/modules/common/common.service'; -import { PermitService } from 'src/modules/permit/permit.service'; -import { PaymentService } from '../../src/modules/payment/payment.service'; import { App } from 'supertest/types'; import { FeatureFlagsService } from '../../src/modules/feature-flags/feature-flags.service'; +import { PermitService } from '../../src/modules/permit-application-payment/permit/permit.service'; +import { PaymentService } from '../../src/modules/permit-application-payment/payment/payment.service'; +import { ApplicationService } from '../../src/modules/permit-application-payment/application/application.service'; let permitServiceMock: DeepMocked; +let applicationServiceMock: DeepMocked; let powerUnitTypeServiceMock: DeepMocked; let trailerTypeServiceMock: DeepMocked; let commonServiceMock: DeepMocked; @@ -25,6 +27,7 @@ describe('AppController (e2e)', () => { beforeAll(async () => { permitServiceMock = createMock(); + applicationServiceMock = createMock(); powerUnitTypeServiceMock = createMock(); trailerTypeServiceMock = createMock(); commonServiceMock = createMock(); @@ -40,6 +43,10 @@ describe('AppController (e2e)', () => { provide: PermitService, useValue: permitServiceMock, }, + { + provide: ApplicationService, + useValue: applicationServiceMock, + }, { provide: PowerUnitTypesService, useValue: powerUnitTypeServiceMock, diff --git a/vehicles/test/unit/app/app.controller.spec.ts b/vehicles/test/unit/app/app.controller.spec.ts index b0ae827e8..9e4df6e64 100644 --- a/vehicles/test/unit/app/app.controller.spec.ts +++ b/vehicles/test/unit/app/app.controller.spec.ts @@ -6,11 +6,13 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { PowerUnitTypesService } from 'src/modules/vehicles/power-unit-types/power-unit-types.service'; import { TrailerTypesService } from 'src/modules/vehicles/trailer-types/trailer-types.service'; import { CommonService } from 'src/modules/common/common.service'; -import { PermitService } from 'src/modules/permit/permit.service'; -import { PaymentService } from '../../../src/modules/payment/payment.service'; import { FeatureFlagsService } from 'src/modules/feature-flags/feature-flags.service'; +import { PermitService } from '../../../src/modules/permit-application-payment/permit/permit.service'; +import { PaymentService } from '../../../src/modules/permit-application-payment/payment/payment.service'; +import { ApplicationService } from '../../../src/modules/permit-application-payment/application/application.service'; let permitServiceMock: DeepMocked; +let applicationServiceMock: DeepMocked; let powerUnitTypeServiceMock: DeepMocked; let trailerTypeServiceMock: DeepMocked; let commonServiceMock: DeepMocked; @@ -22,6 +24,7 @@ describe('AppController', () => { beforeEach(async () => { permitServiceMock = createMock(); + applicationServiceMock = createMock(); powerUnitTypeServiceMock = createMock(); trailerTypeServiceMock = createMock(); commonServiceMock = createMock(); @@ -37,6 +40,10 @@ describe('AppController', () => { provide: PermitService, useValue: permitServiceMock, }, + { + provide: ApplicationService, + useValue: applicationServiceMock, + }, { provide: PowerUnitTypesService, useValue: powerUnitTypeServiceMock,