diff --git a/src/common/middleware/apiConfig.ts b/src/common/middleware/apiConfig.ts index 3e91d2c..8253e68 100644 --- a/src/common/middleware/apiConfig.ts +++ b/src/common/middleware/apiConfig.ts @@ -492,11 +492,22 @@ export const apiList = { //sunbird knowlg and inQuiry service //public + '/api/question/v2/list': createRouteObject({ post: {} }, '/question/v5/list'), '/action/questionset/v2/read/:identifier': createRouteObject( { get: {} }, '/questionset/v5/read/:identifier', ), + // added update one before any identifier + '/action/questionset/v2/hierarchy/update': createRouteObject( + { + patch: { + PRIVILEGE_CHECK: privilegeGroup.content.update, + ROLE_CHECK: rolesGroup.content_restricted, + }, + }, + '/questionset/v5/hierarchy/update', + ), '/action/questionset/v2/hierarchy/:identifier': createRouteObject( { get: {} }, '/questionset/v5/hierarchy/:identifier', @@ -514,6 +525,10 @@ export const apiList = { '/framework/v3/read/:identifier', ), '/action/composite/v3/search': createRouteObject({ post: {} }, '/v3/search'), + '/action/object/category/definition/v1/read': createRouteObject( + { post: {} }, + '/object/category/definition/v4/read', + ), //secure '/action/questionset/v2/create': createRouteObject( { @@ -560,15 +575,7 @@ export const apiList = { }, '/questionset/v5/retire/:identifier', ), - '/action/questionset/v2/hierarchy/update': createRouteObject( - { - patch: { - PRIVILEGE_CHECK: privilegeGroup.content.update, - ROLE_CHECK: rolesGroup.content_restricted, - }, - }, - '/questionset/v5/hierarchy/update', - ), + '/action/questionset/v2/reject/:identifier': createRouteObject( { post: { @@ -614,7 +621,6 @@ export const apiList = { }, }), }; -console.log('api list', JSON.stringify(apiList, null, 2)); export const urlPatterns = Object.keys(apiList); //add public api @@ -627,6 +633,7 @@ export const publicAPI = [ '/api/channel/v1/read/:identifier', '/api/framework/v1/read/:identifier', '/action/composite/v3/search', + '/action/object/category/definition/v1/read', ]; function convertToRegex(pattern) { diff --git a/src/common/middleware/middleware.service.ts b/src/common/middleware/middleware.service.ts index 4ad9ac7..00ab4cd 100644 --- a/src/common/middleware/middleware.service.ts +++ b/src/common/middleware/middleware.service.ts @@ -50,7 +50,6 @@ export class MiddlewareServices { // check API is whitelisted if (apiList[reqUrl]) { if (!apiList[reqUrl][req.method.toLowerCase()]) { - console.log('not whitelist'); throw new HttpException( 'SHIKSHA_API_WHITELIST: URL not whitelisted', HttpStatus.FORBIDDEN, @@ -62,7 +61,6 @@ export class MiddlewareServices { ); let checksToExecute = []; // Iterate for checks defined for API and push to array - //console.log('req', req); apiList[reqUrl][req.method.toLowerCase()].checksNeeded?.forEach( (CHECK) => { checksToExecute.push( @@ -118,7 +116,8 @@ export class MiddlewareServices { //replace forwardUrl if redirectUrl present //check for dynamic url const originalUrl = req.originalUrl; - let reqUrl = originalUrl.split('?')[0]; + let temp = originalUrl.split('?'); + let reqUrl = temp[0]; const withPattern = this.matchUrl(reqUrl); reqUrl = withPattern || reqUrl; if (apiList[reqUrl]?.redirectUrl) { @@ -132,6 +131,9 @@ export class MiddlewareServices { } else { forwardUrl = apiList[reqUrl].redirectUrl; } + if (temp[1]) { + forwardUrl = forwardUrl + '?' + temp[1]; + } } const config = { method: req.method, @@ -164,6 +166,7 @@ export class MiddlewareServices { '/api/channel': 'CONTENT_SERVICE', '/api/framework': 'TAXONOMY_SERVICE', '/action/composite': 'SEARCH_SERVICE', + '/action/object': 'TAXONOMY_SERVICE', }; // Iterate over the mapping to find the correct service based on the URL prefix @@ -324,7 +327,6 @@ export class MiddlewareServices { try { if (checksToExecute.length == 0) { const response = await this.forwardRequest(req, res); - //console.log('response in middleware', response); return res.json(response); } await Promise.allSettled(checksToExecute).then( diff --git a/src/middleware/gateway.service.ts b/src/middleware/gateway.service.ts index 3f96a5a..d4280ae 100644 --- a/src/middleware/gateway.service.ts +++ b/src/middleware/gateway.service.ts @@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common'; import axios from 'axios'; import { MiddlewareLogger } from 'src/common/loggers/logger.service'; - @Injectable() export class GatewayService { constructor(private readonly middlewareLogger: MiddlewareLogger) {} @@ -12,34 +11,33 @@ export class GatewayService { url: string, body: Object, oheaders: any, - ){ + ) { let newheaders = { tenantId: oheaders['tenantid'], 'content-type': 'application/json', - authorization: oheaders['authorization'] - } + authorization: oheaders['authorization'], + }; try { - const response = await axios( - { - method, - url, - data :body, - headers: newheaders - }); - return response.data + const response = await axios({ + method, + url, + data: body, + headers: newheaders, + }); + return response.data; } catch (error) { if (error.response) { return error.response.data; } else if (error.request) { // No response was received return { - result : {}, - params : { - "err": "Internal server error", - "errmsg": "Internal server error", - "status": "failed" - } - } + result: {}, + params: { + err: 'Internal server error', + errmsg: 'Internal server error', + status: 'failed', + }, + }; } else { // Error occurred in setting up the request return error.message;