Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.setTitle(error.name)
.setStatus(HttpStatus.NOT_FOUND)
.setDetail(error.stack)
.setMessage(error.message)
.setSource(req.url)
.build();
this.loggerService.logAPITrace(req, res, HttpStatus.NOT_FOUND, error);
this.metricsService.logAPIMetrics(req, res, HttpStatus.NOT_FOUND);
reject({ errors: [resp], status: HttpStatus.NOT_FOUND });
}
);
});
res.status(result.status).json(result);
}
@httpGet('/products')
public async getProducts(@request() req: Request, @response() res: Response) {
const result: APIResponse = await new Promise((resolve, reject) => {
this.scraperService.getAll().subscribe(
r => {
if (r === undefined) {
this.loggerService.logAPITrace(
req,
res,
HttpStatus.INTERNAL_SERVER_ERROR
);
this.metricsService.logAPIMetrics(
req,
res,
HttpStatus.INTERNAL_SERVER_ERROR
);
reject({ data: r, status: HttpStatus.INTERNAL_SERVER_ERROR });
import { NextFunction, Request, Response } from 'express';
import { inject } from 'inversify';
import { controller, httpGet } from 'inversify-express-utils';
import { authMiddlware } from '../middlewares/auth.middleware';
import { TYPES } from '../services/types';
import { UserService } from '../services/user.service';
@controller('/users')
export class UserController {
constructor(@inject(TYPES.UserService) private _userService: UserService) {
}
@httpGet('/')
public getAllUsers(req: Request, res: Response, next: NextFunction) {
return this._userService.getAllUsers()
.then((users) => {
const mappedUsers = users.map((user) => {
return {
id: user.id,
name: user.name.first + ' ' + user.name.last,
};
});
return res.json({
users: mappedUsers,
});
})
.catch(next);
}
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);
}
@httpPost('/', authMiddlware.bearerStrategy)
public addTodo(req: IRequest, res: Response, next: NextFunction) {
const _todo = req.body;
_todo.userId = req.user.id;
return this._todoService.addTodo(_todo)
@injectable()
@controller(
'/gateway',
'OnlyAcceptApplicationJson'
)
export class GatewayController {
private logger = Logger.getInstance('DASHBOARD_CONTROLLER');
constructor(
@inject(VerificationClientType) private verificationClient: VerificationClientInterface,
@inject(CoinpaymentsClientType) private coinpaimentsClient: CoinpaymentsClientInterface,
@inject(PaymentsServiceType) private paymentsService: PaymentsServiceInterface,
@inject(IPNServiceType) private ipnService: IPNServiceInterface
) { }
@httpGet(
'/currencies'
)
async currencies(req: Request, res: Response): Promise {
const rates = await this.coinpaimentsClient.rates({accepted: 1});
Object.keys(rates).forEach(key => {
if (!rates[key].accepted || !rates[key].can_convert) {
delete rates[key];
}
});
res.json(rates);
}
@httpPost(
'/createTransaction',
'AuthMiddleware'
)
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 } from '../services';
@controller("/api/trakt")
@injectable()
export class TraktTVController implements interfaces.Controller {
constructor( @inject("TraktTVService") private traktTVService: TraktTVService) { }
@httpGet("/watchlist")
private async watchlist( @queryParam("username") username: string = ''): Promise {
let watchlist = await this.traktTVService.findWatchlistByUsername(username);
return watchlist;
}
@httpGet("/trending")
private async trending( @queryParam("years") years: string = '', @queryParam("ratings") ratings: string = '0-100', @queryParam("limit") limit: number = 100): Promise {
let watchlist = await this.traktTVService.findTrendingShows(years, ratings, limit);
return watchlist;
}
@httpGet("/popular")
private async popular( @queryParam("years") years: string = '', @queryParam("ratings") ratings: string = '0-100', @queryParam("limit") limit: number = 100): Promise {
let watchlist = await this.traktTVService.findPopularShows(years, ratings, limit);
return watchlist;
}
'ResetPasswordVerifyValidation'
)
async verifyResetPassword(req: Request, res: Response): Promise {
res.json(await this.userService.verifyResetPassword(req.body));
}
@httpPost(
'/invite',
'AuthMiddleware',
'InviteUserValidation'
)
async invite(req: AuthorizedRequest, res: Response): Promise {
res.json(await this.userService.invite(req.user, req.body));
}
@httpGet(
'/enable2fa/initiate',
'AuthMiddleware'
)
async enable2faInitiate(req: AuthorizedRequest, res: Response): Promise {
res.json(await this.userService.initiateEnable2fa(req.user));
}
@httpPost(
'/enable2fa/verify',
'AuthMiddleware',
'VerificationRequiredValidation'
)
async enable2faVerify(req: AuthorizedRequest, res: Response): Promise {
res.json(await this.userService.verifyEnable2fa(req.user, req.body));
}
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;
}
}