Skip to content

Commit c050913

Browse files
committed
fix: eslint strict null check
1 parent a52fe2e commit c050913

File tree

6 files changed

+91
-90
lines changed

6 files changed

+91
-90
lines changed

src/common/middlewares/cache.middleware.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export class ClearCacheMiddleware implements NestMiddleware {
88
constructor(private readonly cacheService: CacheService) {}
99

1010
async use(request: NestifyRequest, _response: NestifyResponse, next: NestifyNextFunction) {
11-
12-
if(request.query?.clearCache === "true")
13-
await this.cacheService.resetCache()
11+
if (request.query?.clearCache === "true")
12+
await this.cacheService.resetCache();
1413

1514
next();
1615
}

src/entities/user.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class User extends BaseEntity {
114114

115115
o.avatar
116116
= this.avatar
117-
|| `https://ui-avatars.com/api/?name=${this.firstName}+${this.lastName}&background=0D8ABC&color=fff`;
117+
?? `https://ui-avatars.com/api/?name=${this.firstName}+${this.lastName}&background=0D8ABC&color=fff`;
118118

119119
return o;
120120
}

src/lib/aws/aws.s3.service.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export class AwsS3Service {
7979
}),
8080
)).pipe(
8181
map((response) => {
82-
if (response && response.Contents) {
82+
if (response != null && response.Contents) {
8383
return response.Contents.map((value) => {
84-
if (!value.Key)
84+
if (value.Key == null)
8585
return {};
8686
const lastIndex = value.Key.lastIndexOf("/");
8787
const path = value.Key.slice(0, lastIndex);
@@ -117,7 +117,7 @@ export class AwsS3Service {
117117
filename: string,
118118
path?: string,
119119
): Observable<Record<string, any>> {
120-
const key: string = path ? `${path}/${filename}` : filename;
120+
const key: string = path != null ? `${path}/${filename}` : filename;
121121
return from(this.s3Client.send(
122122
new GetObjectCommand({
123123
Bucket: this.bucket,
@@ -254,7 +254,7 @@ export class AwsS3Service {
254254

255255
return listObjectsObservable.pipe(
256256
map((lists) => {
257-
if (!lists || !lists?.Contents)
257+
if (lists == null || lists?.Contents == null)
258258
return [];
259259

260260
return lists.Contents.map(value => ({
@@ -369,10 +369,12 @@ export class AwsS3Service {
369369
): Observable<any> {
370370
let path = options?.path ?? undefined;
371371

372-
if (path)
372+
// TODO: handle for path null
373+
374+
if (path != null)
373375
path = path.startsWith("/") ? path.replace("/", "") : `${path}`;
374376

375-
const key = path ? `${path}/${fileName}` : fileName;
377+
const key = path != null ? `${path}/${fileName}` : fileName;
376378

377379
return from(this.s3Client.send(
378380
new UploadPartCommand({

src/lib/firebase-admin/firebase.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class NestFirebaseService implements NestFirebase {
2323
if (!existsSync(filePath))
2424
throw new Error(`Unknown file ${filePath}`);
2525

26-
if (this._firebaseConnection == null) {
26+
if (this._firebaseConnection == null) {
2727
try {
2828
this._firebaseConnection = admin.initializeApp({
2929
credential: admin.credential.cert(filePath),

src/lib/minio.module.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { NestMinioModule } from "nestjs-minio";
99
inject: [ConfigService],
1010
isGlobal: true,
1111
useFactory: async (configService: ConfigService) => ({
12-
endPoint: configService.get("minio.host","localhost"),
13-
port: configService.get("minio.port",9000),
14-
accessKey: configService.get("minio.accessKey","minio") ,
15-
secretKey: configService.get("minio.secretKey","minio") ,
16-
useSSL: configService.get("minio.ssl",false),
12+
endPoint: configService.get("minio.host", "localhost"),
13+
port: configService.get("minio.port", 9000),
14+
accessKey: configService.get("minio.accessKey", "minio"),
15+
secretKey: configService.get("minio.secretKey", "minio"),
16+
useSSL: configService.get("minio.ssl", false),
1717
}),
1818
}),
1919
],

src/lib/pino/pino.module.ts

+74-74
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,89 @@ const basePinoOptions = {
1313
@Module({
1414
imports: [
1515
LoggerModule.forRoot({
16-
pinoHttp: {
17-
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
18-
name: "ultimate-nest",
19-
customProps: () => ({
20-
context: "HTTP",
21-
}),
22-
serializers: {
23-
req(request: {
16+
pinoHttp: {
17+
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
18+
name: "ultimate-nest",
19+
customProps: () => ({
20+
context: "HTTP",
21+
}),
22+
serializers: {
23+
req(request: {
24+
body: Record<string, any>;
25+
raw: {
2426
body: Record<string, any>;
25-
raw: {
26-
body: Record<string, any>;
27-
};
28-
}) {
29-
request.body = request.raw.body;
27+
};
28+
}) {
29+
request.body = request.raw.body;
3030

31-
return request;
32-
},
33-
},
34-
redact: {
35-
paths: redactFields,
36-
censor: "**GDPR COMPLIANT**",
31+
return request;
3732
},
38-
transport: true
39-
? {
40-
targets: [
41-
{
42-
target: "pino/file",
43-
level: "info", // log only errors to file
44-
options: {
45-
...basePinoOptions,
46-
destination: "logs/info.log",
47-
mkdir: true,
48-
sync: false,
49-
},
33+
},
34+
redact: {
35+
paths: redactFields,
36+
censor: "**GDPR COMPLIANT**",
37+
},
38+
transport: true
39+
? {
40+
targets: [
41+
{
42+
target: "pino/file",
43+
level: "info", // log only errors to file
44+
options: {
45+
...basePinoOptions,
46+
destination: "logs/info.log",
47+
mkdir: true,
48+
sync: false,
5049
},
51-
{
52-
target: "pino/file",
53-
level: "error", // log only errors to file
54-
options: {
55-
...basePinoOptions,
56-
destination: "logs/error.log",
57-
mkdir: true,
58-
sync: false,
59-
},
50+
},
51+
{
52+
target: "pino/file",
53+
level: "error", // log only errors to file
54+
options: {
55+
...basePinoOptions,
56+
destination: "logs/error.log",
57+
mkdir: true,
58+
sync: false,
6059
},
61-
],
62-
}
63-
: {
64-
targets: [
65-
{
66-
target: "pino-pretty",
67-
level: "info", // log only info and above to console
68-
options: {
69-
...basePinoOptions,
70-
colorize: true,
71-
},
60+
},
61+
],
62+
}
63+
: {
64+
targets: [
65+
{
66+
target: "pino-pretty",
67+
level: "info", // log only info and above to console
68+
options: {
69+
...basePinoOptions,
70+
colorize: true,
7271
},
73-
{
74-
target: "pino/file",
75-
level: "info", // log only errors to file
76-
options: {
77-
...basePinoOptions,
78-
destination: "logs/info.log",
79-
mkdir: true,
80-
sync: false,
81-
},
72+
},
73+
{
74+
target: "pino/file",
75+
level: "info", // log only errors to file
76+
options: {
77+
...basePinoOptions,
78+
destination: "logs/info.log",
79+
mkdir: true,
80+
sync: false,
8281
},
83-
{
84-
target: "pino/file",
85-
level: "error", // log only errors to file
86-
options: {
87-
...basePinoOptions,
88-
destination: "logs/error.log",
89-
mkdir: true,
90-
sync: false,
91-
},
82+
},
83+
{
84+
target: "pino/file",
85+
level: "error", // log only errors to file
86+
options: {
87+
...basePinoOptions,
88+
destination: "logs/error.log",
89+
mkdir: true,
90+
sync: false,
9291
},
93-
],
94-
},
95-
},
96-
exclude: [{ method: RequestMethod.ALL, path: "doc" }],
92+
},
93+
],
94+
},
95+
},
96+
exclude: [{ method: RequestMethod.ALL, path: "doc" }],
9797

98-
}),
98+
}),
9999
],
100100
exports: [LoggerModule],
101101
})

0 commit comments

Comments
 (0)