holidayextras/jsonapi-server

View on GitHub

Showing 54 of 94 total issues

Function applyMiddleware has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

router.applyMiddleware = () => {
  app = app || jsonApi._apiConfig.router || express()
  app.use((req, res, next) => {
    res.set({
      'Content-Type': 'application/vnd.api+json',
Severity: Minor
Found in lib/router.js - About 1 hr to fix

    Function _addBasicPaths has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    swaggerPaths._addBasicPaths = (paths, resourceName, resourceConfig) => {
      const genericPaths = { }
      const specificPaths = { }
      paths[`/${resourceName}`] = genericPaths
      paths[`/${resourceName}/{id}`] = specificPaths
    Severity: Minor
    Found in lib/swagger/paths.js - About 1 hr to fix

      Function register has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      searchRoute.register = () => {
        router.bindRoute({
          verb: 'get',
          path: ':type'
        }, (request, resourceConfig, res) => {
      Severity: Minor
      Found in lib/routes/search.js - About 1 hr to fix

        Function generatePageLinks has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        pagination.generatePageLinks = (request, handlerTotal) => {
          const pageData = request.params.page
          if (!handlerTotal || !pageData) {
            return { }
          }
        Severity: Minor
        Found in lib/pagination.js - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function iterate has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          const iterate = (text, node, filter) => {
            if (text.length === 0) return null
            const parts = text.split('.')
            const first = parts.shift()
            const rest = parts.join('.')
        Severity: Minor
        Found in lib/postProcessing/include.js - About 1 hr to fix

          Function define has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          jsonApi.define = resourceConfig => {
            if (!resourceConfig.resource.match(/^[A-Za-z0-9_]*$/)) {
              throw new Error(`Resource '${resourceConfig.resource}' contains illegal characters!`)
            }
            resourceConfig.namespace = resourceConfig.namespace || 'default'
          Severity: Minor
          Found in lib/jsonApi.js - About 1 hr to fix

            Function register has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            findRoute.register = () => {
              router.bindRoute({
                verb: 'get',
                path: ':type/:id'
              }, (request, resourceConfig, res) => {
            Severity: Minor
            Found in lib/routes/find.js - About 1 hr to fix

              Function _generateLink has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              responseHelper._generateLink = (item, schemaProperty, linkProperty) => {
                const link = {
                  meta: {
                    relation: 'primary',
                    // type: schemaProperty._settings.__many || schemaProperty._settings.__one,
              Severity: Minor
              Found in lib/responseHelper.js - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function createReadType has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              readTypes.createReadType = (resourceConfig, otherTypes, allUnionTypes) => {
                const someType = {
                  name: resourceConfig.resource,
                  description: resourceConfig.description,
                  args: filterArgs.generate(resourceConfig.resource),
              Severity: Minor
              Found in lib/graphQl/readTypes.js - About 1 hr to fix

                Function _fetchRelatedResources has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                postProcess._fetchRelatedResources = (request, mainResource, callback) => {
                  // Fetch the other objects
                  let dataItems = mainResource[request.params.relation]
                
                  if (!dataItems) return callback(null, [ null ])
                Severity: Minor
                Found in lib/postProcess.js - About 1 hr to fix

                  Function generatePageLinks has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  pagination.generatePageLinks = (request, handlerTotal) => {
                    const pageData = request.params.page
                    if (!handlerTotal || !pageData) {
                      return { }
                    }
                  Severity: Minor
                  Found in lib/pagination.js - About 1 hr to fix

                    Function parseAndValidate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                    filter.parseAndValidate = request => {
                      if (!request.params.filter) return null
                    
                      const resourceConfig = request.resourceConfig
                    
                    
                    Severity: Minor
                    Found in lib/filter.js - About 1 hr to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function simpleAttribute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                    joiConverter.simpleAttribute = joiScheme => {
                      let type = joiScheme._type
                      if (type === 'any') {
                        // { _valids: { _set: [ 'M', 'F' ] } }
                        type = typeof (joiScheme._valids._set || [ ])[0]
                    Severity: Minor
                    Found in lib/graphQl/joiConverter.js - About 1 hr to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function route has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    rerouter.route = (newRequest, callback) => {
                      const validRoutes = router._routes[newRequest.method.toLowerCase()]
                    
                      const path = rerouter._generateSanePath(newRequest)
                      const route = rerouter._pickFirstMatchingRoute(validRoutes, path)
                    Severity: Minor
                    Found in lib/rerouter.js - About 1 hr to fix

                      Function _getParams has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      router._getParams = req => {
                        let urlParts = req.url.split(jsonApi._apiConfig.base)
                        urlParts.shift()
                        urlParts = urlParts.join(jsonApi._apiConfig.base).split('?')
                      
                      
                      Severity: Minor
                      Found in lib/router.js - About 1 hr to fix

                        Function action has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        fields.action = (request, response, callback) => {
                          const resourceList = request.params.fields
                          if (!resourceList || !(resourceList instanceof Object)) return callback()
                        
                          const allDataItems = response.included.concat(response.data)
                        Severity: Minor
                        Found in lib/postProcessing/fields.js - About 1 hr to fix

                          Function generateWriteSchema has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          jsonApiGraphQL.generateWriteSchema = (allReadTypes, allResourceConfig, allWriteTypes) => {
                            const result = { }
                          
                            Object.keys(allResourceConfig).forEach(resource => {
                              const resourceConfig = allResourceConfig[resource]
                          Severity: Minor
                          Found in lib/graphQl/index.js - About 1 hr to fix

                            Function verifyRequest has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            helper.verifyRequest = (request, resourceConfig, res, handlerRequest, callback) => {
                              if (!resourceConfig) {
                                return helper.handleError(request, res, {
                                  status: '404',
                                  code: 'ENOTFOUND',
                            Severity: Minor
                            Found in lib/routes/helper.js - About 1 hr to fix

                              Function action has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                              Open

                              fields.action = (request, response, callback) => {
                                const resourceList = request.params.fields
                                if (!resourceList || !(resourceList instanceof Object)) return callback()
                              
                                const allDataItems = response.included.concat(response.data)
                              Severity: Minor
                              Found in lib/postProcessing/fields.js - About 1 hr to fix

                              Cognitive Complexity

                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                              A method's cognitive complexity is based on a few simple rules:

                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                              • Code is considered more complex for each "break in the linear flow of the code"
                              • Code is considered more complex when "flow breaking structures are nested"

                              Further reading

                              Function validate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                              Open

                              schemaValidator.validate = function (resources) {
                                Object.keys(resources).forEach(resource => {
                                  Object.keys(resources[resource].attributes).forEach(attribute => {
                                    const joiSchema = resources[resource].attributes[attribute]
                                    if (!joiSchema._settings) return
                              Severity: Minor
                              Found in lib/schemaValidator.js - About 1 hr to fix

                              Cognitive Complexity

                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                              A method's cognitive complexity is based on a few simple rules:

                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                              • Code is considered more complex for each "break in the linear flow of the code"
                              • Code is considered more complex when "flow breaking structures are nested"

                              Further reading

                              Severity
                              Category
                              Status
                              Source
                              Language