|
| 1 | +// GraphQL Resolvers for Project APIs |
| 2 | +import { |
| 3 | + Args, |
| 4 | + Field, |
| 5 | + Mutation, |
| 6 | + ObjectType, |
| 7 | + Query, |
| 8 | + Resolver, |
| 9 | +} from '@nestjs/graphql'; |
| 10 | +import { ProjectsService } from './project.service'; |
| 11 | +import { ProjectPackagesService } from './project-packages.service'; |
| 12 | +import { Projects } from './project.model'; |
| 13 | +import { ProjectPackages } from './project-packages.model'; |
| 14 | +import { UpsertProjectInput } from './dto/project.input'; |
| 15 | + |
| 16 | +@Resolver(() => Projects) |
| 17 | +export class ProjectsResolver { |
| 18 | + constructor( |
| 19 | + private readonly projectsService: ProjectsService, |
| 20 | + private readonly projectPackagesService: ProjectPackagesService |
| 21 | + ) {} |
| 22 | + |
| 23 | + // -------- All the code need to extract the user id from the token and verify is the project user's or not |
| 24 | + // add @GetAuthToken() token: string after test |
| 25 | + @Query(() => [Projects]) |
| 26 | + async getUserProjects(@Args('userId') userId: string): Promise<Projects[]> { |
| 27 | + // if (userId != token.id) return 401 |
| 28 | + |
| 29 | + return this.projectsService.getProjectsByUser(userId); |
| 30 | + } |
| 31 | + |
| 32 | + // @GetAuthToken() token: string |
| 33 | + @Query(() => Projects) |
| 34 | + async getProjectDetails(@Args('projectId') projectId: string): Promise<Projects> { |
| 35 | + return this.projectsService.getProjectById(projectId); |
| 36 | + } |
| 37 | + |
| 38 | + // @GetAuthToken() token: string |
| 39 | + @Mutation(() => Projects) |
| 40 | + async upsertProject( |
| 41 | + @Args('upsertProjectInput') upsertProjectInput: UpsertProjectInput |
| 42 | + ): Promise<Projects> { |
| 43 | + return this.projectsService.upsertProject(upsertProjectInput); |
| 44 | + } |
| 45 | + |
| 46 | + // @GetAuthToken() token: string |
| 47 | + @Mutation(() => Boolean) |
| 48 | + async deleteProject(@Args('projectId') projectId: string): Promise<boolean> { |
| 49 | + return this.projectsService.deleteProject(projectId); |
| 50 | + } |
| 51 | + |
| 52 | + // @GetAuthToken() token: string |
| 53 | + @Mutation(() => ProjectPackages) |
| 54 | + async addPackageToProject( |
| 55 | + @Args('projectId') projectId: string, |
| 56 | + @Args('packageContent') packageContent: string |
| 57 | + ): Promise<ProjectPackages> { |
| 58 | + return this.projectPackagesService.addPackageToProject(projectId, packageContent); |
| 59 | + } |
| 60 | + |
| 61 | + // @GetAuthToken() token: string |
| 62 | + @Mutation(() => Boolean) |
| 63 | + async removePackageFromProject( |
| 64 | + @Args('projectId') projectId: string, |
| 65 | + @Args('packageId') packageId: string |
| 66 | + ): Promise<boolean> { |
| 67 | + return this.projectPackagesService.removePackageFromProject(projectId, packageId); |
| 68 | + } |
| 69 | + |
| 70 | + // @GetAuthToken() token: string |
| 71 | + @Mutation(() => Boolean) |
| 72 | + async updateProjectPath( |
| 73 | + @Args('projectId') projectId: string, |
| 74 | + @Args('newPath') newPath: string |
| 75 | + ): Promise<boolean> { |
| 76 | + return this.projectsService.updateProjectPath(projectId, newPath); |
| 77 | + } |
| 78 | +} |
0 commit comments