Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
declare var require: any
var uuid = require('uuid')
import { Route, Get, Post, Put, Body, Response } from 'tsoa'
import { default as Rating, RatingCreateRequest, RatingUpdateRequest } from '../models/rating'
@Route(`api/ratings`)
export class RatingController {
/**
* Get the all ratings
*/
@Get()
public async GetAll(): Promise {
// @ts-ignore
var ratings = await Rating.find({}).exec()
var result = []
ratings.reduce(function (res, value) {
if (!res[value.productId]) {
res[value.productId] = {
productId: value.productId,
cost: 0,
userId: value.userId,
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()
import {Get, Route} from 'tsoa';
import swaggerJson from '../swagger.json';
@Route('spec')
export class SpecController {
/** Get the current spec */
@Get()
async currentSpec() {
return swaggerJson;
}
}
export interface IWidget {
id: number;
label: string;
color: string;
}
const widgets: IWidget[] = [
{
color: "blue",
id: 1,
label: "first widget",
},
];
@Route("widgets")
export class WidgetsController {
@Get()
@Tags("Widgets")
public async GetWidgets(): Promise {
return widgets;
}
@Get("{widgetId}")
@Tags("Widgets")
public async GetWidget(widgetId: number): Promise {
const widget = widgets.find((w) => w.id === widgetId);
if (!widget) {
throw new ServerError(`no widget found with id ${widgetId}`);
}
return widget;