1import { Inject, Body, Controller, Delete, Get, Param, Patch, Post, Req } from "@nestjs/common"; 2import type { Request } from "express"; 3import { TeamsService } from "./teams.service.js"; 4import { ZodValidate } from "../../common/pipes/zod-validation.pipe.js"; 5import { requireActor } from "../../common/types.js"; 6import { 7 CreateTeamDto, 8 type CreateTeamInput, 9 TeamMemberDto, 10 type TeamMemberInput, 11 UpdateTeamDto, 12 type UpdateTeamInput 13} from "./dto.js"; 14 15@Controller("workspaces/:workspaceId/teams") 16export class TeamsController { 17 constructor(@Inject(TeamsService) private readonly teams: TeamsService) {} 18 19 @Get() 20 list(@Param("workspaceId") workspaceId: string, @Req() req: Request) { 21 return this.teams.list(workspaceId, requireActor(req)); 22 } 23 24 @Post() 25 create( 26 @Param("workspaceId") workspaceId: string, 27 @Body(ZodValidate(CreateTeamDto)) body: CreateTeamInput, 28 @Req() req: Request 29 ) { 30 return this.teams.create(workspaceId, requireActor(req), body, req); 31 } 32 33 @Get(":teamId") 34 get(@Param("workspaceId") workspaceId: string, @Param("teamId") teamId: string, @Req() req: Request) { 35 return this.teams.get(workspaceId, teamId, requireActor(req)); 36 } 37 38 @Patch(":teamId") 39 update( 40 @Param("workspaceId") workspaceId: string, 41 @Param("teamId") teamId: string, 42 @Body(ZodValidate(UpdateTeamDto)) body: UpdateTeamInput, 43 @Req() req: Request 44 ) { 45 return this.teams.update(workspaceId, teamId, requireActor(req), body, req); 46 } 47 48 @Delete(":teamId") 49 remove(@Param("workspaceId") workspaceId: string, @Param("teamId") teamId: string, @Req() req: Request) { 50 return this.teams.remove(workspaceId, teamId, requireActor(req), req).then(() => ({ deleted: true })); 51 } 52 53 @Post(":teamId/members") 54 addMember( 55 @Param("workspaceId") workspaceId: string, 56 @Param("teamId") teamId: string, 57 @Body(ZodValidate(TeamMemberDto)) body: TeamMemberInput, 58 @Req() req: Request 59 ) { 60 return this.teams.addMember(workspaceId, teamId, requireActor(req), body.userId, req); 61 } 62 63 @Delete(":teamId/members/:userId") 64 removeMember( 65 @Param("workspaceId") workspaceId: string, 66 @Param("teamId") teamId: string, 67 @Param("userId") userId: string, 68 @Req() req: Request 69 ) { 70 return this.teams.removeMember(workspaceId, teamId, requireActor(req), userId, req).then(() => ({ removed: true })); 71 } 72} 73