diff --git a/src/decorator.spec.ts b/src/decorator.spec.ts index f22499b..e84ba05 100644 --- a/src/decorator.spec.ts +++ b/src/decorator.spec.ts @@ -41,6 +41,7 @@ function fastifyContextFactory(query: FastifyRequest['query']): Partial { + return data !== null && typeof data === 'object' && !Array.isArray(data) +} + +function isExpressRequest(request: unknown): request is ExpressRequest { + return isRecord(request) && typeof request.get === 'function' +} + export interface PaginateQuery { page?: number limit?: number @@ -41,12 +50,12 @@ function parseParam(queryParam: unknown, parserLogic: (param: string, res: an } export const Paginate = createParamDecorator((_data: unknown, ctx: ExecutionContext): PaginateQuery => { - const request: Request = ctx.switchToHttp().getRequest() - const { query } = request + const request: ExpressRequest | FastifyRequest = ctx.switchToHttp().getRequest() + const query = request.query as Record // Determine if Express or Fastify to rebuild the original url and reduce down to protocol, host and base url - let originalUrl: any - if (request.originalUrl) { + let originalUrl: string + if (isExpressRequest(request)) { originalUrl = request.protocol + '://' + request.get('host') + request.originalUrl } else { originalUrl = request.protocol + '://' + request.hostname + request.url