How to use the @nestjs/cqrs.QueryHandler function in @nestjs/cqrs

To help you get started, we’ve selected a few @nestjs/cqrs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github juicycleff / ultimate-backend / apps / service-tenant / src / cqrs / query / handlers / tenant / get-tenants.handler.ts View on Github external
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);
    }
github juicycleff / ultimate-backend / apps / service-tenant / src / cqrs / query / handlers / tenant / get-tenant.handler.ts View on Github external
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)});
  }
}
github juicycleff / ultimate-backend / libs / core / src / cqrs / queries / handlers / auth / get-auth.handler.ts View on Github external
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});
  }
}
github juicycleff / ultimate-backend / apps / service-tenant / src / cqrs / query / handlers / tenant-member / get-tenant-members.handler.ts View on Github external
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},
            {
github juicycleff / ultimate-backend / libs / core / src / cqrs / queries / handlers / auth / auth-exist.handler.ts View on Github external
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});
  }
}
github juicycleff / ultimate-backend / apps / service-payment / src / cqrs / query / handlers / plan / get-plan.handler.ts View on Github external
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
github juicycleff / ultimate-backend / apps / service-payment / src / cqrs / query / handlers / card / get-cards.handler.ts View on Github external
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 ||
github juicycleff / ultimate-backend / apps / service-payment / src / cqrs / query / handlers / plan / get-plans.handler.ts View on Github external
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'); }
github juicycleff / ultimate-backend / apps / service-payment / src / cqrs / query / handlers / card / get-card.handler.ts View on Github external
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 {

@nestjs/cqrs

A lightweight CQRS module for Nest framework (node.js)

MIT
Latest version published 2 months ago

Package Health Score

86 / 100
Full package analysis

Similar packages