How to use the tsoa.Post 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 vietnam-devs / coolstore-microservices / src / services / catalog / src / controllers / productController.ts View on Github external
/**
   * Get product by Id
   * @param productId Product Id
   */
  @Get(`{productId}`)
  public Get(productId: string): Promise {
    // @ts-ignore
    let product = Product.findOne({ _id: productId }).exec()
    return Promise.resolve(product)
  }

  /**
   * Create a product
   * @param request This is a product creation request description
   */
  @Post()
  public Create(@Body() request: ProductCreateRequest): Promise {
    let product = new Product({ _id: uuid.v1(), ...request })
    console.log(product)
    let result = Product.create(product)
    return Promise.resolve(result)
  }
}
github input-output-hk / smart-contract-backend / src / execution_engines / docker / controllers / smart-contract.ts View on Github external
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 {
      const { containerId } = await findContainerId(contractAddress)
github input-output-hk / smart-contract-backend / src / execution_engine / controllers / smart-contract.ts View on Github external
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 }
      })
  }
}

tsoa

Build swagger-compliant REST APIs using TypeScript and Node

MIT
Latest version published 16 days ago

Package Health Score

95 / 100
Full package analysis