user.resolver.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Args, Parent, ResolveField, Resolver } from '@nestjs/graphql';
  2. import { User } from '../user/user.model';
  3. import { UserHistoryService } from './user-history.service';
  4. import { UserHistory } from './user-history.model';
  5. import { ReqType } from 'src/types/RequestTypes';
  6. import { PaginationArgs } from '../types/input-types.args';
  7. @Resolver(() => User)
  8. export class UserHistoryUserResolver {
  9. constructor(private userHistoryService: UserHistoryService) {}
  10. @ResolveField(() => [UserHistory], {
  11. description: 'Returns a users REST history',
  12. })
  13. async RESTHistory(
  14. @Parent() user: User,
  15. @Args() args: PaginationArgs,
  16. ): Promise<UserHistory[]> {
  17. return await this.userHistoryService.fetchUserHistory(
  18. user.uid,
  19. args.take,
  20. ReqType.REST,
  21. );
  22. }
  23. @ResolveField(() => [UserHistory], {
  24. description: 'Returns a users GraphQL history',
  25. })
  26. async GQLHistory(
  27. @Parent() user: User,
  28. @Args() args: PaginationArgs,
  29. ): Promise<UserHistory[]> {
  30. return await this.userHistoryService.fetchUserHistory(
  31. user.uid,
  32. args.take,
  33. ReqType.GQL,
  34. );
  35. }
  36. }