-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice-group.controller.ts
More file actions
96 lines (89 loc) · 2.94 KB
/
device-group.controller.ts
File metadata and controls
96 lines (89 loc) · 2.94 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
import { Body, Controller, Param, Query } from '@nestjs/common';
import {
Endpoint,
EndpointType,
} from '../../shared/decorator/endpoint.decorator';
import { CountDto } from '../../shared/dto/count.dto';
import { Role } from '../../core/auth/role/role';
import { IdNumberDto } from '../../shared/dto/id.dto';
import { DeviceGroupService } from './device-group.service';
import { DeviceGroupDto } from './dto/device-group.dto';
import { DeviceGroupUpdateDto } from './dto/device-group-update.dto';
import { DeviceGroupCreateDto } from './dto/device-group-create.dto';
import { DeviceGroupGetQueryDto } from './dto/device-group-get-query.dto';
import { PaginationDto } from '../../shared/dto/pagination.dto';
import { SearchDto } from '../../shared/dto/search.dto';
@Controller('device-group')
export class DeviceGroupController {
constructor(private readonly service: DeviceGroupService) {}
@Endpoint(EndpointType.GET, {
path: 'count',
description: 'Gibt die Anzahl aller Geräte-Gruppen zurück',
responseType: CountDto,
roles: [Role.DeviceTypeView],
})
public getCount(@Query() search: SearchDto): Promise<CountDto> {
return this.service.getCount(search.searchTerm);
}
@Endpoint(EndpointType.GET, {
path: '',
description: 'Gibt alle Geräte-Gruppen zurück',
responseType: [DeviceGroupDto],
roles: [Role.DeviceTypeView],
})
public async getAll(
@Query() pagination: PaginationDto,
@Query() querys: DeviceGroupGetQueryDto,
@Query() search: SearchDto,
): Promise<DeviceGroupDto[]> {
return this.service.findAll(
pagination.offset,
pagination.limit,
querys.sortCol,
querys.sortDir,
search.searchTerm,
);
}
@Endpoint(EndpointType.GET, {
path: ':id',
description: 'Gibt eine Geräte-Gruppe zurück',
responseType: DeviceGroupDto,
notFound: true,
roles: [Role.DeviceTypeView],
})
public getOne(@Param() params: IdNumberDto): Promise<DeviceGroupDto> {
return this.service.findOne(params.id);
}
@Endpoint(EndpointType.POST, {
description: 'Erstellt eine Geräte-Gruppe',
responseType: DeviceGroupDto,
notFound: true,
roles: [Role.DeviceTypeManage],
})
public create(@Body() body: DeviceGroupCreateDto): Promise<DeviceGroupDto> {
return this.service.create(body);
}
@Endpoint(EndpointType.PUT, {
path: ':id',
description: 'Aktualisiert eine Geräte-Gruppen',
notFound: true,
responseType: DeviceGroupDto,
roles: [Role.DeviceTypeManage],
})
public update(
@Param() params: IdNumberDto,
@Body() body: DeviceGroupUpdateDto,
): Promise<DeviceGroupDto> {
return this.service.update(params.id, body);
}
@Endpoint(EndpointType.DELETE, {
path: ':id',
description: 'Löscht eine Geräte-Gruppe',
noContent: true,
notFound: true,
roles: [Role.DeviceTypeManage],
})
public async delete(@Param() params: IdNumberDto): Promise<void> {
await this.service.delete(params.id);
}
}