The board lists a pipeline in current work only when it has a deal in that period, and keeps archive-only paths for the prior-data view. Co-authored-by: Cursor <cursoragent@cursor.com>
145 lines
3.7 KiB
TypeScript
145 lines
3.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { RequirePermission, SectionPermissionGuard } from '../auth/section-permission.guard';
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
import { Roles } from '../auth/roles.decorator';
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
import type { Actor } from '../common/record-scope';
|
|
import {
|
|
CreatePipelineDto,
|
|
CreatePipelineStageDto,
|
|
MergePipelineDto,
|
|
ReorderPipelineStagesDto,
|
|
UpdatePipelineStageDto,
|
|
} from './dto';
|
|
import { PipelinesService } from './pipelines.service';
|
|
|
|
@Controller('pipelines')
|
|
@UseGuards(JwtAuthGuard, RolesGuard, SectionPermissionGuard)
|
|
@RequirePermission('sales')
|
|
export class PipelinesController {
|
|
constructor(private readonly pipelinesService: PipelinesService) {}
|
|
|
|
@Get()
|
|
list(
|
|
@CurrentUser() user: Actor,
|
|
@Query('forLens') forLens?: string,
|
|
) {
|
|
return this.pipelinesService.list(user, forLens === '1');
|
|
}
|
|
|
|
@Get('board')
|
|
board(
|
|
@CurrentUser() user: Actor,
|
|
@Query('pipelineId') pipelineId?: string,
|
|
@Query('prior') prior?: string,
|
|
) {
|
|
return this.pipelinesService.getBoard(user.organizationId, pipelineId, user, prior === 'all');
|
|
}
|
|
|
|
@Post()
|
|
@Roles('owner', 'admin')
|
|
create(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Body() dto: CreatePipelineDto,
|
|
) {
|
|
return this.pipelinesService.create(user.organizationId, dto.name);
|
|
}
|
|
|
|
@Get(':pipelineId/merge-preview')
|
|
@Roles('owner', 'admin')
|
|
mergePreview(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('pipelineId') pipelineId: string,
|
|
) {
|
|
return this.pipelinesService.mergePreview(user.organizationId, pipelineId);
|
|
}
|
|
|
|
@Post(':pipelineId/merge')
|
|
@Roles('owner', 'admin')
|
|
merge(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('pipelineId') pipelineId: string,
|
|
@Body() dto: MergePipelineDto,
|
|
) {
|
|
return this.pipelinesService.merge(user.organizationId, pipelineId, dto);
|
|
}
|
|
|
|
@Delete(':pipelineId')
|
|
@Roles('owner', 'admin')
|
|
remove(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('pipelineId') pipelineId: string,
|
|
) {
|
|
return this.pipelinesService.remove(user.organizationId, pipelineId);
|
|
}
|
|
|
|
@Post(':pipelineId/stages')
|
|
@Roles('owner', 'admin')
|
|
createStage(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('pipelineId') pipelineId: string,
|
|
@Body() dto: CreatePipelineStageDto,
|
|
) {
|
|
return this.pipelinesService.createStage(
|
|
user.organizationId,
|
|
pipelineId,
|
|
dto.name,
|
|
);
|
|
}
|
|
|
|
@Patch(':pipelineId/stages/order')
|
|
@Roles('owner', 'admin')
|
|
reorderStages(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('pipelineId') pipelineId: string,
|
|
@Body() dto: ReorderPipelineStagesDto,
|
|
) {
|
|
return this.pipelinesService.reorderStages(
|
|
user.organizationId,
|
|
pipelineId,
|
|
dto.stageIds,
|
|
);
|
|
}
|
|
|
|
@Patch(':pipelineId/stages/:stageId')
|
|
@Roles('owner', 'admin')
|
|
updateStage(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('pipelineId') pipelineId: string,
|
|
@Param('stageId') stageId: string,
|
|
@Body() dto: UpdatePipelineStageDto,
|
|
) {
|
|
return this.pipelinesService.updateStage(
|
|
user.organizationId,
|
|
pipelineId,
|
|
stageId,
|
|
dto.name,
|
|
);
|
|
}
|
|
|
|
@Delete(':pipelineId/stages/:stageId')
|
|
@Roles('owner', 'admin')
|
|
deleteStage(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('pipelineId') pipelineId: string,
|
|
@Param('stageId') stageId: string,
|
|
) {
|
|
return this.pipelinesService.deleteStage(
|
|
user.organizationId,
|
|
pipelineId,
|
|
stageId,
|
|
);
|
|
}
|
|
}
|