Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
name = (typeof name === "object" ? undefined : name)!;
// create endpoint metadata
store.merge("consumes", ["multipart/form-data"]).set("multipartAdded", true);
store
.merge("responses", {
"400": {
description: ` [fieldName]
Example: File too long file1`
}
})
.set("multipartAdded", true);
if (!added) {
// middleware is added
UseBefore(MultipartFileMiddleware)(target, propertyKey, descriptorOf(target, propertyKey));
}
if (name === undefined) {
store.merge(MultipartFileMiddleware, {
options,
any: true
});
UseFilter(multiple ? MultipartFilesFilter : MultipartFileFilter, {
useConverter: false,
paramType: ParamTypes.FORM_DATA
})(target, propertyKey, index);
} else {
const expression = multiple ? (name as string) : name + ".0";
store.merge(MultipartFileMiddleware, {
export function OAuthHead() {
return UseBefore((request, response, next) => {
const {scopes = []} = request.ctx.endpoint.get(OAuthBearerOptions) || {};
response.set("Access-Control-Expose-Headers", "scopes");
response.set("scopes", JSON.stringify(scopes));
if (request.method.toUpperCase() === "HEAD") { // prevent head request and skip endpoint
return response.send();
}
next();
})
}
name = (typeof name === "object" ? undefined : name)!;
// create endpoint metadata
store.merge("consumes", ["multipart/form-data"]).set("multipartAdded", true);
store
.merge("responses", {
"400": {
description: ` [fieldName]
Example: File too long file1`
}
})
.set("multipartAdded", true);
if (!added) {
// middleware is added
UseBefore(MultipartFileMiddleware)(target, propertyKey, descriptorOf(target, propertyKey));
}
if (name === undefined) {
store.merge(MultipartFileMiddleware, {
options,
any: true
});
ParamRegistry.useFilter(multiple ? MultipartFilesFilter : MultipartFileFilter, {
propertyKey,
parameterIndex,
target,
useConverter: false,
paramType: ParamTypes.FORM_DATA
});
} else {
import {Authenticated, Controller, Get, MergeParams, PathParams, QueryParams, UseBefore} from "@tsed/common";
import {Hidden} from "../../../../../packages/swagger/src";
import {Test2Middleware} from "../../middlewares/middleware";
@Controller("/:eventId/tasks")
@MergeParams()
@UseBefore(Test2Middleware)
@Authenticated({options: "options"})
export class TaskCtrl {
@Get("/")
async get(@PathParams("test") value: string, @PathParams("eventId") id: string) {
return {value, id};
}
@Get("/hidden")
@Hidden()
async getHidden() {
return {};
}
@Get("/hiddenparam")
async getHiddenParams(
@Hidden()
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("/")
endpointB() {
console.log("EndpointB");
return {};
}
}
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("/")
endpointB() {
console.log("EndpointB");
MergeParams,
PathParams,
Post,
Put,
Required,
Status,
UseBefore
} from "@tsed/common";
import {NotFound} from "ts-httpexceptions";
import {CheckCalendarIdMiddleware} from "../../middlewares/CheckCalendarIdMiddleware";
import {Event} from "../../interfaces/Event";
import {Task} from "../../interfaces/Task";
@Controller("/:calendarId/events")
@MergeParams(true)
@UseBefore(CheckCalendarIdMiddleware)
export class EventsCtrl {
private AUTO_INC = 5;
private events: Event[] = require("../../../resources/events.json");
@Get("/:id")
async get(@Required() @PathParams("calendarId") calendarId: string,
@PathParams("id") id: string): Promise {
const event = this.events.find(event => event.id === id && event.calendarId === calendarId);
if (event) {
return event;
}
throw new NotFound("event not found");
}
@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}
*/
@Post("/:id")
import {CalendarEvent} from "../../models/events/CalendarEvent";
import {CalendarEventsService} from "../../services/calendars/CalendarEventsService";
@Controller("/:calendarId/events")
@MergeParams(true)
export class EventsCtrl {
constructor(private calendarEventsService: CalendarEventsService) {
}
/**
*
* @returns {null}
*/
@Get("/:id")
@UseBefore(CheckCalendarIdMiddleware)
@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("/")
@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}
*/
@Post("/:id")
@UseBefore(CheckCalendarIdMiddleware)
@Summary("Update event information")
@Status(200, {description: "Success"})
async update(@Description("The calendar id of the event")
@Required()
@PathParams("calendarId") calendarId: string,
@Description("The event id")
@PathParams("id") id: string,
@BodyParams() calendarEvent: CalendarEvent): Promise {
return this
.calendarEventsService
.find(id)
.then(() => this.calendarEventsService.save(calendarEvent))
.catch((err) => {
throw new NotFound("Calendar id not found");
});