utilities/rest-helper-factory.js
function(server, model, options) {
      // TODO: generate multiple DELETE routes at /RESOURCE and at
      // TODO: /RESOURCE/{ownerId}/ASSOCIATION that take a list of Id's as a payload
      try {
        validationHelper.validateModel(model, logger)

        let collectionName = model.collectionDisplayName || model.modelName

        let Log = logger.bind(chalk.blue(collectionName))

        options = options || {}

        if (model.routeOptions.allowRead !== false) {
          this.generateListEndpoint(server, model, options, Log)
          this.generateFindEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.allowCreate !== false) {
          this.generateCreateEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.allowUpdate !== false) {
          this.generateUpdateEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.allowDelete !== false) {
          this.generateDeleteOneEndpoint(server, model, options, Log)
          this.generateDeleteManyEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.associations) {
          for (let associationName in model.routeOptions.associations) {
            let association = model.routeOptions.associations[associationName]

            if (
              association.type === 'MANY_MANY' ||
              association.type === 'ONE_MANY' ||
              association.type === '_MANY'
            ) {
              if (association.allowAdd !== false) {
                this.generateAssociationAddOneEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
                this.generateAssociationAddManyEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
              }
              if (association.allowRemove !== false) {
                this.generateAssociationRemoveOneEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
                this.generateAssociationRemoveManyEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
              }

              if (association.allowRead !== false) {
                this.generateAssociationGetAllEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
              }
            }
          }
        }

        if (model.routeOptions && model.routeOptions.extraEndpoints) {
          for (let extraEndpointIndex in model.routeOptions.extraEndpoints) {
            let extraEndpointFunction =
              model.routeOptions.extraEndpoints[extraEndpointIndex]

            extraEndpointFunction(server, model, options, Log)
          }
        }
      } catch (error) {
        logger.error('Error:', error)
        throw error
      }
    }
function(server, model, options) {
      // TODO: generate multiple DELETE routes at /RESOURCE and at
      // TODO: /RESOURCE/{ownerId}/ASSOCIATION that take a list of Id's as a payload
      try {
        validationHelper.validateModel(model, logger)

        let collectionName = model.collectionDisplayName || model.modelName

        let Log = logger.bind(chalk.blue(collectionName))

        options = options || {}

        if (model.routeOptions.allowRead !== false) {
          this.generateListEndpoint(server, model, options, Log)
          this.generateFindEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.allowCreate !== false) {
          this.generateCreateEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.allowUpdate !== false) {
          this.generateUpdateEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.allowDelete !== false) {
          this.generateDeleteOneEndpoint(server, model, options, Log)
          this.generateDeleteManyEndpoint(server, model, options, Log)
        }

        if (model.routeOptions.associations) {
          for (let associationName in model.routeOptions.associations) {
            let association = model.routeOptions.associations[associationName]

            if (
              association.type === 'MANY_MANY' ||
              association.type === 'ONE_MANY' ||
              association.type === '_MANY'
            ) {
              if (association.allowAdd !== false) {
                this.generateAssociationAddOneEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
                this.generateAssociationAddManyEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
              }
              if (association.allowRemove !== false) {
                this.generateAssociationRemoveOneEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
                this.generateAssociationRemoveManyEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
              }

              if (association.allowRead !== false) {
                this.generateAssociationGetAllEndpoint(
                  server,
                  model,
                  association,
                  options,
                  Log
                )
              }
            }
          }
        }

        if (model.routeOptions && model.routeOptions.extraEndpoints) {
          for (let extraEndpointIndex in model.routeOptions.extraEndpoints) {
            let extraEndpointFunction =
              model.routeOptions.extraEndpoints[extraEndpointIndex]

            extraEndpointFunction(server, model, options, Log)
          }
        }
      } catch (error) {
        logger.error('Error:', error)
        throw error
      }
    }
function ( server , model , options ) { // TODO: generate multiple DELETE routes at /RESOURCE and at // TODO: /RESOURCE/{ownerId}/ASSOCIATION that take a list of Id's as a payload try { validationHelper . validateModel ( model , logger ) let collectionName = model . collectionDisplayName || model . modelName let Log = logger . bind ( chalk . blue ( collectionName ) ) options = options || { } if ( model . routeOptions . allowRead !== false ) { this . generateListEndpoint ( server , model , options , Log ) this . generateFindEndpoint ( server , model , options , Log ) } if ( model . routeOptions . allowCreate !== false ) { this . generateCreateEndpoint ( server , model , options , Log ) } if ( model . routeOptions . allowUpdate !== false ) { this . generateUpdateEndpoint ( server , model , options , Log ) } if ( model . routeOptions . allowDelete !== false ) { this . generateDeleteOneEndpoint ( server , model , options , Log ) this . generateDeleteManyEndpoint ( server , model , options , Log ) } if ( model . routeOptions . associations ) { for ( let associationName in model . routeOptions . associations ) { let association = model . routeOptions . associations [ associationName ] if ( association . type === 'MANY_MANY' || association . type === 'ONE_MANY' || association . type === '_MANY' ) { if ( association . allowAdd !== false ) { this . generateAssociationAddOneEndpoint ( server , model , association , options , Log ) this . generateAssociationAddManyEndpoint ( server , model , association , options , Log ) } if ( association . allowRemove !== false ) { this . generateAssociationRemoveOneEndpoint ( server , model , association , options , Log ) this . generateAssociationRemoveManyEndpoint ( server , model , association , options , Log ) } if ( association . allowRead !== false ) { this . generateAssociationGetAllEndpoint ( server , model , association , options , Log ) } } } } if ( model . routeOptions && model . routeOptions . extraEndpoints ) { for ( let extraEndpointIndex in model . routeOptions . extraEndpoints ) { let extraEndpointFunction = model . routeOptions . extraEndpoints [ extraEndpointIndex ] extraEndpointFunction ( server , model , options , Log ) } } } catch ( error ) { logger . error ( 'Error:' , error ) throw error } }
Generates the restful API endpoints for a single model.
@param server: A Hapi server.
@param model: A mongoose model.
@param options: options object.
Generates the restful API endpoints for a single model .