Skip to content

Commit

Permalink
Merge pull request #23 from arati-tekdi/main
Browse files Browse the repository at this point in the history
Added certificate and user certificate module
  • Loading branch information
rushi-tekdi authored Feb 21, 2025
2 parents 6d95808 + 862a1eb commit b8fe723
Show file tree
Hide file tree
Showing 10 changed files with 881 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { MemoryStore } from 'cache-manager-memory-store';
import { ConfigModule } from '@nestjs/config';
import { TrackingAssessmentModule } from 'src/modules/tracking_assessment/tracking_assessment.module';
import { TrackingContentModule } from 'src/modules/tracking_content/tracking_content.module';
import { CertificateModule } from './modules/certificate/certificate.module';
import { UserCertificateModule } from './modules/user_certificate/user_certificate.module';

@Module({
imports: [
Expand All @@ -15,6 +17,8 @@ import { TrackingContentModule } from 'src/modules/tracking_content/tracking_con
ConfigModule.forRoot({ isGlobal: true }),
DatabaseModule,
CacheModule.register({ isGlobal: true, store: MemoryStore }),
CertificateModule,
UserCertificateModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
91 changes: 91 additions & 0 deletions src/modules/certificate/certificate.contoller.ts
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,
);
}
}
14 changes: 14 additions & 0 deletions src/modules/certificate/certificate.module.ts
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 {}
Loading

0 comments on commit b8fe723

Please sign in to comment.