import { ILoggedInUser } from '@energyweb/origin-backend-core' ; import { ActiveUserGuard , NullOrUndefinedResultInterceptor , UserDecorator } from '@energyweb/origin-backend-utils' ; import { Body , ClassSerializerInterceptor , Controller , Get , HttpCode , HttpStatus , Param , ParseUUIDPipe , Post , UseGuards , UseInterceptors , UsePipes , ValidationPipe } from '@nestjs/common' ; import { AuthGuard } from '@nestjs/passport' ; import { ApiBearerAuth , ApiBody , ApiResponse , ApiTags } from '@nestjs/swagger' ; import { BaseDemandController } from '../../src/pods/demand' ; import { CreateDemandDTO } from './create-demand.dto' ; import { DemandSummaryDTO } from './demand-summary.dto' ; import { DemandDTO } from './demand.dto' ; @ ApiTags ( 'demand' ) @ ApiBearerAuth ( 'access-token' ) @ Controller ( 'demand' ) @ UseInterceptors ( ClassSerializerInterceptor , NullOrUndefinedResultInterceptor ) @ UsePipes ( ValidationPipe ) export class DemandController extends BaseDemandController < string > { @ Get ( '/:id' ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ ApiResponse ( { status : HttpStatus . OK , type : DemandDTO , description : 'Get a demand' } ) public async findOne ( @ UserDecorator ( ) user , @ Param ( 'id' , new ParseUUIDPipe ( { version : '4' } ) ) id ) { return super . findOne ( user , id ) ; } @ Get ( ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ ApiResponse ( { status : HttpStatus . OK , type : [ DemandDTO ] , description : 'Get all demands' } ) public async getAll ( @ UserDecorator ( ) user ) { return super . getAll ( user ) ; } @ Post ( ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ ApiBody ( { type : CreateDemandDTO } ) @ ApiResponse ( { status : HttpStatus . CREATED , type : DemandDTO , description : 'Create a demand' } ) public async create ( @ UserDecorator ( ) user , @ Body ( ) createDemand ) { return super . create ( user , createDemand ) ; } @ Post ( '/summary' ) @ HttpCode ( HttpStatus . OK ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ ApiBody ( { type : CreateDemandDTO } ) @ ApiResponse ( { status : HttpStatus . OK , type : DemandSummaryDTO , description : 'Get a demand summary' } ) public summary ( @ UserDecorator ( ) user , @ Body ( ) createDemand ) { return super . summary ( user , createDemand ) ; } @ Post ( '/:id/pause' ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ HttpCode ( HttpStatus . ACCEPTED ) @ ApiResponse ( { status : HttpStatus . ACCEPTED , type : DemandDTO , description : 'Pause a Demand' } ) public async pause ( @ UserDecorator ( ) user , @ Param ( 'id' , new ParseUUIDPipe ( { version : '4' } ) ) id ) { return super . pause ( user , id ) ; } @ Post ( '/:id/resume' ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ HttpCode ( HttpStatus . ACCEPTED ) @ ApiResponse ( { status : HttpStatus . ACCEPTED , type : DemandDTO , description : 'Resume a Demand' } ) public async resume ( @ UserDecorator ( ) user , @ Param ( 'id' , new ParseUUIDPipe ( { version : '4' } ) ) id ) { return super . resume ( user , id ) ; } @ Post ( '/:id/archive' ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ HttpCode ( HttpStatus . ACCEPTED ) @ ApiResponse ( { status : HttpStatus . ACCEPTED , type : DemandDTO , description : 'Archive a Demand' } ) public async archive ( @ UserDecorator ( ) user , @ Param ( 'id' , new ParseUUIDPipe ( { version : '4' } ) ) id ) { return super . archive ( user , id ) ; } @ Post ( '/:id/replace' ) @ UseGuards ( AuthGuard ( ) , ActiveUserGuard ) @ HttpCode ( HttpStatus . CREATED ) @ ApiBody ( { type : CreateDemandDTO } ) @ ApiResponse ( { status : HttpStatus . CREATED , type : DemandDTO , description : 'Replace a Demand' } ) public async replace ( @ UserDecorator ( ) user , @ Param ( 'id' , new ParseUUIDPipe ( { version : '4' } ) ) id , @ Body ( ) createDemand ) { return super . replace ( user , id , createDemand ) ; } }