-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor PPSApi class and separate different modules (#10)
- Loading branch information
Showing
28 changed files
with
983 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,16 @@ | ||
import { Module, OnModuleInit, Scope } from '@nestjs/common'; | ||
import { HttpModule, HttpService } from '@nestjs/axios'; | ||
|
||
import { Agent } from 'https'; | ||
|
||
import { IHtmlParserSymbol } from '@easy-pps/html-parser/contracts'; | ||
import { HtmlParser } from '@easy-pps'; | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { GenerateController } from './generate.controller'; | ||
import { PPSGeneratorUseCase } from './pps/usecase/pps-generator-usecase.service'; | ||
import { IPPSGenerateUseCaseSymbol } from './pps/usecase/pps-generate-usecase.interface'; | ||
import { IPPSApiSymbol } from './pps/third-party/pps-api.interface'; | ||
import { PPSApi } from './pps/third-party/pps-api'; | ||
import { IPPSApiResponseAuthenticationMetaDataExtractorSymbol } from './pps/domain/authentication-metadata-extractor/pps-api-response-authentication-metadata-extractor.interface'; | ||
import { PPSApiResponseAuthenticationMetaDataExtractor } from './pps/domain/authentication-metadata-extractor/pps-api-response-authentication-metadata-extractor'; | ||
import { KeepAliveController } from './keep-alive/keep-alive.controller'; | ||
import { IRecaptchaCheckerSymbol } from '@pps-easy/recaptcha/contracts'; | ||
import { GoogleRecaptchaChecker, LocalRecaptchaChecker } from '@pps-easy/recaptcha/google'; | ||
import * as process from 'node:process'; | ||
import { RecaptchaController } from './recpatcha/recaptcha.controller'; | ||
import { RecaptchaGuard } from './guards/recaptcha.guard'; | ||
|
||
const isLocalEnvironment = process.env.ENVIRONMENT === 'local'; | ||
import { PPSModule } from './pps/pps.module'; | ||
import { SharedModule } from './shared/shared.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
HttpModule.register({ | ||
httpsAgent: new Agent({ | ||
rejectUnauthorized: false | ||
}), | ||
}), | ||
SharedModule, | ||
PPSModule, | ||
], | ||
controllers: [GenerateController, KeepAliveController, RecaptchaController], | ||
providers: [ | ||
{ provide: IPPSGenerateUseCaseSymbol, useClass: PPSGeneratorUseCase }, | ||
{ provide: IPPSApiSymbol, useClass: PPSApi, scope: Scope.REQUEST }, | ||
{ | ||
provide: IPPSApiResponseAuthenticationMetaDataExtractorSymbol, | ||
useClass: PPSApiResponseAuthenticationMetaDataExtractor, | ||
scope: Scope.REQUEST, | ||
}, | ||
{ | ||
provide: IHtmlParserSymbol, | ||
useClass: HtmlParser, | ||
}, | ||
{ | ||
provide: IRecaptchaCheckerSymbol, | ||
useValue: isLocalEnvironment ? | ||
new LocalRecaptchaChecker() : | ||
new GoogleRecaptchaChecker(process.env.RECAPTCHA_SITE_KEY || '', process.env.FIREBASE_PROJECT_ID || '') | ||
}, | ||
RecaptchaGuard | ||
], | ||
}) | ||
export class AppModule implements OnModuleInit { | ||
constructor(private httpService: HttpService) {} | ||
|
||
onModuleInit() { | ||
// Add request and response interceptors | ||
this.httpService.axiosRef.interceptors.request.use( | ||
(config) => { | ||
// Log request details | ||
console.log('Request:', { | ||
url: config.url, | ||
method: config.method, | ||
headers: config.headers, | ||
params: config.params, | ||
data: config.data, | ||
}); | ||
return config; | ||
}, | ||
error => { | ||
// Log error if any during request setup | ||
console.error('Request error:', error); | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
this.httpService.axiosRef.interceptors.response.use( | ||
response => { | ||
// Log response details | ||
console.log('Response:', { | ||
status: response.status, | ||
data: response.data, | ||
}); | ||
return response; | ||
}, | ||
error => { | ||
// Log response error details | ||
console.error('Response error:', { | ||
status: error.response?.status, | ||
data: error.response?.data, | ||
}); | ||
return Promise.reject(error); | ||
} | ||
); | ||
} | ||
} | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Module, Scope } from '@nestjs/common'; | ||
import { IPPSGenerateUseCaseSymbol } from './usecase/pps-generate-usecase.interface'; | ||
import { PPSGeneratorUseCase } from './usecase/pps-generator-usecase.service'; | ||
import { IPPSApiSymbol } from './third-party/pps-api.interface'; | ||
import { PPSApi } from './third-party/pps-api'; | ||
import { PPSApiFormDataGenerator } from './third-party/pps-api-form-data-generator'; | ||
import { Request } from 'express'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { StartStep } from './third-party/journey-steps/start-step'; | ||
import { RaceInformationStep } from './third-party/journey-steps/race-information-step'; | ||
import { PersonalInformationStep } from './third-party/journey-steps/personal-information-step'; | ||
import { CardiovascularStep } from './third-party/journey-steps/cardiovascular-step'; | ||
import { RiskFactorsStep } from './third-party/journey-steps/risk-factors-step'; | ||
import { PrecautionsStep } from './third-party/journey-steps/precautions-step'; | ||
import { FinalizationStep } from './third-party/journey-steps/finalization-step'; | ||
import { IPPSStepListSymbol } from './third-party/journey-steps/pps-step.interface'; | ||
import { | ||
IPPSApiResponseAuthenticationMetaDataExtractorSymbol | ||
} from './domain/authentication-metadata-extractor/pps-api-response-authentication-metadata-extractor.interface'; | ||
import { | ||
PPSApiResponseAuthenticationMetaDataExtractor | ||
} from './domain/authentication-metadata-extractor/pps-api-response-authentication-metadata-extractor'; | ||
import { SharedModule } from '../shared/shared.module'; | ||
import { PPSProfileDTOToRunnerPersonalInfos } from './domain/pps-profile-dto-to-runner-personal-infos'; | ||
|
||
@Module({ | ||
exports: [IPPSGenerateUseCaseSymbol], | ||
imports: [SharedModule], | ||
providers: [ | ||
{ | ||
provide: IPPSGenerateUseCaseSymbol, | ||
useClass: PPSGeneratorUseCase, | ||
scope: Scope.REQUEST, | ||
}, | ||
{ provide: IPPSApiSymbol, useClass: PPSApi, scope: Scope.REQUEST }, | ||
{ | ||
provide: PPSApiFormDataGenerator, | ||
useFactory: (request: Request) => | ||
new PPSApiFormDataGenerator(new PPSProfileDTOToRunnerPersonalInfos(request.body)), | ||
inject: [REQUEST], | ||
scope: Scope.REQUEST, | ||
}, | ||
StartStep, | ||
RaceInformationStep, | ||
PersonalInformationStep, | ||
CardiovascularStep, | ||
RiskFactorsStep, | ||
PrecautionsStep, | ||
FinalizationStep, | ||
{ | ||
provide: IPPSStepListSymbol, | ||
useFactory: ( | ||
startStep: StartStep, | ||
raceInformationStep: RaceInformationStep, | ||
personalInformationStep: PersonalInformationStep, | ||
cardiovascularStep: CardiovascularStep, | ||
riskFactorsStep: RiskFactorsStep, | ||
precautionsStep: PrecautionsStep, | ||
finalizationStep: FinalizationStep | ||
) => [ | ||
startStep, | ||
raceInformationStep, | ||
personalInformationStep, | ||
cardiovascularStep, | ||
riskFactorsStep, | ||
precautionsStep, | ||
finalizationStep, | ||
], | ||
inject: [ | ||
StartStep, | ||
RaceInformationStep, | ||
PersonalInformationStep, | ||
CardiovascularStep, | ||
RiskFactorsStep, | ||
PrecautionsStep, | ||
FinalizationStep, | ||
], | ||
}, | ||
{ | ||
provide: IPPSApiResponseAuthenticationMetaDataExtractorSymbol, | ||
useClass: PPSApiResponseAuthenticationMetaDataExtractor, | ||
scope: Scope.REQUEST, | ||
}, | ||
], | ||
}) | ||
export class PPSModule {} |
Oops, something went wrong.