2024-03-20 19:32:04 +01:00
|
|
|
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put, Query } from '@nestjs/common';
|
2024-04-27 08:57:39 -04:00
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
2024-03-20 23:53:07 +01:00
|
|
|
import { AssetResponseDto, MemoryLaneResponseDto } 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,
|
|
|
|
|
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';
|
2024-05-29 17:51:01 +02:00
|
|
|
import { MemoryLaneDto } from 'src/dtos/search.dto';
|
2024-03-20 23:53:07 +01:00
|
|
|
import { UpdateStackParentDto } from 'src/dtos/stack.dto';
|
2024-05-09 13:58:44 -04:00
|
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
2024-03-20 15:15:01 -05:00
|
|
|
import { Route } from 'src/middleware/file-upload.interceptor';
|
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')
|
2023-11-03 21:33:15 -04:00
|
|
|
@Controller(Route.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-06-14 20:47:18 -05:00
|
|
|
@Get('memory-lane')
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
2023-12-09 23:34:12 -05:00
|
|
|
getMemoryLane(@Auth() auth: AuthDto, @Query() dto: MemoryLaneDto): Promise<MemoryLaneResponseDto[]> {
|
|
|
|
|
return this.service.getMemoryLane(auth, dto);
|
2023-06-14 20:47:18 -05:00
|
|
|
}
|
2023-06-30 12:24:28 -04:00
|
|
|
|
2023-09-23 17:28:55 +02:00
|
|
|
@Get('random')
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
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')
|
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')
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
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')
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
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()
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
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()
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
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
|
|
|
}
|
|
|
|
|
|
2023-10-22 02:38:07 +00:00
|
|
|
@Put('stack/parent')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
2023-12-09 23:34:12 -05:00
|
|
|
updateStackParent(@Auth() auth: AuthDto, @Body() dto: UpdateStackParentDto): Promise<void> {
|
|
|
|
|
return this.service.updateStackParent(auth, dto);
|
2023-10-22 02:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 12:52:21 -05:00
|
|
|
@Get(':id')
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated({ 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')
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated()
|
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
|
|
|
}
|
2023-05-21 08:26:06 +02:00
|
|
|
}
|