Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Refactor requests and responses (#1507)

Thomas Kaul2a605f850d0a
diff --git a/apps/api/src/app/auth/auth.controller.ts b/apps/api/src/app/auth/auth.controller.ts
index 749f6f0375..08d1c1a31e 100644
--- a/apps/api/src/app/auth/auth.controller.ts
+++ b/apps/api/src/app/auth/auth.controller.ts
@@ -16,6 +16,7 @@ import {
Version
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
+import { Request, Response } from 'express';
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { AuthService } from './auth.service';
@@ -58,18 +59,21 @@ export class AuthController {
@Get('google/callback')
@UseGuards(AuthGuard('google'))
@Version(VERSION_NEUTRAL)
- public googleLoginCallback(@Req() req, @Res() res) {
+ public googleLoginCallback(
+ @Req() request: Request,
+ @Res() response: Response
+ ) {
// Handles the Google OAuth2 callback
- const jwt: string = req.user.jwt;
+ const jwt: string = (<any>request.user).jwt;
if (jwt) {
- res.redirect(
+ response.redirect(
`${this.configurationService.get(
'ROOT_URL'
)}/${DEFAULT_LANGUAGE_CODE}/auth/${jwt}`
);
} else {
- res.redirect(
+ response.redirect(
`${this.configurationService.get(
'ROOT_URL'
)}/${DEFAULT_LANGUAGE_CODE}/auth`
diff --git a/apps/api/src/app/frontend.middleware.ts b/apps/api/src/app/frontend.middleware.ts
index dde9a0b324..41238fdec0 100644
--- a/apps/api/src/app/frontend.middleware.ts
+++ b/apps/api/src/app/frontend.middleware.ts
@@ -50,66 +50,66 @@ export class FrontendMiddleware implements NestMiddleware {
} catch {}
}
- public use(req: Request, res: Response, next: NextFunction) {
+ public use(request: Request, response: Response, next: NextFunction) {
let featureGraphicPath = 'assets/cover.png';
- if (req.path.startsWith('/en/blog/2022/08/500-stars-on-github')) {
+ if (request.path.startsWith('/en/blog/2022/08/500-stars-on-github')) {
featureGraphicPath = 'assets/images/blog/500-stars-on-github.jpg';
- } else if (req.path.startsWith('/en/blog/2022/10/hacktoberfest-2022')) {
+ } else if (request.path.startsWith('/en/blog/2022/10/hacktoberfest-2022')) {
featureGraphicPath = 'assets/images/blog/hacktoberfest-2022.png';
- } else if (req.path.startsWith('/en/blog/2022/11/black-friday-2022')) {
+ } else if (request.path.startsWith('/en/blog/2022/11/black-friday-2022')) {
featureGraphicPath = 'assets/images/blog/black-friday-2022.jpg';
}
if (
- req.path.startsWith('/api/') ||
- this.isFileRequest(req.url) ||
+ request.path.startsWith('/api/') ||
+ this.isFileRequest(request.url) ||
!this.isProduction
) {
// Skip
next();
- } else if (req.path === '/de' || req.path.startsWith('/de/')) {
- res.send(
+ } else if (request.path === '/de' || request.path.startsWith('/de/')) {
+ response.send(
this.interpolate(this.indexHtmlDe, {
featureGraphicPath,
languageCode: 'de',
- path: req.path,
+ path: request.path,
rootUrl: this.configurationService.get('ROOT_URL')
})
);
- } else if (req.path === '/es' || req.path.startsWith('/es/')) {
- res.send(
+ } else if (request.path === '/es' || request.path.startsWith('/es/')) {
+ response.send(
this.interpolate(this.indexHtmlEs, {
featureGraphicPath,
languageCode: 'es',
- path: req.path,
+ path: request.path,
rootUrl: this.configurationService.get('ROOT_URL')
})
);
- } else if (req.path === '/it' || req.path.startsWith('/it/')) {
- res.send(
+ } else if (request.path === '/it' || request.path.startsWith('/it/')) {
+ response.send(
this.interpolate(this.indexHtmlIt, {
featureGraphicPath,
languageCode: 'it',
- path: req.path,
+ path: request.path,
rootUrl: this.configurationService.get('ROOT_URL')
})
);
- } else if (req.path === '/nl' || req.path.startsWith('/nl/')) {
- res.send(
+ } else if (request.path === '/nl' || request.path.startsWith('/nl/')) {
+ response.send(
this.interpolate(this.indexHtmlNl, {
featureGraphicPath,
languageCode: 'nl',
- path: req.path,
+ path: request.path,
rootUrl: this.configurationService.get('ROOT_URL')
})
);
} else {
- res.send(
+ response.send(
this.interpolate(this.indexHtmlEn, {
featureGraphicPath,
languageCode: DEFAULT_LANGUAGE_CODE,
- path: req.path,
+ path: request.path,
rootUrl: this.configurationService.get('ROOT_URL')
})
);
diff --git a/apps/api/src/app/subscription/subscription.controller.ts b/apps/api/src/app/subscription/subscription.controller.ts
index 70317fe764..eee8156521 100644
--- a/apps/api/src/app/subscription/subscription.controller.ts
+++ b/apps/api/src/app/subscription/subscription.controller.ts
@@ -21,6 +21,7 @@ import {
} from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
+import { Request, Response } from 'express';
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { SubscriptionService } from './subscription.service';
@@ -86,9 +87,12 @@ export class SubscriptionController {
}
@Get('stripe/callback')
- public async stripeCallback(@Req() req, @Res() res) {
+ public async stripeCallback(
+ @Req() request: Request,
+ @Res() response: Response
+ ) {
const userId = await this.subscriptionService.createSubscriptionViaStripe(
- req.query.checkoutSessionId
+ <string>request.query.checkoutSessionId
);
Logger.log(
@@ -96,7 +100,7 @@ export class SubscriptionController {
'SubscriptionController'
);
- res.redirect(
+ response.redirect(
`${this.configurationService.get(
'ROOT_URL'
)}/${DEFAULT_LANGUAGE_CODE}/account`