-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathframeworks.controller.ts
More file actions
184 lines (172 loc) · 5.61 KB
/
frameworks.controller.ts
File metadata and controls
184 lines (172 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Query,
UseGuards,
} from '@nestjs/common';
import {
ApiTags,
ApiBearerAuth,
ApiOperation,
ApiQuery,
} from '@nestjs/swagger';
import { HybridAuthGuard } from '../auth/hybrid-auth.guard';
import { PermissionGuard } from '../auth/permission.guard';
import { RequirePermission } from '../auth/require-permission.decorator';
import { SkipOrgCheck } from '../auth/skip-org-check.decorator';
import {
AuthContext,
OrganizationId,
OrganizationIdOptional,
} from '../auth/auth-context.decorator';
import type { AuthContext as AuthContextType } from '../auth/types';
import { FrameworksService } from './frameworks.service';
import { AddFrameworksDto } from './dto/add-frameworks.dto';
import { CreateCustomFrameworkDto } from './dto/create-custom-framework.dto';
import { CreateCustomRequirementDto } from './dto/create-custom-requirement.dto';
import { LinkRequirementsDto } from './dto/link-requirements.dto';
import { LinkControlsDto } from './dto/link-controls.dto';
@ApiTags('Frameworks')
@ApiBearerAuth()
@UseGuards(HybridAuthGuard, PermissionGuard)
@Controller({ path: 'frameworks', version: '1' })
export class FrameworksController {
constructor(private readonly frameworksService: FrameworksService) {}
@Get()
@RequirePermission('framework', 'read')
@ApiOperation({ summary: 'List framework instances for the organization' })
@ApiQuery({ name: 'includeControls', required: false, type: Boolean })
@ApiQuery({ name: 'includeScores', required: false, type: Boolean })
async findAll(
@OrganizationId() organizationId: string,
@Query('includeControls') includeControls?: string,
@Query('includeScores') includeScores?: string,
) {
const data = await this.frameworksService.findAll(organizationId, {
includeControls: includeControls === 'true',
includeScores: includeScores === 'true',
});
return { data, count: data.length };
}
@Get('available')
@SkipOrgCheck()
@ApiOperation({
summary:
'List available frameworks (requires session, no active org needed — used during onboarding)',
})
async findAvailable(@OrganizationIdOptional() organizationId?: string) {
const data = await this.frameworksService.findAvailable(organizationId);
return { data, count: data.length };
}
@Get('scores')
@RequirePermission('framework', 'read')
@ApiOperation({ summary: 'Get overview compliance scores' })
async getScores(
@OrganizationId() organizationId: string,
@AuthContext() authContext: AuthContextType,
) {
return this.frameworksService.getScores(organizationId, authContext.userId);
}
@Get(':id')
@RequirePermission('framework', 'read')
@ApiOperation({ summary: 'Get a single framework instance with full detail' })
async findOne(
@OrganizationId() organizationId: string,
@Param('id') id: string,
) {
return this.frameworksService.findOne(id, organizationId);
}
@Get(':id/requirements/:requirementKey')
@RequirePermission('framework', 'read')
@ApiOperation({ summary: 'Get a specific requirement with related controls' })
async findRequirement(
@OrganizationId() organizationId: string,
@Param('id') id: string,
@Param('requirementKey') requirementKey: string,
) {
return this.frameworksService.findRequirement(
id,
requirementKey,
organizationId,
);
}
@Post()
@RequirePermission('framework', 'create')
@ApiOperation({ summary: 'Add frameworks to the organization' })
async addFrameworks(
@OrganizationId() organizationId: string,
@Body() dto: AddFrameworksDto,
) {
return this.frameworksService.addFrameworks(
organizationId,
dto.frameworkIds,
);
}
@Post('custom')
@RequirePermission('framework', 'create')
@ApiOperation({ summary: 'Create a custom framework for this organization' })
async createCustom(
@OrganizationId() organizationId: string,
@Body() dto: CreateCustomFrameworkDto,
) {
return this.frameworksService.createCustom(organizationId, dto);
}
@Post(':id/requirements')
@RequirePermission('framework', 'update')
@ApiOperation({ summary: 'Add a custom requirement to a framework instance' })
async createRequirement(
@OrganizationId() organizationId: string,
@Param('id') id: string,
@Body() dto: CreateCustomRequirementDto,
) {
return this.frameworksService.createRequirement(id, organizationId, dto);
}
@Post(':id/requirements/link')
@RequirePermission('framework', 'update')
@ApiOperation({
summary:
'Link (clone) existing requirements from another framework into this one',
})
async linkRequirements(
@OrganizationId() organizationId: string,
@Param('id') id: string,
@Body() dto: LinkRequirementsDto,
) {
return this.frameworksService.linkRequirements(
id,
organizationId,
dto.requirementIds,
);
}
@Post(':id/requirements/:requirementKey/controls/link')
@RequirePermission('framework', 'update')
@ApiOperation({
summary: 'Link existing org controls to a requirement',
})
async linkControls(
@OrganizationId() organizationId: string,
@Param('id') id: string,
@Param('requirementKey') requirementKey: string,
@Body() dto: LinkControlsDto,
) {
return this.frameworksService.linkControlsToRequirement(
id,
requirementKey,
organizationId,
dto.controlIds,
);
}
@Delete(':id')
@RequirePermission('framework', 'delete')
@ApiOperation({ summary: 'Delete a framework instance' })
async delete(
@OrganizationId() organizationId: string,
@Param('id') id: string,
) {
return this.frameworksService.delete(id, organizationId);
}
}