2024-03-20 19:32:04 +01:00
|
|
|
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put, Query } from '@nestjs/common';
|
2025-01-29 08:58:10 -08:00
|
|
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
2024-09-23 12:09:26 -04:00
|
|
|
import { EndpointLifecycle } from 'src/decorators';
|
2025-04-30 14:23:32 -04:00
|
|
|
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
|
2023-06-30 12:24:28 -04:00
|
|
|
import {
|
2023-10-06 07:01:14 +00:00
|
|
|
AssetBulkDeleteDto,
|
2023-08-16 16:04:55 -04:00
|
|
|
AssetBulkUpdateDto,
|
2024-03-20 23:53:07 +01:00
|
|
|
AssetJobsDto,
|
2025-08-27 14:31:23 -04:00
|
|
|
AssetMetadataResponseDto,
|
|
|
|
|
AssetMetadataRouteParams,
|
|
|
|
|
AssetMetadataUpsertDto,
|
2024-03-20 23:53:07 +01:00
|
|
|
AssetStatsDto,
|
|
|
|
|
AssetStatsResponseDto,
|
2024-01-22 21:54:53 -05:00
|
|
|
DeviceIdDto,
|
2023-09-23 17:28:55 +02:00
|
|
|
RandomAssetsDto,
|
2024-03-20 19:32:04 +01:00
|
|
|
UpdateAssetDto,
|
2024-03-20 23:53:07 +01:00
|
|
|
} from 'src/dtos/asset.dto';
|
|
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2025-07-25 15:25:23 -04:00
|
|
|
import { Permission, RouteKey } from 'src/enum';
|
2024-05-09 13:58:44 -04:00
|
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
2024-03-21 00:07:30 +01:00
|
|
|
import { AssetService } from 'src/services/asset.service';
|
2024-03-20 15:04:03 -05:00
|
|
|
import { UUIDParamDto } from 'src/validation';
|
2023-05-21 08:26:06 +02:00
|
|
|
|
2024-05-30 00:26:57 +02:00
|
|
|
@ApiTags('Assets')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Controller(RouteKey.Asset)
|
2023-05-21 08:26:06 +02:00
|
|
|
export class AssetController {
|
2024-03-15 12:51:08 -04:00
|
|
|
constructor(private service: AssetService) {}
|
2023-05-21 08:26:06 +02:00
|
|
|
|
2023-09-23 17:28:55 +02:00
|
|
|
@Get('random')
|
2025-07-25 15:25:23 -04:00
|
|
|
@Authenticated({ permission: Permission.AssetRead })
|
2024-09-23 12:09:26 -04:00
|
|
|
@EndpointLifecycle({ deprecatedAt: 'v1.116.0' })
|
2023-12-09 23:34:12 -05:00
|
|
|
getRandom(@Auth() auth: AuthDto, @Query() dto: RandomAssetsDto): Promise<AssetResponseDto[]> {
|
|
|
|
|
return this.service.getRandom(auth, dto.count ?? 1);
|
2023-09-23 17:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-25 15:46:20 +00:00
|
|
|
/**
|
|
|
|
|
* Get all asset of a device that are in the database, ID only.
|
|
|
|
|
*/
|
|
|
|
|
@Get('/device/:deviceId')
|
2025-01-29 08:58:10 -08:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'getAllUserAssetsByDeviceId',
|
|
|
|
|
description: 'Get all asset of a device that are in the database, ID only.',
|
|
|
|
|
})
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
2023-12-09 23:34:12 -05:00
|
|
|
getAllUserAssetsByDeviceId(@Auth() auth: AuthDto, @Param() { deviceId }: DeviceIdDto) {
|
|
|
|
|
return this.service.getUserAssetsByDeviceId(auth, deviceId);
|
2023-11-25 15:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-14 09:30:17 -04:00
|
|
|
@Get('statistics')
|
2025-07-25 15:25:23 -04:00
|
|
|
@Authenticated({ permission: Permission.AssetStatistics })
|
2023-12-09 23:34:12 -05:00
|
|
|
getAssetStatistics(@Auth() auth: AuthDto, @Query() dto: AssetStatsDto): Promise<AssetStatsResponseDto> {
|
|
|
|
|
return this.service.getStatistics(auth, dto);
|
2023-07-14 09:30:17 -04:00
|
|
|
}
|
2023-08-04 17:07:15 -04:00
|
|
|
|
2023-08-18 10:31:48 -04:00
|
|
|
@Post('jobs')
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
2024-08-20 08:50:14 -04:00
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2023-12-09 23:34:12 -05:00
|
|
|
runAssetJobs(@Auth() auth: AuthDto, @Body() dto: AssetJobsDto): Promise<void> {
|
|
|
|
|
return this.service.run(auth, dto);
|
2023-08-18 10:31:48 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-16 16:04:55 -04:00
|
|
|
@Put()
|
2025-07-25 15:25:23 -04:00
|
|
|
@Authenticated({ permission: Permission.AssetUpdate })
|
2025-08-08 15:56:37 -04:00
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2023-12-09 23:34:12 -05:00
|
|
|
updateAssets(@Auth() auth: AuthDto, @Body() dto: AssetBulkUpdateDto): Promise<void> {
|
|
|
|
|
return this.service.updateAll(auth, dto);
|
2023-08-16 16:04:55 -04:00
|
|
|
}
|
2023-09-04 22:25:31 -04:00
|
|
|
|
2023-10-06 07:01:14 +00:00
|
|
|
@Delete()
|
2025-07-25 15:25:23 -04:00
|
|
|
@Authenticated({ permission: Permission.AssetDelete })
|
2025-08-08 15:56:37 -04:00
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2023-12-09 23:34:12 -05:00
|
|
|
deleteAssets(@Auth() auth: AuthDto, @Body() dto: AssetBulkDeleteDto): Promise<void> {
|
|
|
|
|
return this.service.deleteAll(auth, dto);
|
2023-10-06 07:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 12:52:21 -05:00
|
|
|
@Get(':id')
|
2025-07-25 15:25:23 -04:00
|
|
|
@Authenticated({ permission: Permission.AssetRead, sharedLink: true })
|
2024-01-25 12:52:21 -05:00
|
|
|
getAssetInfo(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<AssetResponseDto> {
|
|
|
|
|
return this.service.get(auth, id) as Promise<AssetResponseDto>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 22:25:31 -04:00
|
|
|
@Put(':id')
|
2025-07-25 15:25:23 -04:00
|
|
|
@Authenticated({ permission: Permission.AssetUpdate })
|
2024-03-20 19:32:04 +01:00
|
|
|
updateAsset(
|
|
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: UpdateAssetDto,
|
|
|
|
|
): Promise<AssetResponseDto> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.update(auth, id, dto);
|
2023-09-04 22:25:31 -04:00
|
|
|
}
|
2025-08-27 14:31:23 -04:00
|
|
|
|
|
|
|
|
@Get(':id/metadata')
|
|
|
|
|
@Authenticated({ permission: Permission.AssetRead })
|
|
|
|
|
getAssetMetadata(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<AssetMetadataResponseDto[]> {
|
|
|
|
|
return this.service.getMetadata(auth, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put(':id/metadata')
|
|
|
|
|
@Authenticated({ permission: Permission.AssetUpdate })
|
|
|
|
|
updateAssetMetadata(
|
|
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: AssetMetadataUpsertDto,
|
|
|
|
|
): Promise<AssetMetadataResponseDto[]> {
|
|
|
|
|
return this.service.upsertMetadata(auth, id, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id/metadata/:key')
|
|
|
|
|
@Authenticated({ permission: Permission.AssetRead })
|
|
|
|
|
getAssetMetadataByKey(
|
|
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
|
@Param() { id, key }: AssetMetadataRouteParams,
|
|
|
|
|
): Promise<AssetMetadataResponseDto> {
|
|
|
|
|
return this.service.getMetadataByKey(auth, id, key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id/metadata/:key')
|
|
|
|
|
@Authenticated({ permission: Permission.AssetUpdate })
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
deleteAssetMetadata(@Auth() auth: AuthDto, @Param() { id, key }: AssetMetadataRouteParams): Promise<void> {
|
|
|
|
|
return this.service.deleteMetadataByKey(auth, id, key);
|
|
|
|
|
}
|
2023-05-21 08:26:06 +02:00
|
|
|
}
|