Skip to content

Commit

Permalink
Merge pull request #60 from arati-tekdi/main
Browse files Browse the repository at this point in the history
Change in role for cohort search
  • Loading branch information
Shubham4026 authored Nov 22, 2024
2 parents 8dcd41e + 85f79e1 commit 619a8be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { MiddlewareLoggerModule } from './common/loggers/logger.module';
import { DataValidationService } from './common/service/dataValidation.service';
import { CohortMembers } from './common/entities/CohortMembers.entity';
import { Cohort } from './common/entities/Cohort.entity';
import { LoggingMiddleware } from './common/loggers/logging.middleware';

@Module({
imports: [
Expand Down Expand Up @@ -46,6 +47,6 @@ import { Cohort } from './common/entities/Cohort.entity';
})
export class AppModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(MiddlewareServices).forRoutes('*');
consumer.apply(LoggingMiddleware, MiddlewareServices).forRoutes('*');
}
}
24 changes: 24 additions & 0 deletions src/common/loggers/logging.middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

@Injectable()
export class LoggingMiddleware {
use(req: Request, res: Response, next: NextFunction): void {
// Log request details
const { method, originalUrl, body, query } = req;
console.log(`[Request] ${method} ${originalUrl}`);
console.log('Request Body:', body);
console.log('Request Query:', query);

// Listen for the response and log it after the response is sent
res.on('finish', () => {
const { method, originalUrl } = req;
console.log(`[Response] ${method} ${originalUrl}`);
console.log('Response Status:', res.statusCode);
console.log('Response Body:', res.locals.responseBody); // If you want to log the response body, you will need to capture it (next step).
});

// Proceed to the next middleware or route handler
next();
}
}
12 changes: 9 additions & 3 deletions src/common/middleware/apiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ const rolesGroup = {
'state_admin_mme',
'central_admin_mme',
],
team_leader_teacher: ['teacher', 'team_leader', 'state_admin_mme'],
team_leader_teacher: [
'teacher',
'team_leader',
'state_admin_mme',
'central_admin_mme',
],
admin_team_leader_teacher_student_state_admin_scta_ccta: [
'admin',
'teacher',
Expand All @@ -98,7 +103,7 @@ const rolesGroup = {
'central_admin_mme',
'state_admin_scta',
'central_admin_ccta',
'student'
'student',
],
};
const createPrivilegeGroup = (entity: string) => {
Expand Down Expand Up @@ -170,7 +175,8 @@ export const apiList = {
'/user/v1/read/:userId': createRouteObject({
get: {
PRIVILEGE_CHECK: privilegeGroup.users.read,
ROLE_CHECK: rolesGroup.admin_team_leader_teacher_student_state_admin_scta_ccta,
ROLE_CHECK:
rolesGroup.admin_team_leader_teacher_student_state_admin_scta_ccta,
},
}),
'/user/v1/update/:userId': createRouteObject({
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ForbiddenException } from '@nestjs/common';
async function bootstrap() {
dotenv.config(); // Load environment variables from .env file
const app = await NestFactory.create(AppModule);

//app.use(LoggingMiddleware);
const configService = app.get(ConfigService);

const corsOriginList = configService
Expand Down

0 comments on commit 619a8be

Please sign in to comment.