85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { IdeasService } from "./ideas.service";
|
|
import {
|
|
CreateIdeaDto,
|
|
CaptureIdeaDto,
|
|
UpdateIdeaDto,
|
|
QueryIdeasDto,
|
|
} from "./dto";
|
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
|
import { WorkspaceGuard, PermissionGuard } from "../common/guards";
|
|
import { Workspace, Permission, RequirePermission } from "../common/decorators";
|
|
import { CurrentUser } from "../auth/decorators/current-user.decorator";
|
|
|
|
@Controller("ideas")
|
|
@UseGuards(AuthGuard, WorkspaceGuard, PermissionGuard)
|
|
export class IdeasController {
|
|
constructor(private readonly ideasService: IdeasService) {}
|
|
|
|
@Post("capture")
|
|
@RequirePermission(Permission.WORKSPACE_MEMBER)
|
|
async capture(
|
|
@Body() captureIdeaDto: CaptureIdeaDto,
|
|
@Workspace() workspaceId: string,
|
|
@CurrentUser() user: any
|
|
) {
|
|
return this.ideasService.capture(workspaceId, user.id, captureIdeaDto);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermission(Permission.WORKSPACE_MEMBER)
|
|
async create(
|
|
@Body() createIdeaDto: CreateIdeaDto,
|
|
@Workspace() workspaceId: string,
|
|
@CurrentUser() user: any
|
|
) {
|
|
return this.ideasService.create(workspaceId, user.id, createIdeaDto);
|
|
}
|
|
|
|
@Get()
|
|
@RequirePermission(Permission.WORKSPACE_ANY)
|
|
async findAll(
|
|
@Query() query: QueryIdeasDto,
|
|
@Workspace() workspaceId: string
|
|
) {
|
|
return this.ideasService.findAll({ ...query, workspaceId });
|
|
}
|
|
|
|
@Get(":id")
|
|
@RequirePermission(Permission.WORKSPACE_ANY)
|
|
async findOne(@Param("id") id: string, @Workspace() workspaceId: string) {
|
|
return this.ideasService.findOne(id, workspaceId);
|
|
}
|
|
|
|
@Patch(":id")
|
|
@RequirePermission(Permission.WORKSPACE_MEMBER)
|
|
async update(
|
|
@Param("id") id: string,
|
|
@Body() updateIdeaDto: UpdateIdeaDto,
|
|
@Workspace() workspaceId: string,
|
|
@CurrentUser() user: any
|
|
) {
|
|
return this.ideasService.update(id, workspaceId, user.id, updateIdeaDto);
|
|
}
|
|
|
|
@Delete(":id")
|
|
@RequirePermission(Permission.WORKSPACE_ADMIN)
|
|
async remove(
|
|
@Param("id") id: string,
|
|
@Workspace() workspaceId: string,
|
|
@CurrentUser() user: any
|
|
) {
|
|
return this.ideasService.remove(id, workspaceId, user.id);
|
|
}
|
|
}
|