import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; import { ListLogsArgs } from './dtos/list-logs.args'; import { ReposService } from './repos.service'; import { LogList } from './dtos/log-list.model'; import { ListBranchesArgs } from './dtos/list-branches.args'; import { BranchList } from './dtos/branch-list.model'; import { CheckoutInput } from './dtos/checkout.input'; import { ProjectsService } from '../projects/projects.service'; @Resolver() export class ReposResolver { constructor( private readonly service: ReposService, private readonly projectService: ProjectsService, ) {} @Query(() => LogList) async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) { return await this.service.listLogs(dto); } @Query(() => BranchList) async listBranches( @Args('listBranchesArgs') dto: ListBranchesArgs, ): Promise { return await this.service.listBranches(dto).then((data) => { return { ...data, branches: Object.values(data.branches), }; }); } @Mutation(() => Boolean) async checkout(@Args('checkoutInput') dto: CheckoutInput): Promise { const project = await this.projectService.findOne(dto.projectId); await this.service.checkoutCommit(project, dto.commitNumber); return true; } }