-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocation.controller.ts
More file actions
98 lines (90 loc) · 2.86 KB
/
location.controller.ts
File metadata and controls
98 lines (90 loc) · 2.86 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
import { Body, Controller, Param, Query } from '@nestjs/common';
import { LocationService } from './location.service';
import {
Endpoint,
EndpointType,
} from '../../shared/decorator/endpoint.decorator';
import { LocationDto } from './dto/location.dto';
import { Role } from '../../core/auth/role/role';
import { IdNumberDto } from '../../shared/dto/id.dto';
import { CountDto } from '../../shared/dto/count.dto';
import { LocationGetQueryDto } from './dto/location-get-query.dto';
import { LocationCreateDto } from './dto/location-create.dto';
import { LocationUpdateDto } from './dto/location-update.dto';
import { PaginationDto } from '../../shared/dto/pagination.dto';
import { SearchDto } from '../../shared/dto/search.dto';
@Controller('location')
export class LocationController {
constructor(private readonly service: LocationService) {}
@Endpoint(EndpointType.GET, {
path: 'count',
description: 'Gibt die Anzahl aller Standorte zurück',
responseType: CountDto,
roles: [Role.LocationView],
})
public getCount(@Query() search: SearchDto): Promise<CountDto> {
return this.service.getCount(search.searchTerm);
}
@Endpoint(EndpointType.GET, {
path: '',
description: 'Gibt alle Standorte zurück',
responseType: [LocationDto],
roles: [Role.LocationView],
})
public async getAll(
@Query() pagination: PaginationDto,
@Query() querys: LocationGetQueryDto,
@Query() search: SearchDto,
): Promise<LocationDto[]> {
return this.service.findAll(
pagination.offset,
pagination.limit,
querys.sortCol,
querys.sortDir,
search.searchTerm,
);
}
@Endpoint(EndpointType.GET, {
path: ':id',
description: 'Gibt einen Standort zurück',
responseType: LocationDto,
notFound: true,
roles: [Role.LocationView],
})
public getOne(@Param() params: IdNumberDto): Promise<LocationDto> {
return this.service.findOne(params.id);
}
@Endpoint(EndpointType.POST, {
description: 'Erstellt einen Standort',
responseType: LocationDto,
notFound: true,
roles: [Role.LocationManage],
})
public create(@Body() body: LocationCreateDto): Promise<LocationDto> {
return this.service.create(body);
}
@Endpoint(EndpointType.PUT, {
path: ':id',
description: 'Aktualisiert einen Standort',
notFound: true,
responseType: LocationDto,
roles: [Role.LocationManage],
})
public update(
@Param() params: IdNumberDto,
@Body() body: LocationUpdateDto,
): Promise<LocationDto> {
return this.service.update(params.id, body);
}
@Endpoint(EndpointType.DELETE, {
path: ':id',
description: 'Löscht einen Standort',
noContent: true,
notFound: true,
roles: [Role.LocationManage],
})
public async delete(@Param() params: IdNumberDto): Promise<void> {
await this.service.delete(params.id);
}
// TODO get parent, get children (depth 2)
}