1+ import {
2+ Controller ,
3+ Get ,
4+ Post ,
5+ Body ,
6+ Patch ,
7+ Put ,
8+ Param ,
9+ Delete ,
10+ Query ,
11+ HttpCode ,
12+ HttpStatus ,
13+ ValidationPipe ,
14+ ParseUUIDPipe ,
15+ Request ,
16+ } from '@nestjs/common' ;
17+ import { AssetsService } from './assets.service' ;
18+ import { CreateAssetDto , BulkCreateAssetDto } from './dto/create-asset.dto' ;
19+ import {
20+ UpdateAssetDto ,
21+ UpdateAssetStatusDto ,
22+ BulkUpdateAssetDto ,
23+ BulkDeleteAssetDto ,
24+ } from './dto/update-asset.dto' ;
25+ import { AssetQueryDto } from './dto/asset-query.dto' ;
26+
27+ @Controller ( 'assets' )
28+ export class AssetsController {
29+ constructor ( private readonly assetsService : AssetsService ) { }
30+
31+ @Post ( )
32+ @HttpCode ( HttpStatus . CREATED )
33+ create (
34+ @Body ( ValidationPipe ) createAssetDto : CreateAssetDto ,
35+ @Request ( ) req ,
36+ ) {
37+ const userId = req . user ?. id || 'system' ;
38+ return this . assetsService . create ( createAssetDto , userId ) ;
39+ }
40+
41+ @Post ( 'bulk' )
42+ @HttpCode ( HttpStatus . CREATED )
43+ bulkCreate (
44+ @Body ( ValidationPipe ) bulkCreateDto : BulkCreateAssetDto ,
45+ @Request ( ) req ,
46+ ) {
47+ const userId = req . user ?. id || 'system' ;
48+ return this . assetsService . bulkCreate ( bulkCreateDto , userId ) ;
49+ }
50+
51+ @Get ( )
52+ findAll ( @Query ( ValidationPipe ) query : AssetQueryDto ) {
53+ return this . assetsService . findAll ( query ) ;
54+ }
55+
56+ @Get ( ':id' )
57+ findOne ( @Param ( 'id' , ParseUUIDPipe ) id : string ) {
58+ return this . assetsService . findOne ( id ) ;
59+ }
60+
61+ @Put ( ':id' )
62+ update (
63+ @Param ( 'id' , ParseUUIDPipe ) id : string ,
64+ @Body ( ValidationPipe ) updateAssetDto : UpdateAssetDto ,
65+ @Request ( ) req ,
66+ ) {
67+ const userId = req . user ?. id || 'system' ;
68+ return this . assetsService . update ( id , updateAssetDto , userId ) ;
69+ }
70+
71+ @Patch ( ':id/status' )
72+ updateStatus (
73+ @Param ( 'id' , ParseUUIDPipe ) id : string ,
74+ @Body ( ValidationPipe ) updateStatusDto : UpdateAssetStatusDto ,
75+ @Request ( ) req ,
76+ ) {
77+ const userId = req . user ?. id || 'system' ;
78+ return this . assetsService . updateStatus ( id , updateStatusDto , userId ) ;
79+ }
80+
81+ @Put ( 'bulk' )
82+ bulkUpdate (
83+ @Body ( ValidationPipe ) bulkUpdateDto : BulkUpdateAssetDto ,
84+ @Request ( ) req ,
85+ ) {
86+ const userId = req . user ?. id || 'system' ;
87+ return this . assetsService . bulkUpdate ( bulkUpdateDto , userId ) ;
88+ }
89+
90+ @Delete ( ':id' )
91+ @HttpCode ( HttpStatus . NO_CONTENT )
92+ remove ( @Param ( 'id' , ParseUUIDPipe ) id : string , @Request ( ) req ) {
93+ const userId = req . user ?. id || 'system' ;
94+ return this . assetsService . remove ( id , userId ) ;
95+ }
96+
97+ @Delete ( 'bulk' )
98+ @HttpCode ( HttpStatus . OK )
99+ bulkDelete (
100+ @Body ( ValidationPipe ) bulkDeleteDto : BulkDeleteAssetDto ,
101+ @Request ( ) req ,
102+ ) {
103+ const userId = req . user ?. id || 'system' ;
104+ return this . assetsService . bulkDelete ( bulkDeleteDto , userId ) ;
105+ }
106+ }
0 commit comments