Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {
Processor,
Process,
OnQueueActive,
OnQueueEvent,
BullQueueEvents,
} from 'nest-bull';
import { Job } from 'bull';
import { Logger } from '@nestjs/common';
import { UserEntity } from '@graphqlcqrs/repository';
import { EmailService } from '../email.service';
@Processor({ name: 'auth_queue' })
export class AuthQueue {
private readonly logger = new Logger(this.constructor.name);
constructor(
private readonly service: EmailService,
// private readonly configService: ConfigService,
) {}
@Process({ name: 'UserRegistered' })
async processUserRegister(job: Job) {
if (job.data) { return; }
const user = job.data;
const userEmail = user.emails.reduce(previousValue => previousValue.primary === true && previousValue);
await this.service.sendEmail({
to: userEmail.address,
from: 'noreply@demo.com',
subject: 'Thank for registering',
import * as Consul from 'consul';
import { get } from 'lodash';
import * as YAML from 'yamljs';
import { Logger } from '@nestjs/common';
import { IConfig, IKVResponse, sleep } from '@nestcloud/common';
import { Store } from './store';
import { ConfigSyncException } from './exceptions/config-sync.exception';
export class ConsulConfig implements IConfig {
private readonly store = Store;
private readonly consul: Consul;
private readonly key: string;
private readonly retryInterval: 5000;
private watcher = null;
private readonly logger = new Logger('ConfigModule');
constructor(consul: Consul, key: string) {
this.consul = consul;
this.key = key;
}
async init() {
while (true) {
try {
const result = await this.consul.kv.get(this.key);
this.store.data = result ? YAML.parse(result.Value) : {};
this.createWatcher();
this.logger.log('ConfigModule initialized');
break;
} catch (e) {
this.logger.error('Unable to initial ConfigModule, retrying...', e);
useFactory: async (): Promise => {
const connection = new AmqpConnection(config);
await connection.init();
const logger = new Logger(RabbitMQModule.name);
logger.log('Successfully connected to RabbitMQ');
return connection;
}
}
import * as writeJsonToFile from "write-json-file";
import { dirname } from "path";
import { existsSync } from "fs";
import { Logger } from "@nestjs/common";
import { Json } from "@notadd/core/loaders";
import { importInjectionsFromDirectories } from "../utilities";
import { Injection as InjectionInterface } from "../interfaces";
export class InjectionLoader {
protected cacheForInjections: Array = [];
protected filePathForCache = "";
protected logger = new Logger("Injection");
protected patterns = [
"**/*.injection.js",
"**/*.module.js",
];
public get injections(): Array {
if (!this.cacheForInjections.length) {
this.loadInjectionsFromCache();
}
return this.cacheForInjections;
}
constructor() {
this.loadInjectionsFromCache();
invokeCustomFilters(exception, response) {
if (shared_utils_1.isEmpty(this.filters))
return false;
const filter = this.filters.find(({ exceptionMetatypes, func }) => {
const hasMetatype = !exceptionMetatypes.length ||
!!exceptionMetatypes.find(ExceptionMetatype => exception instanceof ExceptionMetatype);
return hasMetatype;
});
filter && filter.func(exception, response);
return !!filter;
}
isExceptionObject(err) {
return shared_utils_1.isObject(err) && !!err.message;
}
}
ExceptionsHandler.logger = new common_1.Logger(ExceptionsHandler.name);
exports.ExceptionsHandler = ExceptionsHandler;
import { Logger } from '@nestjs/common';
import * as optional from 'optional';
import { RedisClientToken } from './redis.constants';
const redis = optional('redis');
const logger = new Logger('RedisModule');
export function createRedisProviders(config: CreateRedisProvidersConfig) {
const redisProvider = {
provide: RedisClientToken,
useFactory: () => {
const redisClient = redis.createClient({
host: config.host,
port: config.port,
auth_pass: config.auth_pass
});
redisClient.on('connect', () => logger.log('Connecting'));
redisClient.on('ready', () => logger.log('Connected'));
redisClient.on('reconnecting', () => logger.log('Reconnecting'));
redisClient.on('end', () => logger.warn('Ended'));
redisClient.on('error', e => logger.error(e.message, e.stack));
return redisClient;
import { Logger, ParseIntPipe, UseGuards } from '@nestjs/common';
import { Args, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
import { PubSub } from 'graphql-subscriptions';
import { GqlAuthGuard } from '../auth/graphql-auth.guard';
import { CatEntity } from './cat.entity';
import { CatsService } from './cats.service';
import { CreateCatDto } from './dto/create-cat.dto';
const pubSub = new PubSub();
@Resolver('Cat')
export class CatsResolvers {
private logger = new Logger(CatsResolvers.name);
constructor(private readonly catsService: CatsService) {}
@Query()
@UseGuards(GqlAuthGuard)
async getCats() {
this.logger.log('getCats called');
return await this.catsService.findAll();
}
@Query('cat')
@UseGuards(GqlAuthGuard)
async findOneById(
@Args('id', ParseIntPipe)
id: number,
): Promise {
this.logger.log('getCat called');
import { Logger } from '@nestjs/common';
import * as Promise from 'bluebird';
import * as redis from 'redis';
import { RedisClientToken } from './redis.constants';
Promise.promisifyAll(redis.RedisClient.prototype);
Promise.promisifyAll(redis.Multi.prototype);
const logger = new Logger('RedisModule');
export function createRedisProviders(options: CreateRedisProvidersOptions) {
const redisProvider = {
provide: RedisClientToken,
useFactory: () => {
const redisClient = redis.createClient({
host: options.host,
port: options.port,
auth_pass: options.auth_pass
});
redisClient.on('connect', () => logger.log('Connecting'));
redisClient.on('ready', () => logger.log('Connected'));
redisClient.on('reconnecting', () => logger.log('Reconnecting'));
redisClient.on('end', () => logger.warn('Ended'));
redisClient.on('error', e => logger.error(e.message, e.stack));
return redisClient;