Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MongoApiHost<TDatabase, TOptions>

An API with MongoDB helper methods.

Type parameters

Hierarchy

Index

Accessors

app

  • get app(): express.Express

isRunning

  • get isRunning(): boolean

logger

root

  • get root(): express.Router

Methods

authorizer

Protected getDatabaseClass

  • getDatabaseClass(): typeof MongoDatabase
  • Returns the database class.

    Returns typeof MongoDatabase

    The class.

initialize

log

  • log(message: any, type: LogType, payload?: any): Promise<void>
  • Log something into the database. This requires a 'logs' collection, described by 'LogsDocument' interface.

    Parameters

    • message: any

      The message.

    • type: LogType

      The type.

    • Optional payload: any

    Returns Promise<void>

openDatabase

  • openDatabase(opts?: TOptions): Promise<TDatabase>
  • Options a new connection to a database.

    Parameters

    • Optional opts: TOptions

    Returns Promise<TDatabase>

    The new, opened, database.

poweredBy

  • poweredBy(): string
  • poweredBy(newValue: string): this

setBasicAuth

setPrefixedAuthorizer

  • setPrefixedAuthorizer(authorizer: TokenAuthorizer, prefix?: string): this

Protected setupApi

  • setupApi(newApp: express.Express, newRoot: express.Router): void
  • Sets up a new api / app instance.

    Parameters

    • newApp: express.Express

      The instance to setup.

    • newRoot: express.Router

      The API root.

    Returns void

Protected setupLogger

  • setupLogger(newLogger: Logger): void

start

  • start(port?: number): Promise<boolean>
  • Starts the host.

    Parameters

    • Optional port: number

    Returns Promise<boolean>

    The promise, which indicates if operation successful or not.

stop

  • stop(): Promise<boolean>
  • Stops the host.

    Returns Promise<boolean>

    The promise, which indicates if operation successful or not.

useBodyParser

useErrorHandler

withDatabase

  • withDatabase<TResult>(action: (db: TDatabase) => TResult | PromiseLike<TResult>, opts?: TOptions): Promise<TResult>
  • Opens a data connection and invokes an action for it. After invokation, the database is closed automatically.

    Type parameters

    • TResult

    Parameters

    • action: (db: TDatabase) => TResult | PromiseLike<TResult>

      The action to invoke.

        • (db: TDatabase): TResult | PromiseLike<TResult>
        • Parameters

          • db: TDatabase

          Returns TResult | PromiseLike<TResult>

    • Optional opts: TOptions

    Returns Promise<TResult>

    The promise with the result of the action.

Generated using TypeDoc