How to use the @tsed/common.Put 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 / kotsadm / api / src / controllers / kots / AppStatusAPI.ts View on Github external
import Express from "express";
import { Controller, Put, Res, Req, HeaderParams, BodyParams } from "@tsed/common";
import BasicAuth from "basic-auth";
import { KotsAppStatusStore } from "../../kots_app/kots_app_status_store";

interface ErrorResponse {
  error: {};
}

@Controller("/api/v1/appstatus")
export class AppStatusAPI {
  @Put("/")
  async putAppStatus(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @HeaderParams("Authorization") auth: string,
    @BodyParams("") body: any,
  ): Promise {
    const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);

    try {
      await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
    } catch (err) {
      // TODO error type
      response.status(401);
      return;
    }
github replicatedhq / kots / kotsadm / api / src / controllers / kots / DeployAPI.ts View on Github external
import { BodyParams, Controller, Get, HeaderParams, Put, Req, Res } from "@tsed/common";
import BasicAuth from "basic-auth";
import Express from "express";
import _ from "lodash";

interface ErrorResponse {
  error: {};
}

@Controller("/api/v1/deploy")
export class DeployAPI {
  @Put("/result")
  async putDeployResult(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @HeaderParams("Authorization") auth: string,
    @BodyParams("") body: any,
  ): Promise {
    const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);

    let cluster;
    try {
      cluster = await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
    } catch (err) {
      // TODO error type
      response.status(401);
      return {};
    }
github replicatedhq / kots / kotsadm / api / src / controllers / kots / RestoreAPI.ts View on Github external
import { BodyParams, Controller, Get, HeaderParams, Put, Req, Res } from "@tsed/common";
import BasicAuth from "basic-auth";
import Express from "express";
import { KotsAppStore, UndeployStatus } from "../../kots_app/kots_app_store";
import { ClusterStore } from "../../cluster";
import { logger } from "../../server/logger";

interface ErrorResponse {
  error: {};
}

@Controller("/api/v1/undeploy")
export class RestoreAPI {
  @Put("/result")
  async putUndeployResult(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @HeaderParams("Authorization") auth: string,
    @BodyParams("") body: any,
  ): Promise {
    const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);

    let cluster;
    try {
      cluster = await (request.app.locals.stores.clusterStore as ClusterStore).getFromDeployToken(credentials.pass);
    } catch (err) {
      // TODO error type
      response.status(401);
      return {};
    }
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
resolve(model);
    });
  }

  @Get("/query")
  public getQuery(@QueryParams("search") search: string, @Request() request: any): string {
    return search || "EMPTY";
  }

  /**
   *
   * @param auth
   * @param name
   * @returns {{id: number, name: string}}
   */
  @Put("/")
  @Returns(CalendarModel)
  public save(
    @BodyParams("name")
    @Required()
      name: string
  ): CalendarModel {
    const model = new CalendarModel();
    model.id = "2";
    model.name = "test";

    return model;
  }

  @Delete("/")
  @Status(204)
  @Authenticated({role: "admin"})
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / EventCtrl.ts View on Github external
*
   * @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);
  }

  /**
   *
   * @param event
   * @returns {null}
   */
  @Post("/list")
  @Authenticated({role: "admin"})
  @Returns(200, {use: EventModel, collection: Array})
  update(@BodyParams("event", EventModel) event: EventModel[]): EventModel[] {
    return event;
github TypedProject / ts-express-decorators / examples / multer / src / controllers / upload / UploadCtrl.ts View on Github external
import {Controller, Put, Status} from "@tsed/common";
import {MulterOptions, MultipartFile} from "@tsed/multipartfiles";
import {Responses} from "@tsed/swagger";

@Controller("/upload")
export class UploadController {

  constructor() {
  }

  @Put("/")
  @Status(201)
  @Responses("201", {description: "Created"})
  @Responses("400", {description: "Bad Request"})
  @MulterOptions({dest: `${process.cwd()}/.tmp`})
  async add(@MultipartFile("file") file: Express.Multer.File): Promise {

    console.log("file: ", file);

    return true;
  }
}
github replicatedhq / kots / api / src / controllers / kots / KotsAPI.ts View on Github external
});

      if (!cluster) {
        continue;
      }

      await request.app.locals.stores.kotsAppStore.createDownstream(kotsApp.id, downstream, cluster.id);
      await request.app.locals.stores.kotsAppStore.createDownstreamVersion(kotsApp.id, 0, cluster.id, installationSpec.versionLabel, "deployed", "Kots Install", "", "", false);
    }

    return {
      uri: `${params.shipApiEndpoint}/app/${kotsApp.slug}`,
    };
  }

  @Put("/")
  async kotsUploadUpdate(
    @MultipartFile("file") file: Express.Multer.File,
    @BodyParams("") body: CreateAppBody,
    @Req() request: Request,
  ): Promise {
    const metadata = JSON.parse(body.metadata);
    const buffer = fs.readFileSync(file.path);
    const stores = request.app.locals.stores;

    return uploadUpdate(stores, metadata.slug, buffer, "Kots Upload");
  }

  @Post("/airgap")
  async kotsUploadAirgap(
    @MultipartFile("file") file: Express.Multer.File,
    @BodyParams("") body: any,
github TypedProject / ts-express-decorators / examples / mongoose / src / controllers / events / EventsCtrl.ts View on Github external
@Summary("Get an event from his ID")
  @Status(200, {description: "Success"})
  async get(@Description("The event id")
            @PathParams("id") id: string): Promise {
    return this.calendarEventsService
      .find(id)
      .catch((err) => {
        throw new NotFound("Event not found");
      });
  }

  /**
   *
   * @returns {null}
   */
  @Put("/")
  @UseBefore(CheckCalendarIdMiddleware)
  @Summary("Create an event")
  @Status(201, {description: "Created"})
  async save(@Description("The calendar id of the event")
             @Required() @PathParams("calendarId") calendarId: string,
             @BodyParams() calendarEvent: CalendarEvent): Promise {

    calendarEvent.calendarId = calendarId;

    return this.calendarEventsService.save(calendarEvent);
  }

  /**
   *
   * @returns {null}
   */
github TypedProject / ts-express-decorators / examples / passportjs / src / controllers / calendars / CalendarCtrl.ts View on Github external
}

  @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);
  }

  /**
   *
   * @param id
   * @param name
   * @returns {Promise}
   */
  @Post("/:id")
  async update(@PathParams("id") @Required() id: string,
               @BodyParams("name") @Required() name: string): Promise {
    return this.calendarsService.update({id, name});
  }
github TypedProject / ts-express-decorators / examples / mongoose / src / controllers / calendars / CalendarsCtrl.ts View on Github external
const calendar = await this.calendarsService.find(id);

    if (calendar) {
      return calendar;
    }

    throw new NotFound("Calendar not found");
  }

  /**
   *
   * @param {Calendar} calendar
   * @returns {Promise}
   */
  @Put("/")
  @Summary("Create a new Calendar")
  @Status(201, {description: "Created", type: Calendar})
  save(@Description("Calendar model")
       @BodyParams() calendar: Calendar) {
    return this.calendarsService.save(calendar);
  }

  /**
   *
   * @param id
   * @param calendar
   * @returns {Promise}
   */
  @Post("/:id")
  @Summary("Update calendar information")
  @Status(200, {description: "Success", type: Calendar})