fix when quering without page params

This commit is contained in:
João Geonizeli
2022-09-09 18:39:33 -03:00
parent df244377d8
commit 83ebd2933f

View File

@@ -1,7 +1,7 @@
import { HttpService } from '@nestjs/axios';
import { Args, Query, Resolver } from '@nestjs/graphql';
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
import * as camelcase from 'camelcase-object-deep';
import { firstValueFrom, lastValueFrom, map } from 'rxjs';
import { firstValueFrom } from 'rxjs';
import { ThingsArgs } from './dto/things.args';
import { Thing } from './thing.model';
@@ -12,8 +12,8 @@ export class ThingResolver {
@Query(() => [Thing])
async things(@Args() args: ThingsArgs): Promise<Thing[]> {
const params = new URLSearchParams({
page: args.page.toString(),
per_page: args.perPage.toString(),
page: args.page?.toString(),
per_page: args.perPage?.toString(),
sort: args.sort,
posted_after: args.postedAfter,
type: 'trings',
@@ -21,22 +21,18 @@ export class ThingResolver {
const queryStirng = `/search?${params.toString()}`;
this.httpService.axiosRef.interceptors.response.use((response) => {
response.data = camelcase(response);
return response;
});
type Response = {
data: {
try {
const { data: response } = await firstValueFrom(
this.httpService.get<{
hits: Thing[];
total: number;
}
}
const { data: response } = await firstValueFrom(
this.httpService.get<Response>(queryStirng),
}>(queryStirng),
);
return response.data.hits
return camelcase(response.hits || []);
} catch (error) {
return [];
}
}
@Query(() => Thing)