Skip to content

Commit b8fe723

Browse files
authored
Merge pull request #23 from arati-tekdi/main
Added certificate and user certificate module
2 parents 6d95808 + 862a1eb commit b8fe723

10 files changed

+881
-0
lines changed

src/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { MemoryStore } from 'cache-manager-memory-store';
77
import { ConfigModule } from '@nestjs/config';
88
import { TrackingAssessmentModule } from 'src/modules/tracking_assessment/tracking_assessment.module';
99
import { TrackingContentModule } from 'src/modules/tracking_content/tracking_content.module';
10+
import { CertificateModule } from './modules/certificate/certificate.module';
11+
import { UserCertificateModule } from './modules/user_certificate/user_certificate.module';
1012

1113
@Module({
1214
imports: [
@@ -15,6 +17,8 @@ import { TrackingContentModule } from 'src/modules/tracking_content/tracking_con
1517
ConfigModule.forRoot({ isGlobal: true }),
1618
DatabaseModule,
1719
CacheModule.register({ isGlobal: true, store: MemoryStore }),
20+
CertificateModule,
21+
UserCertificateModule,
1822
],
1923
controllers: [AppController],
2024
providers: [AppService],
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Module } from '@nestjs/common';
2+
import { CertificateService } from './certificate.service';
3+
import { CertificateController } from './certificate.contoller';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
import { UserCourseCertificate } from './entities/user_course_certificate';
6+
import { LoggerService } from 'src/common/logger/logger.service';
7+
import { AxiosRequest } from 'src/common/middleware/axios.middleware';
8+
9+
@Module({
10+
imports: [TypeOrmModule.forFeature([UserCourseCertificate])],
11+
controllers: [CertificateController],
12+
providers: [CertificateService, LoggerService, AxiosRequest],
13+
})
14+
export class CertificateModule {}

0 commit comments

Comments
 (0)