How to use the tsoa.SuccessResponse function in tsoa

To help you get started, we’ve selected a few tsoa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github input-output-hk / smart-contract-backend / src / execution_engine / controllers / smart-contract.ts View on Github external
: NodeEngine
}

@Route('')
export class ContainerController extends Controller {
  @SuccessResponse('204', 'No Content')
  @Post('loadSmartContract')
  public async loadSmartContract (@Body() { contractAddress, executable }: LoadContractArgs): Promise {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)

    await engine.load({ contractAddress, executable })
  }

  @SuccessResponse('204', 'No Content')
  @Post('unloadSmartContract')
  public async unloadSmartContract (@Body() { contractAddress }: UnloadContractArgs): Promise {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)

    await engine.unload({ contractAddress })
  }

  @SuccessResponse('200', 'Ok')
  @Post('execute/{contractAddress}/{method}')
  public async execute (contractAddress: string, method: string, @Body() methodArguments: any): Promise<{ data: SmartContractResponse } | { error: string }> {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()

    return engine.execute({ contractAddress, method, methodArgs: methodArguments })
github input-output-hk / smart-contract-backend / src / execution_engine / controllers / smart-contract.ts View on Github external
this.setStatus(204)

    await engine.load({ contractAddress, executable })
  }

  @SuccessResponse('204', 'No Content')
  @Post('unloadSmartContract')
  public async unloadSmartContract (@Body() { contractAddress }: UnloadContractArgs): Promise {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)

    await engine.unload({ contractAddress })
  }

  @SuccessResponse('200', 'Ok')
  @Post('execute/{contractAddress}/{method}')
  public async execute (contractAddress: string, method: string, @Body() methodArguments: any): Promise<{ data: SmartContractResponse } | { error: string }> {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()

    return engine.execute({ contractAddress, method, methodArgs: methodArguments })
      .catch(e => {
        if (e instanceof ContractNotLoaded) {
          this.setStatus(404)
        } else {
          this.setStatus(500)
        }

        return { error: e.message }
      })
  }
github input-output-hk / smart-contract-backend / src / execution_engines / docker / controllers / smart-contract.ts View on Github external
} from '../docker-api'

interface LoadSmartContractRequest {
  contractAddress: string
  dockerImageRepository: string
}

interface UnloadSmartContractRequest {
  contractAddress: string
}

type SmartContractResponse = any

@Route('')
export class ContainerController extends Controller {
  @SuccessResponse('204', 'No Content')
  @Post('loadSmartContract')
  public async loadSmartContract (@Body() { contractAddress, dockerImageRepository }: LoadSmartContractRequest): Promise {
    const { CONTAINER_LOWER_PORT_BOUND, CONTAINER_UPPER_PORT_BOUND } = process.env
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)
    await loadContainer({
      contractAddress,
      dockerImageRepository,
      lowerPortBound: Number(CONTAINER_LOWER_PORT_BOUND),
      upperPortBound: Number(CONTAINER_UPPER_PORT_BOUND)
    })
  }

  @SuccessResponse('204', 'No Content')
  @Post('unloadSmartContract')
  public async unloadSmartContract (@Body() { contractAddress }: UnloadSmartContractRequest): Promise {
github input-output-hk / smart-contract-backend / src / execution_engines / docker / controllers / smart-contract.ts View on Github external
contractAddress,
      dockerImageRepository,
      lowerPortBound: Number(CONTAINER_LOWER_PORT_BOUND),
      upperPortBound: Number(CONTAINER_UPPER_PORT_BOUND)
    })
  }

  @SuccessResponse('204', 'No Content')
  @Post('unloadSmartContract')
  public async unloadSmartContract (@Body() { contractAddress }: UnloadSmartContractRequest): Promise {
    this.setStatus(204)
    contractAddress = contractAddress.toLowerCase()
    await unloadContainer(contractAddress)
  }

  @SuccessResponse('201', 'Created')
  @Post('execute/{contractAddress}/{method}')
  public async execute (contractAddress: string, method: string, @Body() methodArguments: any): Promise<{ data: SmartContractResponse } | { error: string }> {
    const { RUNTIME } = process.env
    contractAddress = contractAddress.toLowerCase()

    let contractEndpoint: string
    const containerNotFoundError = { error: 'Container not initialized. Call /loadContainer and try again' }
    if (RUNTIME !== 'docker') {
      const associatedPort = await findContainerPort(contractAddress)
      if (associatedPort === 0) {
        this.setStatus(400)
        return containerNotFoundError
      }

      contractEndpoint = `http://localhost:${associatedPort}`
    } else {
github input-output-hk / smart-contract-backend / src / execution_engines / docker / controllers / smart-contract.ts View on Github external
export class ContainerController extends Controller {
  @SuccessResponse('204', 'No Content')
  @Post('loadSmartContract')
  public async loadSmartContract (@Body() { contractAddress, dockerImageRepository }: LoadSmartContractRequest): Promise {
    const { CONTAINER_LOWER_PORT_BOUND, CONTAINER_UPPER_PORT_BOUND } = process.env
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)
    await loadContainer({
      contractAddress,
      dockerImageRepository,
      lowerPortBound: Number(CONTAINER_LOWER_PORT_BOUND),
      upperPortBound: Number(CONTAINER_UPPER_PORT_BOUND)
    })
  }

  @SuccessResponse('204', 'No Content')
  @Post('unloadSmartContract')
  public async unloadSmartContract (@Body() { contractAddress }: UnloadSmartContractRequest): Promise {
    this.setStatus(204)
    contractAddress = contractAddress.toLowerCase()
    await unloadContainer(contractAddress)
  }

  @SuccessResponse('201', 'Created')
  @Post('execute/{contractAddress}/{method}')
  public async execute (contractAddress: string, method: string, @Body() methodArguments: any): Promise<{ data: SmartContractResponse } | { error: string }> {
    const { RUNTIME } = process.env
    contractAddress = contractAddress.toLowerCase()

    let contractEndpoint: string
    const containerNotFoundError = { error: 'Container not initialized. Call /loadContainer and try again' }
    if (RUNTIME !== 'docker') {
github input-output-hk / smart-contract-backend / src / execution_engine / controllers / smart-contract.ts View on Github external
import { Post, Route, Body, SuccessResponse, Controller } from 'tsoa'
import DockerEngine from '../docker'
import NodeEngine from '../node_js'
import { LoadContractArgs, ExecutionEngine, UnloadContractArgs, SmartContractResponse, ExecutionEngines } from '../ExecutionEngine'
import { ContractNotLoaded } from '../errors'
import { getConfig, ExecutionEngineConfig } from '../config'

function getEngine (config: ExecutionEngineConfig): ExecutionEngine {
  return config.executionEngine === ExecutionEngines.docker
    ? DockerEngine
    : NodeEngine
}

@Route('')
export class ContainerController extends Controller {
  @SuccessResponse('204', 'No Content')
  @Post('loadSmartContract')
  public async loadSmartContract (@Body() { contractAddress, executable }: LoadContractArgs): Promise {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)

    await engine.load({ contractAddress, executable })
  }

  @SuccessResponse('204', 'No Content')
  @Post('unloadSmartContract')
  public async unloadSmartContract (@Body() { contractAddress }: UnloadContractArgs): Promise {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)

tsoa

Build swagger-compliant REST APIs using TypeScript and Node

MIT
Latest version published 2 days ago

Package Health Score

95 / 100
Full package analysis