@@ -4,6 +4,12 @@ const bodyParser = require('body-parser');
44module . exports = function configureRoutes ( options ) {
55 options . router . use ( bodyParser . json ( ) ) ;
66
7+ /**
8+ * sanitize the templateData attribute for runQueryByID parameter
9+ * @param templateFieldsParams
10+ * @param templateFieldsQuery
11+ * @returns {* }
12+ */
713 function sanitizeTemplateData ( templateFieldsParams , templateFieldsQuery ) {
814 templateFieldsQuery . forEach ( queryParam => {
915 if ( queryParam . type === 'nodeset' || queryParam . type === 'edgeset' ) {
@@ -13,6 +19,14 @@ module.exports = function configureRoutes(options) {
1319 return templateFieldsParams ;
1420 }
1521
22+ /**
23+ * check if the plugin configuration is valid
24+ * @param schemaTypes
25+ * @param entityType
26+ * @param itemType
27+ * @param properties
28+ * @returns {{message: string}|{message: string}|{message: string}|null|{message: string} }
29+ */
1630 function checkPluginsConfiguration ( schemaTypes , entityType , itemType , properties ) {
1731 if ( entityType && entityType !== 'node' && entityType !== 'edge' ) {
1832 return { message : 'Invalid plugin configuration “entityType” (must be “node” or “edge”)' } ;
@@ -55,7 +69,6 @@ module.exports = function configureRoutes(options) {
5569 } ) ;
5670
5771 options . router . post ( '/runQueryByIDPlugin' , async ( req , res ) => {
58- console . log ( req . body ) ;
5972 const data = {
6073 id : + req . body . queryParams . global . queryId ,
6174 sourceKey : req . body . queryParams . global . sourceKey ,
@@ -64,16 +77,16 @@ module.exports = function configureRoutes(options) {
6477 if ( req . body . query . templateFields ) {
6578 data . templateData = sanitizeTemplateData ( req . body . queryParams . templateFields , req . body . query . templateFields ) ;
6679 }
67- console . log ( data ) ;
6880 try {
6981 const queryResult = await options . getRestClient ( req ) . graphQuery . runQueryById ( data ) ;
7082 res . status ( 200 ) ;
7183 res . contentType ( 'application/json' ) ;
7284 res . send ( JSON . stringify ( queryResult ) ) ;
73- } catch ( e ) {
85+ } catch ( e ) {
7486 res . status ( 400 ) ;
7587 res . contentType ( 'application/json' ) ;
76- res . send ( JSON . stringify ( { status : 400 , body : { error : e . originalResponse . body } } ) ) ;
88+ const error = e . originalResponse . body ? e . originalResponse . body : e ;
89+ res . send ( JSON . stringify ( { status : 400 , body : { error} } ) ) ;
7790 }
7891
7992 } ) ;
@@ -87,7 +100,7 @@ module.exports = function configureRoutes(options) {
87100 res . status ( 200 ) ;
88101 res . contentType ( 'application/json' ) ;
89102 res . send ( JSON . stringify ( schemaResult ) ) ;
90- } catch ( e ) {
103+ } catch ( e ) {
91104 res . status ( 412 ) ;
92105 res . send ( JSON . stringify ( { status : 412 , body : e } ) ) ;
93106 }
0 commit comments