Skip to content

Dev: ui up to date #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/learning-token-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
"@nestjs/typeorm": "^9.0.1",
"@pinata/sdk": "^2.1.0",
"@types/passport-jwt": "^3.0.6",
"axios": "^1.7.4",
"axios": "^1.7.7",
"bcrypt": "^5.0.1",
"bcryptjs": "^2.4.3",
"cache-manager": "^4.1.0",
"cache-manager-redis-store": "^2.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"ethers": "^6.13.2",
"dotenv": "^16.4.5",
"ethers": "^6.13.4",
"moment": "^2.29.4",
"nestjs-typeorm-paginate": "^4.0.2",
"nodemailer": "^6.9.14",
Expand All @@ -47,7 +48,7 @@
"passport-local": "^1.0.0",
"pdf-lib": "^1.17.1",
"pg": "^8.8.0",
"pinata": "^0.4.0",
"pinata": "^1.5.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
Expand Down Expand Up @@ -95,5 +96,6 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
},
"packageManager": "[email protected]+sha512.5b7bc055cad63273dda27df1570a5d2eb4a9f03b35b394d3d55393c2a5560a17f5cef30944b11d6a48bcbcfc1c3a26d618aae77044774c529ba36cb771ad5b0f"
}
1 change: 1 addition & 0 deletions src/learning-token-backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PosteventModule } from './modules/postevent/postevent.module'
import { SmartcontractModule } from './modules/smartcontract/smartcontract.module'
import { EventModule } from './modules/event/event.module'
import { SeederModule } from './modules/role/seeder/seeder.module'

@Module({
imports: [
ConfigModule.forRoot({
Expand Down
38 changes: 36 additions & 2 deletions src/learning-token-backend/src/common/guards/jwt-auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
import { Injectable } from '@nestjs/common'
import {
CanActivate,
ExecutionContext,
Injectable,
UnauthorizedException
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'

import { JwtService as Jwt } from '@nestjs/jwt'

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {}
export class JwtAuthGuard extends AuthGuard('jwt') implements CanActivate {
constructor(private readonly jwt: Jwt) {
super()
}

async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest()
const token = this.extractTokenFromHeader(request)

if (!token) {
throw new UnauthorizedException('No token provided')
}

try {
const payload = await this.jwt.verify(token)

request['user'] = payload
return true
} catch (error) {
throw new UnauthorizedException('Invalid token')
}
}

private extractTokenFromHeader(request: any): string | undefined {
const [type, token] = request.headers.authorization?.split(' ') ?? []
return type === 'Bearer' ? token : undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { AdminService } from './users.service'
export class AdminController {
constructor(private readonly adminService: AdminService) {}

@UseGuards(JwtAuthGuard)
// @UseGuards(JwtAuthGuard)
@Get('institution-list')
private async get_institution_list(
@Query('page') page = 1, // Set default value to 1
Expand Down Expand Up @@ -87,7 +87,7 @@ export class AdminController {
}
}

@UseGuards(JwtAuthGuard)
// @UseGuards(JwtAuthGuard)
@Patch('institution/:id')
async update_institution(@Param('id') id: number) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AuthService {
private readonly jwtService: JwtService,
@InjectRepository(Role)
private readonly roleRepository: Repository<Role>
) {}
) { }

/**
* REGISTRATION OF A USER
Expand Down Expand Up @@ -243,4 +243,4 @@ export class AuthService {
public refreshToken(loggedInUser: any) {
return this.jwtService.generateToken(loggedInUser, 'institution')
}
}
}
20 changes: 16 additions & 4 deletions src/learning-token-backend/src/modules/auth/service/jwt.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common'
import { Injectable, UnauthorizedException } from '@nestjs/common'
import { JwtService as Jwt } from '@nestjs/jwt'
import { InjectRepository } from '@nestjs/typeorm'
import * as bcrypt from 'bcryptjs'
Expand Down Expand Up @@ -91,10 +91,22 @@ export class JwtService {
return bcrypt.hashSync(password, salt)
}

// Validate JWT Token, throw forbidden error if JWT Token is invalid
// Validate JWT Token, throw unauthorized exception if JWT Token is invalid
public async verify(token: string): Promise<any> {
console.log('Received token:', token)

if (!token || typeof token !== 'string') {
console.error('Invalid token received:', token)
throw new UnauthorizedException('No valid token provided')
}

try {
return this.jwt.verify(token)
} catch (err) {}
const decoded = this.jwt.verify(token)
console.log('Decoded token:', decoded)
return decoded
} catch (err) {
console.error('Token verification failed:', err.message)
throw new UnauthorizedException('Invalid token')
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Module } from '@nestjs/common';
import { InstructorsService } from './instructors.service';
import { InstructorsController } from './instructors.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Instructor } from './entities/instructor.entity';
import { AuthModule } from '../auth/auth.module';
import { Module } from '@nestjs/common'
import { InstructorsService } from './instructors.service'
import { InstructorsController } from './instructors.controller'
import { TypeOrmModule } from '@nestjs/typeorm'
import { Instructor } from './entities/instructor.entity'
import { AuthModule } from '../auth/auth.module'

@Module({
controllers: [InstructorsController],
providers: [InstructorsService],
imports: [TypeOrmModule.forFeature([Instructor]), AuthModule],
imports: [TypeOrmModule.forFeature([Instructor]), AuthModule]
})
export class InstructorsModule {}
export class InstructorsModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,14 @@ export class PreeventService {
const orderByCondition: FindOptionsOrder<Preevent> = {
[orderBy]: desc ? 'DESC' : 'ASC'
}
console.log('reqUser::: ', reqUser);

return await paginate<Preevent>(this.preeventRepository, options, {
where: { id: reqUser.id },
where: {
instructor: {
id: reqUser.id
}
},
relations: [
'onlineEvent',
'onlineEvent.scoringGuide',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { DistributeTokenDto } from './dto/distrbute-token.dto'

@Controller('smartcontract')
export class SmartcontractController {
constructor(private readonly smartcontractService: SmartcontractService) {}
constructor(private readonly smartcontractService: SmartcontractService) { }

@Get()
findAll() {
Expand Down Expand Up @@ -52,13 +52,7 @@ export class SmartcontractController {
return result
}

@Post('register-actor')
async registerInstitution(@Body() body: any) {
const result = await this.smartcontractService.onboardingActor(body)
return result
}

@UseGuards(JwtAuthGuard)
@Post('token-distributions')
@AllowUserTypes(RoleEnum.INSTRUCTOR)
@Post('token-distributions')
async distributeToken(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Module, Post } from '@nestjs/common'
import { SmartcontractService } from './smartcontract.service'
import { SmartcontractController } from './smartcontract.controller'
import { Module } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { TypeOrmModule } from '@nestjs/typeorm'
import { Postevent } from '../postevent/entities/postevent.entity'
import { Preevent } from '../preevent/entities/preevent.entity'
import { Learner } from '../learners/entities/learner.entity'
import { Institution } from '../institutions/entities/institution.entity'
import { Instructor } from '../instructors/entities/instructor.entity'
import { Learner } from '../learners/entities/learner.entity'
import { Postevent } from '../postevent/entities/postevent.entity'
import { Preevent } from '../preevent/entities/preevent.entity'
import { SmartcontractController } from './smartcontract.controller'
import { SmartcontractService } from './smartcontract.service'
import { OnlineEvent } from '../event/entities/event.entity'
import { ScoringGuide } from '../event/entities/scoring-guide.entity'

Expand All @@ -27,4 +27,4 @@ import { ScoringGuide } from '../event/entities/scoring-guide.entity'
providers: [SmartcontractService, ConfigService],
exports: [SmartcontractService]
})
export class SmartcontractModule {}
export class SmartcontractModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class SmartcontractService {
// console.log('View Function Result:', processedResult)
console.log(
body.functionName ===
SmartcontractFunctionsEnum.REGISTER_LEARNER
SmartcontractFunctionsEnum.REGISTER_LEARNER
)
if (
body.functionName ===
Expand Down
24 changes: 0 additions & 24 deletions src/learning-token-backend/test/app.e2e-spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/learning-token-backend/test/jest-e2e.json

This file was deleted.

17 changes: 17 additions & 0 deletions src/learning-token-dashboard/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
28 changes: 26 additions & 2 deletions src/learning-token-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,46 @@
"preview": "vite preview"
},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@metismenu/react": "^0.0.3",
"@pinata/sdk": "^2.1.0",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@reduxjs/toolkit": "^1.9.6",
"@tanstack/react-table": "^8.20.5",
"@types/node": "^22.5.1",
"axios": "^1.6.2",
"bootstrap": "^5.3.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"ethers": "^6.7.1",
"formik": "^2.4.5",
"framer-motion": "^11.3.31",
"lucide-react": "^0.436.0",
"next-themes": "^0.3.0",
"react": "^18.2.0",
"react-bootstrap": "^2.10.5",
"react-dom": "^18.2.0",
"react-hook-form": "^7.53.0",
"react-hot-toast": "^2.4.1",
"react-icons": "^4.11.0",
"react-redux": "^8.1.2",
"react-router-dom": "^6.16.0",
"react-select": "^5.7.5",
"rsuite": "^5.40.0",
"sass": "^1.68.0",
"sonner": "^1.5.0",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
"xlsx": "^0.18.5",
"yup": "^1.3.2"
"yup": "^1.3.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand All @@ -42,5 +65,6 @@
"tailwindcss": "^3.3.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
},
"packageManager": "[email protected]+sha512.5b7bc055cad63273dda27df1570a5d2eb4a9f03b35b394d3d55393c2a5560a17f5cef30944b11d6a48bcbcfc1c3a26d618aae77044774c529ba36cb771ad5b0f"
}
Loading