-
Notifications
You must be signed in to change notification settings - Fork 482
/
feature-toggle.controller.ts
108 lines (101 loc) · 2.98 KB
/
feature-toggle.controller.ts
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
import {
Body,
Controller,
Get,
HttpStatus,
Post,
Query,
UseGuards
} from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Feature } from './feature.entity';
import { FeatureService } from './feature.service';
import { FeatureInterface } from 'unleash-client/lib/feature';
import { getFeatureToggleDefinitions } from 'unleash-client';
import { TenantPermissionGuard } from '../shared/guards/auth/tenant-permission.guard';
import { AuthGuard } from '@nestjs/passport';
import { FeatureEnum, IFeatureOrganizationUpdateInput } from '@gauzy/models';
import { CommandBus } from '@nestjs/cqrs';
import { FeatureToggleUpdateCommand } from './commands/feature-toggle.update.command';
@ApiTags('Feature')
@Controller()
export class FeaturesToggleController {
constructor(
private readonly featureService: FeatureService,
private readonly commandBus: CommandBus
) {}
@Get()
async get() {
let featureToggles: FeatureInterface[] = getFeatureToggleDefinitions();
//only support gauzy feature and removed other
const featureEnums: string[] = Object.values(FeatureEnum);
if (featureToggles) {
featureToggles = featureToggles.filter((toggle: FeatureInterface) =>
featureEnums.includes(toggle.name)
);
}
return featureToggles;
}
@ApiOperation({ summary: 'Find all parent features.' })
@ApiResponse({
status: HttpStatus.OK,
description: 'Found feature',
type: Feature
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Record not found'
})
@UseGuards(AuthGuard('jwt'))
@Get('parent')
async getParentFeatureList(@Query('data') data: any) {
return this.featureService.getParentFeatureList(data);
}
@ApiOperation({ summary: 'Find all features.' })
@ApiResponse({
status: HttpStatus.OK,
description: 'Found feature',
type: Feature
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Record not found'
})
@UseGuards(AuthGuard('jwt'))
@Get('all')
async getAllFeatureList() {
return this.featureService.getAllFeatureList();
}
@ApiOperation({ summary: 'Find all feature organizations.' })
@ApiResponse({
status: HttpStatus.OK,
description: 'Found feature',
type: Feature
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Record not found'
})
@UseGuards(AuthGuard('jwt'), TenantPermissionGuard)
@Get('/organizations')
async getFeaturesOrganization(@Query('data') data: any) {
return this.featureService.getFeatureOrganizations(data);
}
@ApiOperation({ summary: 'Enabled or disabled features' })
@ApiResponse({
status: HttpStatus.CREATED,
description: 'The record has been successfully created/updated.'
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description:
'Invalid input, The response body may contain clues as to what went wrong'
})
@UseGuards(AuthGuard('jwt'), TenantPermissionGuard)
@Post()
async enabledDisabledFeature(
@Body() input: IFeatureOrganizationUpdateInput
) {
return this.commandBus.execute(new FeatureToggleUpdateCommand(input));
}
}