How to use the @tsed/common.Status 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 / users / UserCtrl.ts View on Github external
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);
  }

  @Get("/:user")
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
@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"})
  @Security("global_auth", "read:global")
  @Security("calendar_auth", "write:calendar", "read:calendar")
  public remove(
    @BodyParams("id")
    @Required()
      id: string
  ): void {

    return undefined;
  }

  @Delete("/token")
  @Status(204)
  @OAuth({role: "admin", scopes: ["write:calendar", "read:calendar"]})
  public removeWithToken(@BodyParams("id") @Required() id: string): void {
github TypedProject / ts-express-decorators / docs / tutorials / snippets / session / example-session.ts View on Github external
import {BodyParams, Controller, Get, Post, Session, Status} from "@tsed/common";

@Controller("/")
export class MyCtrl {

  @Get("/whoami")
  whoAmI(@Session() session: any) {
    console.log("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")
  @Status(204)
  logout(@Session("user") user: any) {
    user.id = null;
    delete user.name;
  }
}
github TypedProject / ts-express-decorators / examples / mongoose / src / controllers / events / EventsCtrl.ts View on Github external
return this
      .calendarEventsService
      .find(id)
      .then(() => this.calendarEventsService.save(calendarEvent))
      .catch((err) => {
        throw new NotFound("Calendar id not found");
      });
  }

  /**
   *
   */
  @Delete("/:id")
  @UseBefore(CheckCalendarIdMiddleware)
  @Summary("Remove an event")
  @Status(204, {description: "No content"})
  async remove(@Description("The calendar id of the event")
               @Required() @PathParams("calendarId") calendarId: string,
               @Description("The event id")
               @PathParams("id") id: string): Promise {
    return this.calendarEventsService.remove(id);
  }

  @Get("/")
  @Summary("Get all events for a calendar")
  @Status(200, {description: "Success"})
  async getEvents(@Description("The calendar id of the event")
                  @Required() @PathParams("calendarId") calendarId: string): Promise {
    return this.calendarEventsService.query(calendarId);
  }
}
github TypedProject / ts-express-decorators / examples / mongoose / src / controllers / calendars / CalendarsCtrl.ts View on Github external
@BodyParams() calendar: Calendar): Promise {

    calendar._id = id;

    return this.calendarsService.save
    (calendar);
  }

  /**
   *
   * @param id
   * @returns {{id: string, name: string}}
   */
  @Delete("/:id")
  @Summary("Remove a calendar.")
  @Status(204, {description: "No content"})
  async remove(@PathParams("id") id: string): Promise {
    await this.calendarsService.remove(id);
  }

  @Delete("/")
  @Summary("Remove all calendars.")
  @Status(204, {description: "No content"})
  async clear(@PathParams("id") id: string): Promise {
    await this.calendarsService.clear();
  }

  /**
   *
   * @returns {Promise}
   */
  @Get("/")
github TypedProject / ts-express-decorators / examples / getting-started / src / controllers / events / EventsCtrl.ts View on Github external
@PathParams("id") id: string,
               @BodyParams("startDate") startDate: string,
               @BodyParams("endDate") endDate: string,
               @BodyParams("name") name: string): Promise {

    const event = await this.get(calendarId, id);
    event.name = name;
    event.startDate = name;
    event.endDate = name;

    return event;
  }

  @Delete("/:id")
  @Authenticated()
  @Status(204)
  async remove(@Required() @PathParams("calendarId") calendarId: string,
               @PathParams("id") id: string): Promise {
    this.events = this.events.filter(event => event.id === id && event.calendarId === calendarId);
  }

  @Get("/")
  async getEvents(@Required() @PathParams("calendarId") calendarId: string): Promise {
    return this.events.filter(event => event.calendarId === calendarId);
  }
}
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")
  @Status(204)
  logout(@Session("user") user: any) {
    user.id = null;
    delete user.name;
  }
}
github TypedProject / ts-express-decorators / examples / aws / src / controllers / calendars / CalendarsCtrl.ts View on Github external
* @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});
  }

  /**
   *
   * @param id
   * @returns {{id: string, name: string}}
   */
  @Delete("/")
  @Status(204)
  async remove(@BodyParams("id") @Required() id: string): Promise {
    this.calendarsService.remove(id);
  }

  @Get("/")
  async getAllCalendars(): Promise {
    return this.calendarsService.query();
  }
}
github TypedProject / ts-express-decorators / examples / mongoose / src / controllers / calendars / CalendarsCtrl.ts View on Github external
@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})
  async update(@PathParams("id") @Required() id: string,
               @BodyParams() calendar: Calendar): Promise {

    calendar._id = id;

    return this.calendarsService.save
    (calendar);
  }

  /**
   *
   * @param id
   * @returns {{id: string, name: string}}
   */
  @Delete("/:id")
  @Summary("Remove a calendar.")
github TypedProject / ts-express-decorators / examples / mongoose / src / controllers / calendars / CalendarsCtrl.ts View on Github external
*/
@Controller("/calendars", EventsCtrl)
export class CalendarsCtrl {

  constructor(private calendarsService: CalendarsService) {

  }

  /**
   *
   * @param {string} id
   * @returns {Promise}
   */
  @Get("/:id")
  @Summary("Return a calendar from his ID")
  @Status(200, {description: "Success", type: Calendar})
  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");
  }

  /**
   *
   * @param {Calendar} calendar
   * @returns {Promise}
   */