|
| 1 | +import { Controller, Post, Body, Res, UseGuards, Req } from '@nestjs/common'; |
| 2 | +import { |
| 3 | + ApiInternalServerErrorResponse, |
| 4 | + ApiBadRequestResponse, |
| 5 | + ApiNotFoundResponse, |
| 6 | + ApiOkResponse, |
| 7 | +} from '@nestjs/swagger'; |
| 8 | +import { Response } from 'express'; |
| 9 | +import { CertificateService } from './certificate.service'; |
| 10 | +import { IssueCredentialDto } from './dto/issue-certificate-dto'; |
| 11 | + |
| 12 | +@Controller('certificate') |
| 13 | +export class CertificateController { |
| 14 | + constructor(private readonly certificateService: CertificateService) {} |
| 15 | + // API to generate DID |
| 16 | + @ApiOkResponse({ description: 'DID generated successfully' }) |
| 17 | + @ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) |
| 18 | + @ApiBadRequestResponse({ description: 'Bad Request.' }) |
| 19 | + @Post('generateDid') |
| 20 | + async generateDid( |
| 21 | + @Body() createCertificateDto: any, |
| 22 | + @Res() response: Response, |
| 23 | + ) { |
| 24 | + return this.certificateService.generateDid( |
| 25 | + createCertificateDto.userId, |
| 26 | + response, |
| 27 | + ); |
| 28 | + } |
| 29 | + // API to create schema |
| 30 | + @ApiOkResponse({ description: 'Credential schema created successfully' }) |
| 31 | + @ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) |
| 32 | + @ApiBadRequestResponse({ description: 'Bad Request.' }) |
| 33 | + @Post('schema') |
| 34 | + async createCredentialSchema( |
| 35 | + @Body() createCertificateDto: any, |
| 36 | + @Res() response: Response, |
| 37 | + ) { |
| 38 | + return this.certificateService.createCredentialSchema( |
| 39 | + createCertificateDto.schema, |
| 40 | + response, |
| 41 | + ); |
| 42 | + } |
| 43 | + // API to create template |
| 44 | + @ApiOkResponse({ description: 'Template created successfully' }) |
| 45 | + @ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) |
| 46 | + @ApiBadRequestResponse({ description: 'Bad Request.' }) |
| 47 | + @ApiNotFoundResponse({ description: 'Certificate Not Found.' }) |
| 48 | + @Post('template') |
| 49 | + async createTemplate( |
| 50 | + @Body() createCertificateDto: any, |
| 51 | + @Res() response: Response, |
| 52 | + ) { |
| 53 | + return this.certificateService.createTemplate( |
| 54 | + createCertificateDto.schemaId, |
| 55 | + createCertificateDto.template, |
| 56 | + response, |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + // // API to issue certificate |
| 61 | + @ApiOkResponse({ description: 'Certificate issued successfully.' }) |
| 62 | + @ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) |
| 63 | + @ApiBadRequestResponse({ description: 'Bad Request.' }) |
| 64 | + @Post('issue') |
| 65 | + async issueCertificate( |
| 66 | + @Body() issueCertificateDto: IssueCredentialDto, |
| 67 | + @Res() response: Response, |
| 68 | + @Req() request: Request, |
| 69 | + ) { |
| 70 | + return await this.certificateService.issueCertificateAfterCourseCompletion( |
| 71 | + issueCertificateDto, |
| 72 | + request, |
| 73 | + response, |
| 74 | + ); |
| 75 | + } |
| 76 | + // API to render certificate |
| 77 | + @ApiOkResponse({ description: 'Certificate rendered successfully.' }) |
| 78 | + @ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) |
| 79 | + @ApiBadRequestResponse({ description: 'Bad Request.' }) |
| 80 | + @Post('render') |
| 81 | + async renderCertificate( |
| 82 | + @Body() renderCertificateDto: any, |
| 83 | + @Res() response: Response, |
| 84 | + ) { |
| 85 | + return await this.certificateService.renderCredentials( |
| 86 | + renderCertificateDto.credentialId, |
| 87 | + renderCertificateDto.templateId, |
| 88 | + response, |
| 89 | + ); |
| 90 | + } |
| 91 | +} |
0 commit comments