Skip to content

Commit c5b5541

Browse files
fix(response-body): fix counting issue in response body (#66)
* fix(response-body): fix counting issue in response body * fix(response-body): attach pagination meta data to data object
1 parent fc044b1 commit c5b5541

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/interceptor/response.interceptor.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ export class ResponseInterceptor<T> implements NestInterceptor<T, IResponse<T>>
2020
context.getHandler()
2121
);
2222
return next.handle().pipe(
23-
map((data: T) => ({
24-
data,
25-
count: Array.isArray(data) ? data.length : data ? 1 : 0,
26-
message: custom_message || 'Success',
27-
}))
23+
map((response_body) => {
24+
const data = response_body.data ?? response_body;
25+
26+
return {
27+
data: response_body,
28+
count: Array.isArray(data) ? data.length : data ? 1 : 0,
29+
30+
message: custom_message || 'Success',
31+
};
32+
})
2833
);
2934
}
3035
}

0 commit comments

Comments
 (0)