Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
@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;
}
/**
*
* @returns {null}
*/
@Delete("/:id")
remove(): Promise | void {
return Promise.resolve(null);
}
/**
*
* @returns {null}
});
}
@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"})
@Security("global_auth", "read:global")
@Get("/:id")
@Returns(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");
}
@Put("/")
@Status(201)
@Returns(Calendar)
save(@BodyParams() calendar: CreateCalendar): Promise {
return this.calendarsService.create(calendar);
}
@Post("/:id")
@Returns(Calendar)
async update(@PathParams("id") @Required() id: string,
@BodyParams() @Required() calendar: CreateCalendar): Promise {
return this.calendarsService.update({id, ...calendar});
}
@Delete("/")
@Status(204)
async remove(@BodyParams("id") @Required() id: string): Promise {
await this.calendarsService.remove(id);
}
if (calendar) {
return calendar;
}
throw new NotFound("Calendar not found");
}
@Put("/")
@Status(201)
@Returns(Calendar)
save(@BodyParams() calendar: CreateCalendar): Promise {
return this.calendarsService.create(calendar);
}
@Post("/:id")
@Returns(Calendar)
async update(@PathParams("id") @Required() id: string,
@BodyParams() @Required() calendar: CreateCalendar): Promise {
return this.calendarsService.update({id, ...calendar});
}
@Delete("/")
@Status(204)
async remove(@BodyParams("id") @Required() id: string): Promise {
await this.calendarsService.remove(id);
}
@Get("/")
@ReturnsArray(Calendar)
async getAllCalendars() {
return this.calendarsService.query();
}
*
* In this case, EventsCtrl is a dependency of CalendarsCtrl.
* All routes of EventsCtrl will be mounted on the `/calendars` path.
*/
@Controller({
path: "/calendars",
children: [
EventsCtrl
]
})
export class CalendarsCtrl {
constructor(private calendarsService: CalendarsService) {
}
@Get("/:id")
@Returns(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");
}
@Put("/")
@Status(201)
@Returns(Calendar)
save(@BodyParams() calendar: CreateCalendar): Promise {
return this.calendarsService.create(calendar);
}