Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@Get("/:resources/test/:id")
@Summary("Return an element by his resource")
async getTest(
@Description("The resource")
@PathParams("resources")
resources: string,
@Description("Id of the resource")
@PathParams("id")
id: string
): Promise {
return {_id: id};
}
@Get("/list")
@Summary("Return all elements from a service")
async index(): Promise {
return [{_id: "test"}];
}
}
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")
@UseBefore(CheckCalendarIdMiddleware)
}
/**
*
* @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("/")
@Summary("Return all calendars")
@Status(200, {description: "Success", type: Calendar, collectionType: Array})
async getAllCalendars(): Promise {
return this.calendarsService.query();
}
}
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("/")
@UseBefore(CheckCalendarIdMiddleware)
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.")
@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}
*/
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("/")
@Summary("Return all calendars")
@Status(200, {description: "Success", type: Calendar, collectionType: Array})
async getAllCalendars(): Promise {
return this.calendarsService.query();
}
}
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);
}
}
* All routes of EventsCtrl will be mounted on the `/calendars` path.
*/
@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}
/**
*
*/
@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);
}
}
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})
async update(@PathParams("id") @Required() id: string,