Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const winston = require('winston');
import {Component} from '@nestjs/common';
@Component()
export class Log {
readonly info;
readonly warn;
readonly debug;
readonly error;
constructor() {
const logger = winston.createLogger({
level: 'debug',
format: winston.format.json(),
transports: [
// hack to put everything in stdout so you get a streamlined console history.
// see https://github.com/winstonjs/winston/issues/814
new winston.transports.Console({stderrLevels: []})
]
});
import { TickerDto } from './../../../../../common/dtos/ticker.model';
import { Subscriber } from 'rxjs/Subscriber';
import { Observable } from 'rxjs/Observable';
import { Component, Get, Req } from '@nestjs/common';
import { RxHttpRequest } from 'rx-http-request';
import { ApiWrapper } from './../api.wrapper';
import { Exchange } from '../../../../../common/enums/exchange.enum';
import { BitfinexTicker } from './../../../../../common/enums/bitfinexticker.enum';
import { HistoryPeriod } from '../../../../../common/enums/period.enum';
@Component()
export class BitfinexWrapper extends ApiWrapper {
publicEndpoints = [`https://api.bitfinex.com/v1/`, `https://api.bitfinex.com/v2/`];
exchange = Exchange.bitfinex;
getTickers(): Observable {
// symbols only available in v1
const assetPairsUrl = this.composeUrl(`symbols`, 0);
return RxHttpRequest.get(assetPairsUrl, {}).map((data) => {
if (data.response.statusCode === 200) {
return JSON.parse(data.response.body);
} else {
// TODO: error handling
return [];
}
}).switchMap((pairs: string[]) => {
import { Component } from '@nestjs/common';
import { Connection } from 'typeorm';
@Component()
export class DatabaseService {
constructor(private connection: Connection) {}
public closeConnection() {
return this.connection.close();
}
public drop() {
return this.connection.dropDatabase();
}
}
import { Component, Inject } from '@nestjs/common';
import { IUser, IUserService } from './interfaces/index';
import { User } from './user.entity';
import { DatabaseUtilitiesService } from '../database/database-utilities.service';
@Component()
export class UserService implements IUserService {
constructor(@Inject('UserRepository') private readonly UserRepository: typeof User,
@Inject('SequelizeInstance') private readonly sequelizeInstance,
private readonly databaseUtilitiesService: DatabaseUtilitiesService) { }
public async findAll(options?: object): Promise> {
return await this.UserRepository.findAll(options);
}
public async findOne(options?: object): Promise {
return await this.UserRepository.findOne(options);
}
public async findById(id: number): Promise {
return await this.UserRepository.findById(id);
}
import {Component} from '@nestjs/common';
import {ApiTokenRepository} from '../../../persistence/repository/api-token.repository';
@Component()
export class SpaRedirectorComponent {
constructor(
private readonly apiTokenRepository: ApiTokenRepository,
) {}
createApiTokenAndRedirect(user, req, res, next) {
this.apiTokenRepository.createForUser(user)
.then(apiToken => {
req.login(
user,
loginErr => {
if (loginErr) {
return next(loginErr);
}
import { UserRepository } from './user.repository';
import { PasswordEncrypterService } from './../../../utils/encryption/password-encrypter.service';
import { User } from './user.entity';
import { Component } from "@nestjs/common";
@Component()
export class UserManager {
constructor(private userRepository: UserRepository, private passwordEncrypter: PasswordEncrypterService) {}
async getAll() {
const users = await this.userRepository.findAll();
return users.map((user: User) => {
delete user.password;
return user;
});
}
async getOne(userId: number) {
const user = await this.userRepository.findOneById(userId);
delete user.password;
return user;
import {
BadRequestException, Component, ConflictException, InternalServerErrorException,
NotFoundException
} from "@nestjs/common";
import {InjectRepository} from "@nestjs/typeorm";
import {Repository} from "typeorm";
import {Client, User} from "./models";
import {DbErrorCode} from "../enums/db-error-code.enum";
@Component()
export class OAuthService {
constructor(@InjectRepository(Client) private readonly clientsRepository: Repository, @InjectRepository(User) private readonly usersRepository: Repository) {
}
async createClient(client: Client): Promise {
try {
let c: Client = await this.clientsRepository.save(client);
return Promise.resolve(c);
} catch (e) {
if (e.code) {
if (DbErrorCode.UNIQUE_VIOLATION == e.code) {
throw new BadRequestException("Sorry, already exists an client registered with the same name.");
} else if (DbErrorCode.NOT_NULL_VIOLATION == e.code || DbErrorCode.CHECK_VIOLATION == e.code || DbErrorCode.STRING_DATA_RIGHT_TRUNCATION == e.code) {
throw new BadRequestException("Unable to create the client due to invalid client data.");
import {
FindManyOptions,
FindOneAndReplaceOption,
FindOneOptions,
MongoRepository,
ObjectID,
ObjectLiteral,
RemoveOptions,
SaveOptions,
} from 'typeorm';
import { DeepPartial } from 'typeorm/common/DeepPartial';
import { DatabaseException } from '../database';
import { User } from './user.entity';
@Component()
export class UserService {
constructor(
@InjectRepository(User)
private readonly userRepository: MongoRepository,
) {}
public async create(entity: User, options?: SaveOptions) {
try {
return await this.userRepository.save(entity, options);
} catch (err) {
throw new DatabaseException(err);
}
}
public async find(options?: FindManyOptions) {
try {
import { v4 } from 'uuid';
import Album from 'shared/models/Album';
import Artist from 'shared/models/Artist';
import File, { FileEntity, FileIndex } from 'shared/models/File';
import Library from 'shared/models/Library';
import ResourceType from 'shared/models/ResourceType';
import Track from 'shared/models/Track';
import Debug from 'debug';
const debug = Debug('compactd:media-scanner');
const warn = Debug('compactd:media-scanner:warn');
const walk = require('walk');
@Component()
export default class MediaScannerService {
public async runScan(factory: PouchFactory, libraryId: string) {
debug('Starting scan...');
const library = await Library.findById(factory, libraryId);
await this.scanFolderAndCreateFiles(factory, library._id, library.path);
const filesToProcess: FileEntity[] = await File.queryDocs(
factory,
FileIndex.UnprocessedFiles
);
const filesByAlbum: {
[album: string]: FileEntity[];
} = filesToProcess.reduce((acc, file) => {
if (!file.tags || !file.tags.album) {
import { Component, Inject } from '@nestjs/common';
import { Repository } from 'typeorm';
import { Author } from './author.interface';
@Component()
export class AuthorsService {
constructor( @Inject('AuthorRepositoryToken') private readonly authorRepository: Repository) { }
async findAll(): Promise {
try {
return await this.authorRepository.find();
} catch (err) {
return err;
}
}
async create(author: Author) {
try {
return await this.authorRepository.save(author);
} catch (err) {
return err;