adjustment-source.resolver.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
  2. import {
  3. AdjustmentOperationsQueryArgs,
  4. AdjustmentSourceQueryArgs,
  5. AdjustmentSourcesQueryArgs,
  6. CreateAdjustmentSourceMutationArgs,
  7. Permission,
  8. UpdateAdjustmentSourceMutationArgs,
  9. } from 'shared/generated-types';
  10. import { PaginatedList } from 'shared/shared-types';
  11. import { AdjustmentSource } from '../../entity/adjustment-source/adjustment-source.entity';
  12. import { Order } from '../../entity/order/order.entity';
  13. import { AdjustmentSourceService } from '../../service/providers/adjustment-source.service';
  14. import { Allow } from '../common/auth-guard';
  15. import { RequestContext } from '../common/request-context';
  16. import { Ctx } from '../common/request-context.decorator';
  17. @Resolver('Order')
  18. export class AdjustmentSourceResolver {
  19. constructor(private adjustmentSourceService: AdjustmentSourceService) {}
  20. @Query()
  21. @Allow(Permission.ReadAdjustmentSource)
  22. adjustmentSources(
  23. @Ctx() ctx: RequestContext,
  24. @Args() args: AdjustmentSourcesQueryArgs,
  25. ): Promise<PaginatedList<AdjustmentSource>> {
  26. if (!args.options) {
  27. args.options = {};
  28. }
  29. if (!args.options.filter) {
  30. args.options.filter = {};
  31. }
  32. args.options.filter.type = {
  33. eq: args.type,
  34. };
  35. return this.adjustmentSourceService.findAll(args.options || undefined);
  36. }
  37. @Query()
  38. @Allow(Permission.ReadAdjustmentSource)
  39. adjustmentSource(
  40. @Ctx() ctx: RequestContext,
  41. @Args() args: AdjustmentSourceQueryArgs,
  42. ): Promise<AdjustmentSource | undefined> {
  43. return this.adjustmentSourceService.findOne(args.id);
  44. }
  45. @Query()
  46. @Allow(Permission.ReadAdjustmentSource)
  47. adjustmentOperations(@Ctx() ctx: RequestContext, @Args() args: AdjustmentOperationsQueryArgs) {
  48. return this.adjustmentSourceService.getAdjustmentOperations(args.type);
  49. }
  50. @Mutation()
  51. @Allow(Permission.CreateAdjustmentSource)
  52. createAdjustmentSource(
  53. @Ctx() ctx: RequestContext,
  54. @Args() args: CreateAdjustmentSourceMutationArgs,
  55. ): Promise<AdjustmentSource> {
  56. return this.adjustmentSourceService.createAdjustmentSource(ctx, args.input);
  57. }
  58. @Mutation()
  59. @Allow(Permission.UpdateAdjustmentSource)
  60. updateAdjustmentSource(
  61. @Ctx() ctx: RequestContext,
  62. @Args() args: UpdateAdjustmentSourceMutationArgs,
  63. ): Promise<AdjustmentSource> {
  64. return this.adjustmentSourceService.updateAdjustmentSource(ctx, args.input);
  65. }
  66. }