File

src/application/application.controller.ts

Prefix

/application

Index

Methods

Methods

Async deleteApplication
deleteApplication(response, id: number)
Decorators :
@Delete('/:id')
@ApiResponse({type: Application})
Parameters :
Name Type Optional
response No
id number No
Returns : unknown
Async deleteLogoApplication
deleteLogoApplication(response, objectName: string)
Decorators :
@Delete('upload/:objectName')
@ApiResponse({status: undefined})
Parameters :
Name Type Optional
response No
objectName string No
Returns : any
disableApplication
disableApplication(id: number)
Decorators :
@Patch(':id/disable')
@ApiResponse({type: Application})
Parameters :
Name Type Optional
id number No
Returns : any
enableApplication
enableApplication(id: number)
Decorators :
@Patch(':id/enable')
@ApiResponse({type: Application})
Parameters :
Name Type Optional
id number No
Returns : any
getApplication
getApplication()
Decorators :
@Get()
@ApiResponse({type: undefined})
Returns : any
getApplicationDashboards
getApplicationDashboards(applicationName: string)
Decorators :
@Get('dashboards/:applicationName')
@ApiResponse({type: undefined})
Parameters :
Name Type Optional
applicationName string No
Returns : any
getApplicationId
getApplicationId(id: number)
Decorators :
@Get('/:id')
@ApiResponse({type: Application})
Parameters :
Name Type Optional
id number No
Returns : any
getTest
getTest(req: Request)
Decorators :
@Get('/client')
@ApiResponse({type: undefined})
Parameters :
Name Type Optional
req Request No
Returns : any
Async postApplication
postApplication(response, body: ApplicationCreateDTO)
Decorators :
@Post()
@ApiResponse({status: undefined, type: Application})
Parameters :
Name Type Optional
response No
body ApplicationCreateDTO No
Returns : any
putApplication
putApplication(body: ApplicationCreateDTO, id: number)
Decorators :
@Put('/:id')
@ApiResponse({type: Application})
Parameters :
Name Type Optional
body ApplicationCreateDTO No
id number No
Returns : any
Async uploadLogoApplication
uploadLogoApplication(response, file: Express.Multer.File)
Decorators :
@Post('upload')
@ApiResponse({status: undefined})
@UseInterceptors(undefined)
Parameters :
Name Type Optional
response No
file Express.Multer.File No
Returns : any
import {
  Body,
  Controller,
  Delete,
  Get,
  HttpStatus,
  Param,
  Patch,
  Post,
  Put,
  Res,
  Req,
  UploadedFile,
  UseInterceptors,
  ParseFilePipe,
  MaxFileSizeValidator,
  FileTypeValidator,
} from '@nestjs/common';
import { Request } from 'express';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApplicationService } from './application.service';
import { MinioService } from '../provider/minio/minio.service';
import { ApplicationCreateDTO } from './dto/application.dto';
import { Application } from 'src/entities/application';
import { heydrateErrorCatch } from 'src/util/exception-error';
import jwt, { JwtPayload } from 'jsonwebtoken'
import { ApplicationDashboardService } from 'src/application-dashboard/application-dashboard.service';

@ApiTags('application')
@ApiBearerAuth('token')
@Controller('/application')
export class ApplicationController {
  constructor(
    private readonly applicationDashboardsService: ApplicationDashboardService,
    private readonly applicationService: ApplicationService,
    private readonly minioService: MinioService,
  ) {}

  @Post()
  @ApiResponse({ status: HttpStatus.CREATED, type: Application })
  async postApplication(@Res() response, @Body() body: ApplicationCreateDTO) {
    const id = await this.applicationService.postApplication(body);
    response.status(HttpStatus.CREATED).json({ id });
  }

  @Post('upload')
  @ApiResponse({ status: HttpStatus.CREATED })
  @UseInterceptors(FileInterceptor('file'))
  async uploadLogoApplication(
    @Res() response,
    @UploadedFile(
      new ParseFilePipe({
        validators: [
          new MaxFileSizeValidator({ maxSize: 1024 * 1024 }),
          new FileTypeValidator({ fileType: /(png|PNG|svg|SVG)/ }),
        ],
      }),
    )
    file: Express.Multer.File,
  ) {
    try {
      const filename = await this.minioService.saveFile(file);
      response.status(HttpStatus.CREATED).json({ filename });
    } catch (error) {
      heydrateErrorCatch(error, response);
    }
  }

  @Delete('upload/:objectName')
  @ApiResponse({ status: HttpStatus.CREATED })
  async deleteLogoApplication(
    @Res() response,
    @Param('objectName') objectName: string,
  ) {
    try {
      const result = await this.minioService.deleteObject(objectName);
      response.status(HttpStatus.CREATED).json(result);
    } catch (error) {
      heydrateErrorCatch(error, response);
    }
  }

  @Get()
  @ApiResponse({ type: [Application] })
  getApplication() {
    return this.applicationService.getApplication();
  }

  @Get('dashboards/:applicationName')
  @ApiResponse({ type: [Application] })
  getApplicationDashboards(@Param('applicationName') applicationName: string) {
    return this.applicationDashboardsService.getDashboardsByApplicationName(applicationName);
  }

  @Get('/client')
  @ApiResponse({ type: [Application] })
  getTest(@Req() req: Request) {
    const { authorization } = req.headers
    const [_, token] = authorization.split(' ')
    const decoded = jwt.decode(token, { complete: true });
    const payload: string | JwtPayload | { email: string } = decoded.payload

    return this.applicationService.getApplicationForClient({ email: payload['email'] });
  }

  @Get('/:id')
  @ApiResponse({ type: Application })
  getApplicationId(@Param('id') id: number) {
    return this.applicationService.getApplicationById(id);
  }

  @Put('/:id')
  @ApiResponse({ type: Application })
  putApplication(@Body() body: ApplicationCreateDTO, @Param('id') id: number) {
    return this.applicationService.putApplication(+id, body);
  }

  @Patch(':id/enable')
  @ApiResponse({ type: Application })
  enableApplication(@Param('id') id: number) {
    return this.applicationService.enable(+id);
  }

  @Patch(':id/disable')
  @ApiResponse({ type: Application })
  disableApplication(@Param('id') id: number) {
    return this.applicationService.disable(+id);
  }

  @Delete('/:id')
  @ApiResponse({ type: Application })
  async deleteApplication(@Res() response, @Param('id') id: number) {
    await this.applicationService.deleteApplication(+id);
    return response.sendStatus(HttpStatus.NO_CONTENT);
  }
}

results matching ""

    No results matching ""