44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
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';
|
|
|
|
@Resolver(() => Project)
|
|
export class ProjectsResolver {
|
|
constructor(private readonly service: ProjectsService) {}
|
|
@Query(() => [Project])
|
|
async findProjects() {
|
|
return await this.service.list();
|
|
}
|
|
|
|
@Query(() => Project)
|
|
async findProject(@Args('id', { type: () => String }) id: string) {
|
|
return await this.service.findOne(id);
|
|
}
|
|
|
|
@Mutation(() => Project)
|
|
async createProject(
|
|
@Args('project', { type: () => CreateProjectInput })
|
|
dto: UpdateProjectInput,
|
|
) {
|
|
return await this.service.create(dto);
|
|
}
|
|
|
|
@Mutation(() => Project)
|
|
async modifyProject(
|
|
@Args('id', { type: () => String }) id: string,
|
|
@Args('project', { type: () => UpdateProjectInput })
|
|
dto: UpdateProjectInput,
|
|
) {
|
|
const tmp = await this.service.update(id, dto);
|
|
console.log(tmp);
|
|
return tmp;
|
|
}
|
|
|
|
@Mutation(() => Number)
|
|
async deleteProject(@Args('id', { type: () => String }) id: string) {
|
|
return await this.service.remove(id);
|
|
}
|
|
}
|