fennec-be/src/repos/repos.resolver.ts
2021-02-28 21:51:52 +08:00

38 lines
1.3 KiB
TypeScript

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<BranchList> {
return await this.service.listBranches(dto).then((data) => {
return {
...data,
branches: Object.values(data.branches),
};
});
}
@Mutation(() => Boolean)
async checkout(@Args('checkoutInput') dto: CheckoutInput): Promise<true> {
const project = await this.projectService.findOne(dto.projectId);
await this.service.checkoutCommit(project, dto.commitNumber);
return true;
}
}