How to use the @tsed/common.Post 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 / ship / GitHubHookAPI.ts View on Github external
import WebhooksApi from "@octokit/webhooks";
import jwt from "jsonwebtoken";
import { Cluster } from "../../cluster";
import { Watch } from "../../watch"
import * as _ from "lodash";

interface ErrorResponse {
  error: {};
}

/**
 *  gets hooks from github
 */
@Controller("api/v1/hooks/github")
export class GitHubHookAPI {
  @Post("")
  async githubHook(
    @Res() response: Express.Response,
    @Req() request: Express.Request,
    @HeaderParams("x-github-event") eventType: string,
    @BodyParams("") body?: { action?: string }, // we're just gonna cast this later
  ): Promise<{} | ErrorResponse> {
    logger.info({msg: `received github hook for eventType ${eventType}`});

    switch (eventType) {
      case "pull_request": {
        await this.handlePullRequest(request, body as WebhooksApi.WebhookPayloadPullRequest);
        await this.createGithubCheck(request, body as WebhooksApi.WebhookPayloadPullRequest);
        response.status(204);
        return {};
      }
github replicatedhq / kots / api / src / controllers / kots / KotsAPI.ts View on Github external
} catch(err) {
        await request.app.locals.stores.kotsAppStore.setUpdateDownloadStatus(String(err), "failed");
        throw err;
      } finally {
        liveness.stop();
      }
    }
    downloadUpdates(); // download asyncronously

    response.status(200);
    return {
      updatesAvailable: updatesAvailable.length,
    };
  }

  @Post("/license")
  async kotsUploadLicense(
    @BodyParams("") body: UploadLicenseBody,
    @Req() request: Request,
    @Res() response: Response,
    @HeaderParams("Authorization") auth: string,
  ): Promise {

    // Intentionally not processing registry settings here because empty strings don't
    // necessarily mean existing info should be deleted.

    const session: Session = await request.app.locals.stores.sessionStore.decode(auth);
    if (!session || !session.userId) {
      response.status(401);
      return {};
    }
github replicatedhq / kots / kotsadm / api / src / controllers / troubleshoot / TroubleshootAPI.ts View on Github external
// Check if bundle exists
    const exists = await stores.troubleshootStore.supportBundleExists(supportBundleId);
    if (!exists) {
      response.send(404, "Bundle does not exist");
      return;
    }

    const b = await stores.troubleshootStore.getSupportBundle(supportBundleId);
    const analyzers = await stores.troubleshootStore.tryGetAnalyzersForKotsApp(b.watchId);
    await performAnalysis(supportBundleId, analyzers, stores);
    const analyzedBundle = await stores.troubleshootStore.getSupportBundle(supportBundleId);

    response.send(200, analyzedBundle);
  }

  @Post("/:watchId/:supportBundleId")
  public async bundleUploaded(
    @Res() response: Response,
    @Req() request: Request,
    @BodyParams("") body: BundleUploadedBody,
    @PathParams("watchId") watchId: string,
    @PathParams("supportBundleId") supportBundleId: string,
  ): Promise {
    const stores = request.app.locals.stores;

    // Don't create support bundle if there is one with the same ID
    const exists = await stores.troubleshootStore.supportBundleExists(supportBundleId);
    if (exists) {
      response.send(403);
      return;
    }
github TypedProject / ts-express-decorators / test / integration / app / controllers / users / UserCtrl.ts View on Github external
userId: string;

  constructor(public userService: UserService) {}

  @Post("/connect")
  @Status(204)
  async connect(@Session() session: Express.Session, @BodyParams("user") user: User) {
    session.user = user;
  }

  @Get("/get-connected")
  async getConnected(@Session("user") user: User): Promise {
    return user;
  }

  @Post("/")
  @Status(201)
  async createUser(@BodyParams() userData: User) {
    return await this.userService.create(userData);
  }

  @Get("/:user")
  async testPerRequest(@PathParams("user") userId: string): Promise {
    this.userService.user = userId;
    this.userId = userId;

    return new Promise((resolve, reject) => {
      if (userId === "0") {
        setTimeout(() => {
          resolve({userId, idSrv: this.userService.user, idCtrl: this.userId});
        }, 500);
      }
github TypedProject / ts-express-decorators / test / integration / app / controllers / users / UserCtrl.ts View on Github external
import {BodyParams, Controller, Get, PathParams, Post, ProviderScope, Required, Scope, Session, Status} from "@tsed/common";
import {MultipartFile} from "../../../../../packages/multipartfiles/src";
import {Docs, Hidden} from "../../../../../packages/swagger/src";
import {IUser, User} from "../../models/User";
import {UserService} from "../../services/UserService";

@Controller("/user")
@Scope(ProviderScope.REQUEST)
@Hidden()
@Docs("hidden")
export class UserCtrl {
  userId: string;

  constructor(public userService: UserService) {}

  @Post("/connect")
  @Status(204)
  async connect(@Session() session: Express.Session, @BodyParams("user") user: User) {
    session.user = user;
  }

  @Get("/get-connected")
  async getConnected(@Session("user") user: User): Promise {
    return user;
  }

  @Post("/")
  @Status(201)
  async createUser(@BodyParams() userData: User) {
    return await this.userService.create(userData);
  }
github replicatedhq / kots / api / src / controllers / kots / KotsAPI.ts View on Github external
} catch(err) {

        await request.app.locals.stores.kotsAppStore.setUpdateDownloadStatus(String(err), "failed");
        throw(err);

      } finally {
        liveness.stop();
      }
    }

    processFile();

    response.status(202);
  }

  @Post("/airgap/reset/:slug")
  async kotsResetAirgapUpload(
    @Req() request: Request,
    @Res() response: Response,
    @HeaderParams("Authorization") auth: string,
  ) {
    const session: Session = await request.app.locals.stores.sessionStore.decode(auth);
    if (!session || !session.userId) {
      response.status(401);
      return {};
    }

    const slug = request.params.slug;

    const appId = await request.app.locals.stores.kotsAppStore.getIdFromSlug(slug);
    await request.app.locals.stores.kotsAppStore.resetAirgapInstallInProgress(appId);
    response.send(200);
github replicatedhq / kots / api / src / controllers / kots / KotsAPI.ts View on Github external
return a.slug === slug;
    });

    if (!app) {
      response.status(404);
      return {};
    }

    response.header("Content-Type", "application/gzip");
    response.status(200);
    response.send(await app.getArchive(''+app.currentSequence));
  }



  @Post("/:slug/update-check")
  async kotsUpdateCheck(
    @Req() request: Request,
    @Res() response: Response,
    @PathParams("slug") slug: string,
    @QueryParams("deploy") deploy: boolean,
  ) {
    const apps = await request.app.locals.stores.kotsAppStore.listInstalledKotsApps();
    const app = _.find(apps, (a: KotsApp) => {
      return a.slug === slug;
    });

    if (!app) {
      response.status(404);
      return {};
    }
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 replicatedhq / kots / api / src / controllers / kots / SignupAPI.ts View on Github external
} from "@tsed/common";

interface SignupRequest {
  email: string;
  firstName: string;
  lastName: string;
  password: string;
}

interface ErrorResponse {
  message: string;
}

@Controller("/api/v1/signup")
export class SignupAPI {
  @Post("")
  public async signup(
    @Res() response: Express.Response,
    @Req() request: Express.Request,
    @BodyParams("") body: any,
  ): Promise {
    if (body.email === "" || body.password === "") {
      return {
        message: `Email and password are both required`,
      };
    }

    const user = await request.app.locals.stores.userStore.createPasswordUser(body.email, body.password, body.firstName, body.lastName);

    const sessionToken = await request.app.locals.stores.sessionStore.createPasswordSession(user.id);

    response.status(201);
github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / server / src / controllers / HelloWorldCtrl.ts View on Github external
return {text: "hello world with no authorisation"};
  }

  @Head("/post-auth-scoped")
  @Post("/post-auth-scoped")
  @OAuthBearer({scopes: ["tester"]})
  postAuthScoped(@OAuthParams("scopes") scopes: string[], @BodyParams() message: any) {

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

    return {text: "Auth w Scopes: " + message.text};
  }

  @Head("/post-auth-not-scoped")
  @Post("/post-auth-not-scoped")
  @OAuthBearer()
  postAuthNotScopedHead(@OAuthParams("scopes") scopes: string[], @BodyParams() message: any) {

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

    return {text: "Auth wout Scopes: " + message.text};
  }

  @OAuthHead()
  @Post("/post-no-auth")
  postNoAuth(@OAuthParams("scopes") scopes: string[], @BodyParams() message: any) {

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

    return {text: "No Auth: " + message.text};
  }