Skip to content

Commit

Permalink
fix(nestjs): ensure mapper is safe for accessing with optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jan 29, 2021
1 parent 7ec5110 commit 83307f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/nestjs/src/lib/interceptors/map.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function createMapInterceptor(

class MixinMapInterceptor implements NestInterceptor {
constructor(
@Optional() @InjectMapper(mapperName) private readonly mapper: Mapper
@Optional() @InjectMapper(mapperName) private readonly mapper?: Mapper
) {}

async intercept(
Expand All @@ -43,7 +43,7 @@ function createMapInterceptor(
map((response) => {
if (isArray) {
if (!Array.isArray(response)) return response;
return this.mapper.mapArray(
return this.mapper?.mapArray(
response,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
to as any,
Expand All @@ -53,7 +53,7 @@ function createMapInterceptor(
);
}

return this.mapper.map(
return this.mapper?.map(
response,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
to as any,
Expand Down

0 comments on commit 83307f5

Please sign in to comment.