Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Logger} from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import {ApolloError} from 'apollo-server-express';
import { TenantRepository } from '@graphqlcqrs/repository/repositories';
import { TenantEntity } from '@graphqlcqrs/repository/entities';
import { GetTenantsQuery } from '../../impl';
import { ObjectId } from 'bson';
@QueryHandler(GetTenantsQuery)
export class GetTenantsHandler implements IQueryHandler {
constructor(
private readonly tenantRepository: TenantRepository,
) {}
async execute(query: GetTenantsQuery): Promise {
Logger.log(query, 'GetTenantsQuery'); // write here
const { where, user } = query;
if (!user) { throw Error('Missing get current user'); }
try {
return await this.tenantRepository.find({ conditions: {...where, ownerId: new ObjectId(user.id)} });
} catch (e) {
throw new ApolloError(e);
}
import {Logger} from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import { TenantRepository } from '@graphqlcqrs/repository/repositories';
import { TenantEntity } from '@graphqlcqrs/repository/entities';
import { GetTenantQuery } from '../../impl';
import { ObjectId } from 'bson';
@QueryHandler(GetTenantQuery)
export class GetTenantHandler implements IQueryHandler {
constructor(
private readonly tenantRepository: TenantRepository,
) {}
async execute(query: GetTenantQuery): Promise {
Logger.log(query, 'GetTenantQuery'); // write here
const { where, user } = query;
if (!where) { throw Error('Missing get inputs'); }
return await this.tenantRepository.findOne({...where, ownerId: new ObjectId(user.id)});
}
}
import {Logger} from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import { AuthRepository, AuthEntity } from '@graphqlcqrs/repository';
import { GetAuthQuery } from '../../impl';
@QueryHandler(GetAuthQuery)
export class GetAuthHandler implements IQueryHandler {
constructor(
private readonly authRepository: AuthRepository,
) {}
async execute(query: GetAuthQuery): Promise {
Logger.log(query, 'GetAuthQuery');
const { where } = query;
if (!where) { throw Error('Missing get inputs'); }
// @ts-ignore
return await this.authRepository.findOne({ 'local.email': where.local.email});
}
}
import {Logger} from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import { TenantMemberEmbed } from '@graphqlcqrs/repository/entities';
import { TenantRepository } from '@graphqlcqrs/repository';
import { GetTenantMembersQuery } from '../../impl';
@QueryHandler(GetTenantMembersQuery)
export class GetTenantMembersHandler implements IQueryHandler {
constructor(
private readonly tenantRepository: TenantRepository,
) {}
async execute(query: GetTenantMembersQuery): Promise {
Logger.log(query, 'GetUserQuery'); // write here
const { where, tenantId } = query;
if (!where) { throw Error('Missing get inputs'); }
const tenant = await this.tenantRepository.aggregate([
{
$match: {
$and: [
{_id: tenantId},
{
import {Logger} from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import { AuthRepository } from '@graphqlcqrs/repository';
import { AuthExistQuery } from '../../impl';
@QueryHandler(AuthExistQuery)
export class AuthExistHandler implements IQueryHandler {
constructor(
private readonly authRepository: AuthRepository,
) {}
async execute(query: AuthExistQuery): Promise {
Logger.log(query, 'AuthExistQuery');
const { where } = query;
if (!where) { throw Error('Missing get inputs'); }
// @ts-ignore
return await this.authRepository.exist({ 'local.email': where.local.email});
}
}
import { Logger, CACHE_MANAGER, Inject, CacheStore } from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import { InjectStripe } from 'nestjs-stripe';
import * as Stripe from 'stripe';
import { UserInputError, ApolloError } from 'apollo-server-express';
import { Plan } from '../../../../types';
import { convertToPlan } from '../../../../converter.util';
import { GetPlanQuery } from '../../impl';
@QueryHandler(GetPlanQuery)
export class GetPlanHandler implements IQueryHandler {
logger = new Logger(this.constructor.name);
public constructor(
@InjectStripe() private readonly stripeClient: Stripe,
@Inject(CACHE_MANAGER) private readonly cacheStore: CacheStore,
) {}
async execute(query: GetPlanQuery): Promise {
this.logger.log(`Async ${query.constructor.name}...`);
const { id } = query;
if (!id) { throw new UserInputError('Missing plan id input'); }
try {
// Check cache to see if data exist
import { CACHE_MANAGER, CacheStore, Inject, Logger } from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import { Card } from '@ultimatebackend/contracts';
import { ApolloError } from 'apollo-server-express';
import { InjectStripe } from 'nestjs-stripe';
import * as Stripe from 'stripe';
import { GetCardsQuery } from '../../impl';
import { convertFromToCard } from '../../../../converter.util';
import { BadRequestError } from '@graphqlcqrs/common';
@QueryHandler(GetCardsQuery)
export class GetCardsHandler implements IQueryHandler {
logger = new Logger(this.constructor.name);
constructor(
@InjectStripe() private readonly stripeClient: Stripe,
@Inject(CACHE_MANAGER) private readonly cacheStore: CacheStore,
) {}
async execute(query: GetCardsQuery): Promise {
this.logger.log(`Async ${query.constructor.name}...`);
const { user } = query;
try {
if (user.payment === null ||
user.payment.stripeId === undefined ||
import { CACHE_MANAGER, CacheStore, Inject, Logger } from '@nestjs/common';
import {IQueryHandler, QueryHandler} from '@nestjs/cqrs';
import {ApolloError} from 'apollo-server-express';
import * as Stripe from 'stripe';
import { InjectStripe } from 'nestjs-stripe';
import { GetPlansQuery } from '../../impl';
import { Plan } from '../../../../types';
import { convertToPlan } from '../../../../converter.util';
@QueryHandler(GetPlansQuery)
export class GetPlansHandler implements IQueryHandler {
logger = new Logger(this.constructor.name);
public constructor(
@InjectStripe() private readonly stripeClient: Stripe,
@Inject(CACHE_MANAGER) private readonly cacheStore: CacheStore,
) {}
async execute(query: GetPlansQuery): Promise {
this.logger.log(`Async ${query.constructor.name}...`);
const { where } = query;
try {
if (!where) { throw new ApolloError('Missing get where input'); }
import { CACHE_MANAGER, CacheStore, Inject, Logger } from '@nestjs/common';
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { Card } from '@ultimatebackend/contracts';
import { GetCardQuery } from '../../impl';
import { InjectStripe } from 'nestjs-stripe';
import * as Stripe from 'stripe';
import { convertFromToCard } from '../../../../converter.util';
import { ApolloError, UserInputError } from 'apollo-server-express';
import { BadRequestError } from '@graphqlcqrs/common';
@QueryHandler(GetCardQuery)
export class GetCardHandler implements IQueryHandler {
logger = new Logger(this.constructor.name);
constructor(
@InjectStripe() private readonly stripeClient: Stripe,
@Inject(CACHE_MANAGER) private readonly cacheStore: CacheStore,
) {}
async execute(query: GetCardQuery): Promise {
this.logger.log(`Async ${query.constructor.name}...`);
const { id, user } = query;
if (!id) { throw new UserInputError('Missing card id inputs'); }
try {