Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { injectable } from "inversify";
import { Controller, Get } from "inversify-express-utils";
import { authMiddleware } from "../middleware/auth_middleware";
// This is an example of a controller protected by the auth middleware
@injectable()
@Controller("/api/secure", authMiddleware({ role: "admin" }))
export class SecureController {
@Get("/")
public async get() {
return Promise.resolve(["This", "data", "is", "secure!"]);
}
}
import * as express from 'express';
import {injectable, inject} from 'inversify';
import Dictionary from "../Dictionary";
import IProjectionRunner from "../projections/IProjectionRunner";
import IProjectionsManager from "./IProjectionsManager";
import { Controller, Get } from 'inversify-express-utils';
@Controller('/projections')
@injectable()
class ProjectionsManager implements Controller,IProjectionsManager{
constructor(@inject("IProjectionRunnerHolder") private projectionsRunnerCollection:Dictionary>){
}
@Get('/stop/:name')
stop(req: express.Request, res: express.Response): void {
console.log(this.projectionsRunnerCollection);
let projection:IProjectionRunner = this.getProjectionRunner(null);
if(projection)
projection.stop();
this.writeResponse(res,projection,req.params.name,"Stop");
}
@Get('/pause/:name')
pause(req: express.Request, res: express.Response): void {
let projection:IProjectionRunner = this.getProjectionRunner(req.params.name);
if(projection)
projection.pause();
projection.stop();
this.writeResponse(res,projection,req.params.name,"Stop");
}
@Get('/pause/:name')
pause(req: express.Request, res: express.Response): void {
let projection:IProjectionRunner = this.getProjectionRunner(req.params.name);
if(projection)
projection.pause();
this.writeResponse(res,projection,req.params.name,"Pause");
}
@Get('/resume/:name')
resume(req: express.Request, res: express.Response): void {
let projection:IProjectionRunner = this.getProjectionRunner(req.params.name);
if(projection)
projection.resume();
this.writeResponse(res,projection,req.params.name,"Resume");
}
private getProjectionRunner(name : string){
return (this.projectionsRunnerCollection[name]) ? this.projectionsRunnerCollection[name] : null;
}
private writeResponse(res:express.Response,projectionRunner:IProjectionRunner,name:string,operation:string){
if(projectionRunner)
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { directorRepository } from "../../../domain/constants/decorators";
import { DirectorRepository } from "../../../domain/interfaces/repositories";
@injectable()
@Controller("/api/directors")
export class DirectorController {
@directorRepository public _directorRepository: DirectorRepository;
@Get("/")
public async get() {
return await this._directorRepository.findAll();
}
@Get("/:id")
public async getById(
@RequestParam("id") id: string,
) {
return await this._directorRepository.findById(id);
}
}
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { SearchService } from "../../../domain/interfaces/services";
import { searchService } from "../../../domain/constants/decorators";
@injectable()
@Controller("/api/search")
export class SearchController {
@searchService private _searchService: SearchService;
@Get("/:query")
public async get(
@RequestParam("query") query: string,
) {
return this._searchService.search(query);
}
}
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { directorRepository } from "../../../domain/constants/decorators";
import { DirectorRepository } from "../../../domain/interfaces/repositories";
@injectable()
@Controller("/api/directors")
export class DirectorController {
@directorRepository public _directorRepository: DirectorRepository;
@Get("/")
public async get() {
return await this._directorRepository.findAll();
}
@Get("/:id")
public async getById(
@RequestParam("id") id: string,
) {
return await this._directorRepository.findById(id);
}
}
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { actorRepository } from "../../../domain/constants/decorators";
import { ActorRepository } from "../../../domain/interfaces/repositories";
@injectable()
@Controller("/api/actors")
export class ActorController {
@actorRepository public _actorRepository: ActorRepository;
@Get("/")
public async get() {
return await this._actorRepository.findAll();
}
@Get("/:id")
public async getById(
@RequestParam("id") id: string,
) {
return await this._actorRepository.findById(id);
}
}
*/
@injectable()
@Controller('')
export class ApiController {
@Get('/info')
public getInfo( @Response() res: express.Response): any {
const pkg = require('../../../package.json');
return res.json({
name: pkg.name,
version: pkg.version,
description: pkg.description
});
}
@Get('/status')
public getStatus( @Request() req: express.Request, @Response() res: express.Response): any {
return monitor().pageRoute(req, res);
}
}
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { movieRepository } from "../../../domain/constants/decorators";
import { MovieRepository } from "../../../domain/interfaces/repositories";
@injectable()
@Controller("/api/movies")
export class MovieController {
@movieRepository public _movieRepository: MovieRepository;
@Get("/")
public async get() {
return await this._movieRepository.findAll();
}
@Get("/:id")
public async getById(
@RequestParam("id") id: string,
) {
return await this._movieRepository.findById(id);
}
}
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { movieRepository } from "../../../domain/constants/decorators";
import { MovieRepository } from "../../../domain/interfaces/repositories";
@injectable()
@Controller("/api/movies")
export class MovieController {
@movieRepository public _movieRepository: MovieRepository;
@Get("/")
public async get() {
return await this._movieRepository.findAll();
}
@Get("/:id")
public async getById(
@RequestParam("id") id: string,
) {
return await this._movieRepository.findById(id);
}
}