Skip to content

Commit

Permalink
fix: circular dependency between Permit, Applications, Payments (#1268)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Mar 15, 2024
1 parent 948dc69 commit 12b2812
Show file tree
Hide file tree
Showing 64 changed files with 623 additions and 554 deletions.
6 changes: 3 additions & 3 deletions dops/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tps-migration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vehicles/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions vehicles/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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() + '/../');

Expand Down Expand Up @@ -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],
Expand Down
22 changes: 20 additions & 2 deletions vehicles/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,6 +26,7 @@ export class AppService {
private commonService: CommonService,
private paymentService: PaymentService,
private featureFlagsService: FeatureFlagsService,
private applicationService: ApplicationService,
) {}

getHello(): string {
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 11 additions & 10 deletions vehicles/src/common/enum/application-status.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> =
[
ApplicationStatus.IN_PROGRESS,
ApplicationStatus.WAITING_PAYMENT,
ApplicationStatus.CANCELLED,
ApplicationStatus.UNDER_REVIEW,
];
export const ACTIVE_APPLICATION_STATUS_FOR_ISSUANCE: ReadonlyArray<ApplicationStatus> =
[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> =
[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> =
[
ApplicationStatus.IN_PROGRESS,
ApplicationStatus.WAITING_PAYMENT,
ApplicationStatus.UNDER_REVIEW,
//ApplicationStatus.CANCELLED, //! Discovery Pending
];
2 changes: 2 additions & 0 deletions vehicles/src/common/enum/cache-key.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
20 changes: 0 additions & 20 deletions vehicles/src/common/helper/application.status.helper.ts

This file was deleted.

14 changes: 10 additions & 4 deletions vehicles/src/common/helper/database.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ export const callDatabaseSequence = async (
dataSource: DataSource,
): Promise<string> => {
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;
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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[],
) => {
Expand Down
Loading

0 comments on commit 12b2812

Please sign in to comment.