How to use the @tsed/common.Controller function in @tsed/common

To help you get started, we’ve selected a few @tsed/common 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 replicatedhq / kots / api / src / controllers / kots / KotsAPI.ts View on Github external
interface CreateAppBody {
  metadata: string;
}

interface UploadLicenseBody {
  name: string;
  license: string;
  appSlug: string;
}

interface UpdateAppBody {
  slug: string;
}

@Controller("/api/v1/kots")
export class KotsAPI {
  @Get("/ports")
  async kotsPorts(
    @Req() request: Request,
    @Res() response: Response,
  ): Promise {
    // This method is connected to over kubectl...
    // There is no user auth, but this method should be
    // exposed only on cluster ip to enforce that it's
    // not exposed to the public

    const kotsAppStore: KotsAppStore = request.app.locals.stores.kotsAppStore;

    const apps = await kotsAppStore.listInstalledKotsApps();
    if (apps.length === 0) {
      return [];
github TypedProject / ts-express-decorators / test / integration / app / controllers / products / ProductsCtrl.ts View on Github external
import {BodyParams, Controller, Get, Post, Scope} from "@tsed/common";
import {Docs, Hidden} from "@tsed/swagger";
import {$log} from "ts-log-debug";
import {CalendarModel} from "../../models/Calendar";
import {AdminProductPostModel, UserProductPostModel} from "../../models/Product";
import {InnerService} from "../../services/InnerService";
import {OuterService} from "../../services/OuterService";

@Controller("/products")
@Scope("request")
@Hidden()
@Docs("hidden")
export class ProductsCtrl {
  constructor(public innerService: InnerService, public outerService: OuterService) {
    $log.debug("Controller New Instance");
    $log.debug("innerService == outerService.innerService? ", innerService === outerService.innerService);
  }

  @Get("/")
  async renderCalendars(): Promise {
    return [{id: "1", name: "test"}];
  }

  $onDestroy() {
    $log.debug("Destroy controller");
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
import {TokenService} from "../../services/TokenService";
import {BaseController} from "../base/BaseController";
import {EventCtrl} from "./EventCtrl";

interface ICalendar {
  id: string;
  name: string;
}

/**
 * Add @ControllerProvider annotation to declare your provide as Router controller. The first param is the global path for your controller.
 * The others params is the children controllers.
 *
 * In this case, EventCtrl is a depedency of CalendarCtrl. All routes of EventCtrl will be mounted on the `/calendars` path.
 */
@Controller("/calendars", EventCtrl)
@Description("Controller description")
export class CalendarCtrl extends BaseController {
  constructor(private tokenService: TokenService) {
    super(tokenService);
  }

  /**
   *
   * @param request
   * @param response
   * @param next
   */
  static middleware(request: any, response: Express.Response, next: Express.NextFunction) {
    request["user"] = 1;
    response.locals.id = "local-10909";
    request.ctx.set("uid", "ctx-10909");
github TypedProject / ts-express-decorators / docs / docs / snippets / middlewares / call-sequences.ts View on Github external
import {Controller, Get, Next, Use, UseAfter, UseBefore, UseBeforeEach} from "@tsed/common";

@Controller("/")
@UseAfter(MdlwCtrlAfter)
@UseBefore(MdlwCtrlBefore)
@UseBeforeEach(MdlwCtrlBeforeEach)
@Use(MdlwCtrl)
export class MyCtrl {

  @Get("/")
  @UseBefore(MdlwBefore)
  @Use(Mdlw)
  @UseAfter(MdlwAfter)
  endpointA(@Next() next: Next) {
    console.log("EndpointA");
    next();
  }

  @Get("/")
github replicatedhq / kots / kotsadm / api / src / controllers / CrashzAPI.ts View on Github external
import { Controller, Get } from "@tsed/common";

@Controller("/crashz")
export class CrashzAPI {
  @Get("")
  async crashIntentionally() {
    throw new Error("Crashz!");
  }
}
github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / server / src / controllers / HelloWorldCtrl.ts View on Github external
import {$log, BodyParams, Controller, Get, Head, Post} from "@tsed/common";
import {OAuthBearer} from "../decorators/OAuthBearer";
import {OAuthParams} from "../decorators/OAuthParams";
import {OAuthHead} from "../decorators/OAuthHead";

@Controller("/rest")
export class HelloWorldCtrl {

  @Get("/hello-auth-world")
  @OAuthBearer({"scopes": ["tester"]})
  helloAuthScopesWorld(@OAuthParams("scopes") scopes: string[]) {

    $log.info({event: "helloAuthScopesWorld", scopes});

    return {text: "hello world with scopes"};
  }

  @Get("/hello-auth-world-no-scope")
  @OAuthBearer()
  helloAuthNoScopesWorld(@OAuthParams("scopes") scopes: string[]) {

    $log.info({event: "helloAuthNoScopesWorld", scopes});
github TypedProject / ts-express-decorators / integration / typeorm / src / controllers / users / UsersCtrl.ts View on Github external
import {BodyParams, Controller, Get, Post} from "@tsed/common";
import {ReturnsArray} from "@tsed/swagger";
import {User} from "../../entity/User";
import {UsersService} from "../../services/UsersService";

@Controller("/users")
export class UsersCtrl {

  constructor(private usersService: UsersService) {
  }

  @Post("/")
  create(@BodyParams() user: User): Promise {
    return this.usersService.create(user);
  }

  @Get("/")
  @ReturnsArray(User)
  async getList(): Promise {
    return this.usersService.find();
  }
}
github TypedProject / ts-express-decorators / integration / session / src / controllers / RestCtrl.ts View on Github external
import {$log, BodyParams, Controller, Get, Post, Session, Status} from "@tsed/common";

@Controller("/")
export class RestCtrl {

  @Get("/whoami")
  whoAmI(@Session() session: any) {
    $log.info("User in session =>", session.user);
    return session.user && session.user.id ? `Hello user ${session.user.name}` : "Hello world";
  }

  @Post("/login")
  @Status(204)
  login(@BodyParams("name") name: string, @Session("user") user: any) {
    user.id = "1";
    user.name = name;
  }

  @Post("/logout")
github TypedProject / ts-express-decorators / examples / aws / src / controllers / calendars / CalendarsCtrl.ts View on Github external
import {BodyParams, Controller, Delete, Get, PathParams, Post, Put, Required, Status} from "@tsed/common";
import {NotFound} from "ts-httpexceptions";
import {Calendar} from "../../interfaces/Calendar";
import {CalendarsService} from "../../services/calendars/CalendarsService";
import {EventsCtrl} from "../events/EventsCtrl";

/**
 * Add @Controller annotation to declare your class as Router controller.
 * The first param is the global path for your controller.
 * The others params is the controller dependencies.
 *
 * In this case, EventsCtrl is a dependency of CalendarsCtrl.
 * All routes of EventsCtrl will be mounted on the `/calendars` path.
 */
@Controller("/calendars", EventsCtrl)
export class CalendarsCtrl {

  constructor(private calendarsService: CalendarsService) {

  }

  @Get("/:id")
  async get(@Required() @PathParams("id") id: string): Promise {

    const calendar = await this.calendarsService.find(id);

    if (calendar) {
      return calendar;
    }

    throw new NotFound("Calendar not found");
github replicatedhq / kots / kotsadm / api / src / controllers / titled / LicenseAPI.ts View on Github external
import Express from "express";
import {
  BodyParams,
  Controller,
  Get,
  Req,
  Res,
  Any,
} from "@tsed/common";
import yaml from "js-yaml";
import * as _ from "lodash";

@Controller("/license/v1")
export class LicenseAPI {
  @Get("/license")
  public async license(
    @Res() response: Express.Response,
    @Req() request: Express.Request,
    @BodyParams("") body: any,
  ): Promise {
    const apps = await request.app.locals.stores.kotsAppStore.listInstalledKotsApps();
    if (_.size(apps) === 0) {
      response.status(404);
      return {};
    }

    if (_.size(apps) > 1) {
      response.status(400);
      return {};