fennec-be/src/projects/projects.resolver.ts
2021-07-18 22:40:33 +08:00

45 lines
1.3 KiB
TypeScript

import { AccountRole, Roles } from '@nestjs-lib/auth';
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
import { CreateProjectInput } from './dtos/create-project.input';
import { UpdateProjectInput } from './dtos/update-project.input';
import { Project } from './project.entity';
import { ProjectsService } from './projects.service';
@Roles(AccountRole.admin, AccountRole.super)
@Resolver(() => Project)
export class ProjectsResolver {
constructor(private readonly service: ProjectsService) {}
@Query(() => [Project])
async projects() {
return await this.service.list();
}
@Query(() => Project)
async project(@Args('id', { type: () => String }) id: string) {
return await this.service.findOne(id);
}
@Mutation(() => Project)
async createProject(
@Args('project', { type: () => CreateProjectInput })
dto: CreateProjectInput,
) {
return await this.service.create(dto);
}
@Mutation(() => Project)
async updateProject(
@Args('project', { type: () => UpdateProjectInput })
dto: UpdateProjectInput,
) {
const tmp = await this.service.update(dto);
console.log(tmp);
return tmp;
}
@Mutation(() => Number)
async removeProject(@Args('id', { type: () => String }) id: string) {
return await this.service.remove(id);
}
}