From a52fe2ec4305696ae437c3f36c0e0676af15b20a Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Tue, 27 Aug 2024 22:55:40 +0545 Subject: [PATCH] fix: eslint strict null check --- .../validation/validation-field.generator.ts | 2 +- src/common/helpers/helpers.utils.ts | 2 +- src/common/middlewares/cache.middleware.ts | 5 ++++- src/common/middlewares/request-id.middleware.ts | 2 +- src/lib/crud/crud.controller.ts | 2 +- src/lib/firebase-admin/firebase.service.ts | 2 +- src/lib/minio.module.ts | 10 +++++----- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/common/decorators/validation/validation-field.generator.ts b/src/common/decorators/validation/validation-field.generator.ts index 721630a1..d296c7e7 100644 --- a/src/common/decorators/validation/validation-field.generator.ts +++ b/src/common/decorators/validation/validation-field.generator.ts @@ -75,7 +75,7 @@ export class ValidatorFieldBuilder { } addMinMaxLength() { - if (this.options.minLength && this.options.maxLength) { + if (this.options?.minLength != null && this.options?.maxLength != null) { MinMaxLength({ minLength: this.options.minLength, maxLength: this.options.maxLength, diff --git a/src/common/helpers/helpers.utils.ts b/src/common/helpers/helpers.utils.ts index 4c83d18b..ab84f98a 100644 --- a/src/common/helpers/helpers.utils.ts +++ b/src/common/helpers/helpers.utils.ts @@ -32,7 +32,7 @@ export const HelperService = { ...pick(user, ["id", "idx"]), }, accessToken, - ...(refreshToken ? { refresh_token: refreshToken } : {}), + ...(refreshToken != null ? { refresh_token: refreshToken } : {}), }; }, diff --git a/src/common/middlewares/cache.middleware.ts b/src/common/middlewares/cache.middleware.ts index 321073d2..d7952ebc 100644 --- a/src/common/middlewares/cache.middleware.ts +++ b/src/common/middlewares/cache.middleware.ts @@ -8,7 +8,10 @@ export class ClearCacheMiddleware implements NestMiddleware { constructor(private readonly cacheService: CacheService) {} async use(request: NestifyRequest, _response: NestifyResponse, next: NestifyNextFunction) { - request.query?.clearCache === "true" && (await this.cacheService.resetCache()); + + if(request.query?.clearCache === "true") + await this.cacheService.resetCache() + next(); } } diff --git a/src/common/middlewares/request-id.middleware.ts b/src/common/middlewares/request-id.middleware.ts index 0d4dd07a..6025219e 100644 --- a/src/common/middlewares/request-id.middleware.ts +++ b/src/common/middlewares/request-id.middleware.ts @@ -4,7 +4,7 @@ import { REQUEST_ID_TOKEN_HEADER } from "@common/constant"; export function RequestIdMiddleware(request: NestifyRequest, response: NestifyResponse, next: NestifyNextFunction) { const requestId = request.header(REQUEST_ID_TOKEN_HEADER); - if (!request.headers[REQUEST_ID_TOKEN_HEADER] || (requestId && !isCuid(requestId))) + if (request.headers[REQUEST_ID_TOKEN_HEADER] == null || (requestId != null && !isCuid(requestId))) request.headers[REQUEST_ID_TOKEN_HEADER] = createId(); response.set(REQUEST_ID_TOKEN_HEADER, request.headers[REQUEST_ID_TOKEN_HEADER]); diff --git a/src/lib/crud/crud.controller.ts b/src/lib/crud/crud.controller.ts index c3ef8609..ceb7ebb9 100644 --- a/src/lib/crud/crud.controller.ts +++ b/src/lib/crud/crud.controller.ts @@ -17,7 +17,7 @@ export class AbstractValidationPipe extends ValidationPipe { async transform(value: any, metadata: ArgumentMetadata) { const targetType = this.targetTypes[metadata.type] as Type; - if (!targetType) + if (targetType == null) return super.transform(value, metadata); return super.transform(value, { ...metadata, metatype: targetType }); diff --git a/src/lib/firebase-admin/firebase.service.ts b/src/lib/firebase-admin/firebase.service.ts index f3dc5251..4ca2a0be 100644 --- a/src/lib/firebase-admin/firebase.service.ts +++ b/src/lib/firebase-admin/firebase.service.ts @@ -23,7 +23,7 @@ export class NestFirebaseService implements NestFirebase { if (!existsSync(filePath)) throw new Error(`Unknown file ${filePath}`); - if (!this._firebaseConnection) { + if (this._firebaseConnection == null) { try { this._firebaseConnection = admin.initializeApp({ credential: admin.credential.cert(filePath), diff --git a/src/lib/minio.module.ts b/src/lib/minio.module.ts index f169a920..9daaff33 100644 --- a/src/lib/minio.module.ts +++ b/src/lib/minio.module.ts @@ -9,11 +9,11 @@ import { NestMinioModule } from "nestjs-minio"; inject: [ConfigService], isGlobal: true, useFactory: async (configService: ConfigService) => ({ - endPoint: configService.get("minio.host") || "localhost", - port: configService.get("minio.port") || 9000, - accessKey: configService.get("minio.accessKey") || "minio", - secretKey: configService.get("minio.secretKey") || "minio", - useSSL: configService.get("minio.ssl"), + endPoint: configService.get("minio.host","localhost"), + port: configService.get("minio.port",9000), + accessKey: configService.get("minio.accessKey","minio") , + secretKey: configService.get("minio.secretKey","minio") , + useSSL: configService.get("minio.ssl",false), }), }), ],