-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from arati-tekdi/main
Added certificate and user certificate module
- Loading branch information
Showing
10 changed files
with
881 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Controller, Post, Body, Res, UseGuards, Req } from '@nestjs/common'; | ||
import { | ||
ApiInternalServerErrorResponse, | ||
ApiBadRequestResponse, | ||
ApiNotFoundResponse, | ||
ApiOkResponse, | ||
} from '@nestjs/swagger'; | ||
import { Response } from 'express'; | ||
import { CertificateService } from './certificate.service'; | ||
import { IssueCredentialDto } from './dto/issue-certificate-dto'; | ||
|
||
@Controller('certificate') | ||
export class CertificateController { | ||
constructor(private readonly certificateService: CertificateService) {} | ||
// API to generate DID | ||
@ApiOkResponse({ description: 'DID generated successfully' }) | ||
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) | ||
@ApiBadRequestResponse({ description: 'Bad Request.' }) | ||
@Post('generateDid') | ||
async generateDid( | ||
@Body() createCertificateDto: any, | ||
@Res() response: Response, | ||
) { | ||
return this.certificateService.generateDid( | ||
createCertificateDto.userId, | ||
response, | ||
); | ||
} | ||
// API to create schema | ||
@ApiOkResponse({ description: 'Credential schema created successfully' }) | ||
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) | ||
@ApiBadRequestResponse({ description: 'Bad Request.' }) | ||
@Post('schema') | ||
async createCredentialSchema( | ||
@Body() createCertificateDto: any, | ||
@Res() response: Response, | ||
) { | ||
return this.certificateService.createCredentialSchema( | ||
createCertificateDto.schema, | ||
response, | ||
); | ||
} | ||
// API to create template | ||
@ApiOkResponse({ description: 'Template created successfully' }) | ||
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) | ||
@ApiBadRequestResponse({ description: 'Bad Request.' }) | ||
@ApiNotFoundResponse({ description: 'Certificate Not Found.' }) | ||
@Post('template') | ||
async createTemplate( | ||
@Body() createCertificateDto: any, | ||
@Res() response: Response, | ||
) { | ||
return this.certificateService.createTemplate( | ||
createCertificateDto.schemaId, | ||
createCertificateDto.template, | ||
response, | ||
); | ||
} | ||
|
||
// // API to issue certificate | ||
@ApiOkResponse({ description: 'Certificate issued successfully.' }) | ||
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) | ||
@ApiBadRequestResponse({ description: 'Bad Request.' }) | ||
@Post('issue') | ||
async issueCertificate( | ||
@Body() issueCertificateDto: IssueCredentialDto, | ||
@Res() response: Response, | ||
@Req() request: Request, | ||
) { | ||
return await this.certificateService.issueCertificateAfterCourseCompletion( | ||
issueCertificateDto, | ||
request, | ||
response, | ||
); | ||
} | ||
// API to render certificate | ||
@ApiOkResponse({ description: 'Certificate rendered successfully.' }) | ||
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' }) | ||
@ApiBadRequestResponse({ description: 'Bad Request.' }) | ||
@Post('render') | ||
async renderCertificate( | ||
@Body() renderCertificateDto: any, | ||
@Res() response: Response, | ||
) { | ||
return await this.certificateService.renderCredentials( | ||
renderCertificateDto.credentialId, | ||
renderCertificateDto.templateId, | ||
response, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { CertificateService } from './certificate.service'; | ||
import { CertificateController } from './certificate.contoller'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { UserCourseCertificate } from './entities/user_course_certificate'; | ||
import { LoggerService } from 'src/common/logger/logger.service'; | ||
import { AxiosRequest } from 'src/common/middleware/axios.middleware'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([UserCourseCertificate])], | ||
controllers: [CertificateController], | ||
providers: [CertificateService, LoggerService, AxiosRequest], | ||
}) | ||
export class CertificateModule {} |
Oops, something went wrong.