Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { NextFunction, Response } from 'express';
import { inject } from 'inversify';
import {
controller, httpDelete, httpGet, httpPost, httpPut,
} from 'inversify-express-utils';
import { IRequest } from '../interfaces/irequest';
import { authMiddlware } from '../middlewares/auth.middleware';
import { TodoService } from '../services/todo.service';
import { TYPES } from '../services/types';
@controller('/todos')
export class TodoController {
constructor(@inject(TYPES.TodoService) private _todoService: TodoService) {
}
@httpGet('/', authMiddlware.bearerStrategy)
public getAllTodos(req: IRequest, res: Response, next: NextFunction) {
const completed = req.query.completed !== undefined ? req.query.completed === 'true' : null;
return this._todoService.getAllTodos(req.user.id, completed)
.then((userTodos) => {
return res.json({
todos: userTodos,
});
})
.catch(next);
}
import { interfaces, controller, httpGet, httpPost, httpPut, httpDelete, request, queryParam, response, requestBody, requestParam } from "inversify-express-utils";
import { injectable, inject } from "inversify";
import * as express from "express";
import { ListService } from '../services';
@controller("/api/list")
@injectable()
export class ListController implements interfaces.Controller {
constructor( @inject("ListService") private listService: ListService) { }
@httpGet("/")
private async list(): Promise {
return this.listService.findAll();
}
@httpPost('/')
public async create( @response() res: Response, @requestBody() body: any): Promise {
await this.listService.create(body);
return {};
}
@httpDelete('/:id')
requestParam,
response
} from 'inversify-express-utils';
import { timeout } from 'rxjs/operators';
import SERVICE_IDENTIFIER from '../../../common/constants/identifiers';
import { ILogger, IMetrics } from '../../../common/interfaces';
import { authMiddleware } from '../../../common/middleware/auth-middleware';
import { IExample } from '../../interfaces';
import { HttpError, Quote } from '../../models';
import { ErrorResponseBuilder, HttpStatus } from '../../services';
/**
* Examples Controller
* JWT Auth middleware as well as logging middleware added
*/
@controller(
'/examples',
authMiddleware({ role: 'admin' } as any),
SERVICE_IDENTIFIER.LOGGER_MIDDLEWARE
)
class ExampleController extends BaseHttpController {
public exampleService: IExample;
public loggerService: ILogger;
public metricsService: IMetrics;
public constructor(
@inject(SERVICE_IDENTIFIER.EXAMPLE) exampleService: IExample,
@inject(SERVICE_IDENTIFIER.LOGGER) loggerService: ILogger,
@inject(SERVICE_IDENTIFIER.METRICS) metricsService: IMetrics
) {
super();
this.exampleService = exampleService;
import { inject, injectable } from "inversify";
import { interfaces, controller } from 'inversify-express-utils';
import AudioFactory from '../services/media_providers/AudioFactory';
import { TYPES } from '../../Types';
@injectable()
@controller('Song')
export default class Song implements interfaces.Controller {
public constructor( @inject(TYPES.AudioFactory) private _audio_factory: AudioFactory) { }
public getSong(args: any, callback: Function) {
let song = this._audio_factory.getSong(args.song_name);
song.then((song) => callback(null, song));
song.catch((error: Error) => {
callback(error);
});
}
}
import { getConnection } from 'typeorm';
import { Logger } from '../logger';
import { EmailTemplateServiceType, EmailTemplateService } from '../services/email.template.service';
const TRANSACTION_STATUS_PENDING = 'pending';
const TRANSACTION_TYPE_TOKEN_PURCHASE = 'token_purchase';
export const INVEST_SCOPE = 'invest';
/**
* Dashboard controller
*/
@injectable()
@controller(
'/dashboard',
'OnlyAcceptApplicationJson'
)
export class DashboardController {
private logger = Logger.getInstance('DASHBOARD_CONTROLLER');
private icoContractAddresses: Array = [];
constructor(
@inject(VerificationClientType) private verificationClient: VerificationClientInterface,
@inject(Web3ClientType) private web3Client: Web3ClientInterface,
@inject(TransactionServiceType) private transactionService: TransactionServiceInterface,
@inject(EmailTemplateServiceType) private emailTemplateService: EmailTemplateService
) {
this.icoContractAddresses.push(config.contracts.ico.address);
if (config.contracts.ico.oldAddresses.length > 0) {
this.icoContractAddresses.push(...config.contracts.ico.oldAddresses);
import { interfaces, controller, httpGet, httpPost, httpDelete, request, queryParam, response, requestParam } from "inversify-express-utils";
import { injectable, inject } from "inversify";
import * as express from "express";
import { TraktTVService, SonarrService, SyncRunnerService } from '../services';
@controller("/api/sonarr")
@injectable()
export class SonarrController implements interfaces.Controller {
constructor( @inject("SonarrService") private sonarrService: SonarrService) { }
@httpGet("/paths")
private async paths(): Promise {
let paths = await this.sonarrService.findPaths();
return paths;
}
@httpGet("/profiles")
private async profiles(): Promise {
let profiles = await this.sonarrService.findProfiles();
return profiles;
}
}
import {injectable} from "inversify";
import {controller, httpGet} from "inversify-express-utils";
import * as express from "express";
import { ApiPath, ApiOperationGet } from "../lib/swagger-specification";
@ApiPath({
path: "/books",
name : "Book",
description : "Everything about book"
})
@controller( "/books" )
@injectable()
export class BooksController {
public static TARGET_NAME: string = "BooksController";
constructor(){
}
@ApiOperationGet({
description : "Book object that need to be",
summary : "Add a new Book"
})
@httpGet("/")
public get(request: express.Request, response: express.Response, next: express.NextFunction): void {
response.json([
{