How to use the @tsed/common.Get 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 TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
* By default, the response is sent with status 200 and is serialized in JSON.
   *
   * @param request
   * @param response
   * @returns {{id: any, name: string}}
   */
  @Get("/classic/:id")
  public findClassic(request: any, response: any): CalendarModel {
    const model = new CalendarModel();
    model.id = request.params.id;
    model.name = "test";

    return model;
  }

  @Get("/token")
  public getToken(@CookiesParams("authorization") authorization: string): string {
    if (authorization) {
      const token = this.tokenService.token();

      return token;
      // console.log('TOKEN', this.tokenService, token);
    }

    return "";
  }

  @Get("/token/:token")
  public updateToken(
    @PathParams("token")
    @Description("Token required to update token")
      token: string
github TypedProject / ts-express-decorators / test / integration / app / controllers / responses / ResponseScenarioCtrl.ts View on Github external
return {
      "id": 1
    };
  }

  @Get("/scenario6")
  testScenario6Observable() {
    return of({"id": 1});
  }

  @Get("/scenario6b")
  async testScenario6bObservable() {
    return of({"id": 1});
  }

  @Get("/scenario7")
  @ContentType("application/json")
  testScenario7Stream() {
    return createReadStream(join(__dirname, "data/data.json"));
  }

  @Get("/scenario7b")
  @ContentType("application/json")
  async testScenario7bStream() {
    return createReadStream(join(__dirname, "data/data.json"));
  }

  @Get("/scenario8")
  testScenario8Middleware() {

    return (req: Req, res: Res, next: Next) => {
      res.json({"id": 1});
github TypedProject / ts-express-decorators / test / integration / app / controllers / base / BaseController.ts View on Github external
constructor(protected entriesService: any) {}

  @Get("/:resources/test/:id")
  @Summary("Return an element by his resource")
  async getTest(
    @Description("The resource")
    @PathParams("resources")
    resources: string,
    @Description("Id of the resource")
    @PathParams("id")
    id: string
  ): Promise {
    return {_id: id};
  }

  @Get("/list")
  @Summary("Return all elements from a service")
  async index(): Promise {
    return [{_id: "test"}];
  }
}
github TypedProject / ts-express-decorators / test / integration / app / controllers / responses / ResponseScenarioCtrl.ts View on Github external
@Get("/scenario4/:id")
  async testScenario4Assert(@PathParams("id") id: number, @Req() request: Req, @Next() next: Next) {
    await new Promise(resolve => {
      setTimeout(resolve, 100);
    });

    request.ctx.test = "value";
    next();
  }

  @Get("/scenario4/:id")
  public testScenario4Get(@PathParams("id") id: number, @Req() request: Req) {
    return id + request.ctx.test;
  }

  @Get("/scenario5")
  async testScenario5Promise() {
    await new Promise(resolve => {
      setTimeout(resolve, 100);
    });

    return {
      "id": 1
    };
  }

  @Get("/scenario6")
  testScenario6Observable() {
    return of({"id": 1});
  }

  @Get("/scenario6b")
github TypedProject / ts-express-decorators / test / integration / app / controllers / pages / SocketPageCtrl.ts View on Github external
import {ContentType, Controller, Get, Render} from "@tsed/common";
import {Hidden} from "@tsed/swagger";
import * as fs from "fs";

@Controller("/")
@Hidden()
export class SocketPageCtrl {
  @Get("/socket")
  @Render("socket")
  public socket() {
    return {socketScript: "/socket/socket.io.js"};
  }

  @Get("/socket/socket.io.js")
  @ContentType("application/javascript")
  public getScript() {
    return fs.readFileSync(require.resolve("socket.io-client/dist/socket.io.js"), {encoding: "utf8"});
  }
}
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / EventCtrl.ts View on Github external
}

  /**
   *
   * @returns {null}
   */
  @Delete("/:id")
  remove(): Promise | void {
    return Promise.resolve(null);
  }

  /**
   *
   * @returns {null}
   */
  @Get("/status")
  byStatus(@QueryParams("status", String) status: string[]): Promise | void {
    return Promise.resolve(status);
  }

  /**
   *
   * @returns {null}
   */
  @Get("/")
  query(): Promise | void {
    return Promise.resolve([
      {id: "1"},
      {id: "2"}
    ]);
  }
}
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / EventCtrl.ts View on Github external
@BodyParams()
      event: EventModel
  ): EventModel {
    if (event.id === "0" || event.id === "") {
      throw new NotFound("Not found");
    }

    return event;
  }

  /**
   *
   * @param response
   * @returns {null}
   */
  @Get("/:id")
  find(@Response() response: any): Promise | void {
    response.send(200, "OK");

    return Promise.resolve(null);
  }

  /**
   *
   * @returns {null}
   */
  @Put("/:id")
  save(@BodyParams() event: EventModel): Promise | void {
    event.id = "1";

    return Promise.resolve(event);
  }
github replicatedhq / kots / api / src / controllers / ship / WatchDownloadAPI.ts View on Github external
import Express from "express";
import { Controller, Get, PathParams, Res, Req } from "@tsed/common";

@Controller("/api/v1/download")
export class WatchDownloadAPI {
  @Get("/:watchId")
  async downloadDeploymentYAML(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @PathParams("watchId") watchId: string
  ): Promise {
    const watch = await response.locals.context.getWatch(watchId);

    const { filename, contents, contentType } = await request.app.locals.stores.watchDownload.downloadDeploymentYAML(watch);

    response.setHeader("Content-Disposition", `attachment; filename=${filename}`);
    response.setHeader("Content-Type", contentType);
    response.send(contents);
  }

  @Get("/:watchId/:sequence")
  async downloadDeploymentYAMLForSequence(
github TypedProject / ts-express-decorators / examples / aws / src / controllers / calendars / CalendarsCtrl.ts View on Github external
/**
 * 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");
  }

  @Put("/")
  save(@BodyParams("name") name: string) {
    return this.calendarsService.create(name);
  }
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 {};
    }