All files / src/modules/agencies agencies.resolver.ts

82.75% Statements 24/29
56.25% Branches 9/16
61.53% Functions 8/13
80% Lines 20/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 5211x 11x 11x 11x 11x 11x 11x 11x     11x 11x   22x   11x       22x   11x       22x 11x       22x 11x       22x     11x                          
import { Resolver, Query, Mutation, Args, Int } from '@nestjs/graphql';
import { UseGuards } from '@nestjs/common';
import { GqlAuthGuard } from '@app/common/guards/gql-auth.guard';
import { RolesGuard } from '@app/common/guards/roles.guard';
import { Roles } from '@app/common/decorators/roles.decorator';
import { CurrentUser } from '@app/common/decorators/current-user.decorator';
import { AgenciesService } from '@app/modules/agencies/agencies.service';
import { User } from '@prisma/client';
 
@Resolver()
export class AgenciesResolver {
  constructor(private readonly agencies: AgenciesService) {}
 
  @Query(() => [String], { name: 'myAgencyApplications', description: 'List my agency applications' })
  @UseGuards(GqlAuthGuard)
  myAgencyApplications(@CurrentUser() user: User) {
    return this.agencies.getMyApplications(user);
  }
 
  @Query(() => String, { name: 'myAgency', description: 'Get my agency profile' })
  @UseGuards(GqlAuthGuard)
  myAgency(@CurrentUser() user: User) {
    return this.agencies.getMyAgency(user);
  }
 
  @Query(() => String, { name: 'agency', description: 'Get an agency by ID' })
  agency(@Args('id', { type: () => Int }) id: number) {
    return this.agencies.getAgencyById(id);
  }
 
  @Query(() => [String], { name: 'agencyAgents', description: 'List agents for an agency' })
  agencyAgents(@Args('id', { type: () => Int }) id: number) {
    return this.agencies.getAgencyAgents(id);
  }
 
  @Mutation(() => String)
  @UseGuards(GqlAuthGuard, RolesGuard)
  @Roles('AGENT')
  requestAgencyUpdate(
    @CurrentUser() user: User,
    @Args('name', { nullable: true }) name?: string,
    @Args('description', { nullable: true }) description?: string,
    @Args('logoUrl', { nullable: true }) logoUrl?: string,
    @Args('phone', { nullable: true }) phone?: string,
    @Args('address', { nullable: true }) address?: string,
  ) {
    return this.agencies.updateAgencyProfile(user, { name, description, logoUrl, phone, address });
  }
}