Skip to content

Commit

Permalink
Merge pull request #17 from poojakarma/event_integration_in_Middleware
Browse files Browse the repository at this point in the history
PS - added middleware for event(1947), todo (2127) and notification (1960)
  • Loading branch information
rushi-tekdi authored Oct 11, 2024
2 parents b45883f + fdcfa9e commit be0aa30
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
50 changes: 38 additions & 12 deletions src/common/middleware/apiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const privilegeGroup = {
cohort: createPrivilegeGroup('cohort'),
cohortmembers: createPrivilegeGroup('cohortmembers'),
attendance: createPrivilegeGroup('attendance'),
event: createPrivilegeGroup('event'),
};
const common_public_get = { get: {} };
const createRouteObject = (methods: any, redirectUrl: string | null = null) => {
Expand Down Expand Up @@ -335,23 +336,20 @@ export const apiList = {
'/event-service/event/v1/create': createRouteObject({
post: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
PRIVILEGE_CHECK: privilegeGroup.event.create,
},
}),
'/event-service/event/v1/list': createRouteObject({
post: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
ROLE_CHECK: rolesGroup.common,
PRIVILEGE_CHECK: privilegeGroup.event.read,
},
}),
'/event-service/event/v1/:id': createRouteObject({
get: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
},
patch: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
},
delete: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
},
PRIVILEGE_CHECK: privilegeGroup.event.update,
}
}),
//event-attendance
'/event-service/attendees/v1/create': createRouteObject({
Expand All @@ -377,7 +375,7 @@ export const apiList = {
//notification templates
'/notification-templates': createRouteObject({
post: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
ROLE_CHECK: rolesGroup.admin_team_leader_teacher
},
}),
'/notification-templates/list': createRouteObject({
Expand Down Expand Up @@ -496,6 +494,29 @@ export const apiList = {
ROLE_CHECK: rolesGroup.admin_team_leader,
},
}),
// todos
'/todo/create': createRouteObject({
post: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
},
}),
'/todo/list': createRouteObject({
post: {
ROLE_CHECK: rolesGroup.common,
},
}),
'/todo/:id': createRouteObject({
get: {
ROLE_CHECK: rolesGroup.common,
},
patch: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
},
delete: {
ROLE_CHECK: rolesGroup.admin_team_leader_teacher,
},
}),


//sunbird knowlg and inQuiry service
//public
Expand Down Expand Up @@ -774,9 +795,14 @@ export const publicAPI = [

// api which required academic year
export const apiListForAcademicYear = [
'/user/v1/academicyears/create',
'/user/v1/academicyears/list',
'/user/v1/academicyears/:identifier',
'user/v1/cohortmember/list',
'user/v1/cohortmember/bulkCreate',
'user/v1/cohortmember/create',
'user/v1/cohortmember/read/:identifier',
'user/v1/cohort/create',
'user/v1/cohort/search',
'user/v1/cohort/cohortHierarchy/:identifier',
'user/v1/cohort/mycohorts/:identifier'
];

function convertToRegex(pattern) {
Expand Down
5 changes: 3 additions & 2 deletions src/common/middleware/middleware.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class MiddlewareServices {
private permissionService: PermissionsService,
private configService: ConfigService,
private dataValidationService: DataValidationService,
) {}
) { }

async use(req: Request, res: Response, next: NextFunction) {
try {
Expand Down Expand Up @@ -236,6 +236,7 @@ export class MiddlewareServices {
const serviceMapping: { [key: string]: string } = {
'/user': 'USER_SERVICE',
'/event-service': 'EVENT_SERVICE',
'/todo': 'TODO_SERVICE',
'/notification-templates': 'NOTIFICATION_SERVICE',
'/notification': 'NOTIFICATION_SERVICE',
'/queue': 'NOTIFICATION_SERVICE',
Expand Down Expand Up @@ -332,7 +333,7 @@ export class MiddlewareServices {
const isAuthorized = rolesOfTenant?.includes('admin')
? true
: rolesForURL.filter((role: string) => rolesOfTenant?.includes(role))
.length > 0;
.length > 0;

if (isAuthorized) {
return resolve(true);
Expand Down
3 changes: 2 additions & 1 deletion src/middleware/gateway.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MiddlewareLogger } from 'src/common/loggers/logger.service';

@Injectable()
export class GatewayService {
constructor(private readonly middlewareLogger: MiddlewareLogger) {}
constructor(private readonly middlewareLogger: MiddlewareLogger) { }

async handleRequest(
method: string,
Expand All @@ -14,6 +14,7 @@ export class GatewayService {
) {
let newheaders = {
tenantId: oheaders['tenantid'],
academicyearid: oheaders['academicyearid'],
'content-type': 'application/json',
authorization: oheaders['authorization'],
};
Expand Down

0 comments on commit be0aa30

Please sign in to comment.