channel.resolver.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
  2. import {
  3. ChannelQueryArgs,
  4. CreateChannelMutationArgs,
  5. Permission,
  6. UpdateChannelMutationArgs,
  7. } from 'shared/generated-types';
  8. import { Channel } from '../../entity/channel/channel.entity';
  9. import { ChannelService } from '../../service/providers/channel.service';
  10. import { Allow } from '../common/auth-guard';
  11. import { Decode } from '../common/id-interceptor';
  12. import { RequestContext } from '../common/request-context';
  13. import { Ctx } from '../common/request-context.decorator';
  14. @Resolver('Channel')
  15. export class ChannelResolver {
  16. constructor(private channelService: ChannelService) {}
  17. @Query()
  18. @Allow(Permission.SuperAdmin)
  19. channels(@Ctx() ctx: RequestContext): Promise<Channel[]> {
  20. return this.channelService.findAll();
  21. }
  22. @Query()
  23. @Allow(Permission.SuperAdmin)
  24. async channel(@Ctx() ctx: RequestContext, @Args() args: ChannelQueryArgs): Promise<Channel | undefined> {
  25. return this.channelService.findOne(args.id);
  26. }
  27. @Mutation()
  28. @Allow(Permission.SuperAdmin)
  29. @Decode('defaultTaxZoneId', 'defaultShippingZoneId')
  30. async createChannel(@Args() args: CreateChannelMutationArgs): Promise<Channel> {
  31. return this.channelService.create(args.input);
  32. }
  33. @Mutation()
  34. @Allow(Permission.SuperAdmin)
  35. @Decode('defaultTaxZoneId', 'defaultShippingZoneId')
  36. async updateChannel(@Args() args: UpdateChannelMutationArgs): Promise<Channel> {
  37. return this.channelService.update(args.input);
  38. }
  39. }