Skip to content

Commit d92e16d

Browse files
committed
feat: add responses payload for array types
1 parent e27dc19 commit d92e16d

8 files changed

+29
-8
lines changed

lib/filters/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './response.exception-filter'
1+
export * from './response.exception-filter'

lib/filters/response.exception-filter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export class ResponseFilter implements GqlExceptionFilter {
1818

1919
const { stack } = this._config
2020

21-
const stackMessage = stack === undefined || stack === true ? exception.stack : undefined
21+
const stackMessage =
22+
stack === undefined || stack === true ? exception.stack : undefined
2223

2324
this._logger.error(`${message} (${description})`, exception.stack)
2425

lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './filters'
22
export * from './interfaces'
3-
export * from './types'
3+
export * from './types'

lib/interfaces/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './response-error.interface'
22
export * from './response-payload.interface'
3-
export * from './response-filter-config.interface'
3+
export * from './response-filter-config.interface'
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export interface ResponseFilterConfig {
22
stack?: boolean
3-
}
3+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ResponseError } from "./response-error.interface"
1+
import { ResponseError } from './response-error.interface'
22

33
export interface ResponsePayload<T> {
4-
data?: T
4+
data?: T | T[]
55
error?: ResponseError
66
}

lib/types/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './response-error.type'
2-
export * from './response-payload.type'
2+
export * from './response-payload.type'

lib/types/responses-payload.type.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Type } from '@nestjs/common'
2+
import { Field, ObjectType } from '@nestjs/graphql'
3+
import { ResponseError } from '../interfaces/response-error.interface'
4+
import { ResponsePayload } from '../interfaces/response-payload.interface'
5+
import { ResponseErrorType } from './response-error.type'
6+
7+
export const ResponsePayloadType = <T>(
8+
classRef: Type<T>,
9+
): Type<ResponsePayload<T>> => {
10+
@ObjectType('ResponsesPayload', { isAbstract: true })
11+
class ResponsePayloadType implements ResponsePayload<T> {
12+
@Field(() => [classRef], { nullable: true })
13+
data?: T[]
14+
15+
@Field(() => ResponseErrorType, { nullable: true })
16+
error?: ResponseError
17+
}
18+
19+
return ResponsePayloadType
20+
}

0 commit comments

Comments
 (0)