src/application/application.controller.ts
/application
Methods |
| Async deleteApplication | |||||||||
deleteApplication(response, id: number)
|
|||||||||
Decorators :
@Delete('/:id')
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async deleteLogoApplication | |||||||||
deleteLogoApplication(response, objectName: string)
|
|||||||||
Decorators :
@Delete('upload/:objectName')
|
|||||||||
|
Defined in src/application/application.controller.ts:72
|
|||||||||
|
Parameters :
Returns :
any
|
| disableApplication | ||||||
disableApplication(id: number)
|
||||||
Decorators :
@Patch(':id/disable')
|
||||||
|
Parameters :
Returns :
any
|
| enableApplication | ||||||
enableApplication(id: number)
|
||||||
Decorators :
@Patch(':id/enable')
|
||||||
|
Parameters :
Returns :
any
|
| getApplication |
getApplication()
|
Decorators :
@Get()
|
|
Defined in src/application/application.controller.ts:86
|
|
Returns :
any
|
| getApplicationDashboards | ||||||
getApplicationDashboards(applicationName: string)
|
||||||
Decorators :
@Get('dashboards/:applicationName')
|
||||||
|
Defined in src/application/application.controller.ts:92
|
||||||
|
Parameters :
Returns :
any
|
| getApplicationId | ||||||
getApplicationId(id: number)
|
||||||
Decorators :
@Get('/:id')
|
||||||
|
Parameters :
Returns :
any
|
| getTest | ||||||
getTest(req: Request)
|
||||||
Decorators :
@Get('/client')
|
||||||
|
Defined in src/application/application.controller.ts:98
|
||||||
|
Parameters :
Returns :
any
|
| Async postApplication | |||||||||
postApplication(response, body: ApplicationCreateDTO)
|
|||||||||
Decorators :
@Post()
|
|||||||||
|
Defined in src/application/application.controller.ts:42
|
|||||||||
|
Parameters :
Returns :
any
|
| putApplication | |||||||||
putApplication(body: ApplicationCreateDTO, id: number)
|
|||||||||
Decorators :
@Put('/:id')
|
|||||||||
|
Parameters :
Returns :
any
|
| Async uploadLogoApplication | |||||||||
uploadLogoApplication(response, file: Express.Multer.File)
|
|||||||||
Decorators :
@Post('upload')
|
|||||||||
|
Defined in src/application/application.controller.ts:50
|
|||||||||
|
Parameters :
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);
}
}