fix when quering without page params
This commit is contained in:
@@ -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;
|
||||
});
|
||||
try {
|
||||
const { data: response } = await firstValueFrom(
|
||||
this.httpService.get<{
|
||||
hits: Thing[];
|
||||
total: number;
|
||||
}>(queryStirng),
|
||||
);
|
||||
|
||||
type Response = {
|
||||
data: {
|
||||
hits: Thing[];
|
||||
total: number;
|
||||
}
|
||||
return camelcase(response.hits || []);
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
const { data: response } = await firstValueFrom(
|
||||
this.httpService.get<Response>(queryStirng),
|
||||
);
|
||||
|
||||
return response.data.hits
|
||||
}
|
||||
|
||||
@Query(() => Thing)
|
||||
|
||||
Reference in New Issue
Block a user