How to use the @nestjs/cqrs.CommandHandler 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 new-eden-social / new-eden-social / src / api / src / modules / notification / commands / handlers / seen.handler.ts View on Github external
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
import { InjectRepository } from '@nestjs/typeorm';
import { NotificationRepository } from '../../notification.repository';
import { SeenNotificationCommand } from '../seen.command';

@CommandHandler(SeenNotificationCommand)
export class SeenNotificationCommandHandler implements ICommandHandler {
  constructor(
    @InjectRepository(NotificationRepository)
    private readonly repository: NotificationRepository,
    private readonly publisher: EventPublisher,
  ) {
  }

  async execute(command: SeenNotificationCommand) {
    const { notification } = command;

    const entity = this.publisher.mergeObjectContext(
      await this.repository.markAsSeen(notification),
    );

    // Sends actual event
github kamilmysliwiec / nest-cqrs-example / src / heroes / commands / handlers / drop-ancient-item.handler.ts View on Github external
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
import * as clc from 'cli-color';
import { HeroRepository } from '../../repository/hero.repository';
import { DropAncientItemCommand } from '../impl/drop-ancient-item.command';

@CommandHandler(DropAncientItemCommand)
export class DropAncientItemHandler
  implements ICommandHandler {
  constructor(
    private readonly repository: HeroRepository,
    private readonly publisher: EventPublisher,
  ) {}

  async execute(command: DropAncientItemCommand) {
    console.log(clc.yellowBright('Async DropAncientItemCommand...'));

    const { heroId, itemId } = command;
    const hero = this.publisher.mergeObjectContext(
      await this.repository.findOneById(+heroId),
    );
    hero.addItem(itemId);
    hero.commit();
github santaz1995 / nestjs-cqrs-starter / src / application / command / project / update-project.execute.ts View on Github external
import { ICommandHandler, CommandHandler, EventPublisher } from '@nestjs/cqrs';
import { Inject } from '@nestjs/common';
import { UpdateProjectCommand } from './update-project.command';
import { ProjectCommandRepository } from '../../../domains/project/project.command.repository';

@CommandHandler(UpdateProjectCommand)
export class UpdateProjectExecute implements ICommandHandler {

    constructor(
        @Inject('ProjectCommandRepository') private projectRepository: ProjectCommandRepository,
        private readonly publisher: EventPublisher) {
    }

    /**
     * @param {UpdateProjectCommand} command
     * @param {(value?) => void} resolve
     * @returns {Promise}
     */
    async execute(command: UpdateProjectCommand, resolve: (value?) => void) {

        resolve();
github santaz1995 / nestjs-cqrs-starter / src / application / command / project-category / create-project-category.execute.ts View on Github external
import { ICommandHandler, CommandHandler, EventPublisher } from '@nestjs/cqrs';
import { Inject } from '@nestjs/common';
import { CreateProjectCategoryCommand } from './create-project-category.command';
import { ProjectCategory } from '../../../domains/project-category/project-category';
import { ProjectCategoryCommandRepository } from '../../../domains/project-category/project-category.command.repository';

@CommandHandler(CreateProjectCategoryCommand)
export class CreateProjectCategoryExecute implements ICommandHandler {

    constructor(
        @Inject('ProjectCategoryCommandRepository') private projectCategoryRepository: ProjectCategoryCommandRepository,
        private readonly publisher: EventPublisher) {
    }

    /**
     * @param {CreateProjectCategoryCommand} command
     * @param {(value?) => void} resolve
     * @returns {Promise}
     */
    async execute(command: CreateProjectCategoryCommand, resolve: (value?) => void) {

        resolve();
github notadd / next / packages / logger / commands / handlers / logger-create.handler.js View on Github external
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const cqrs_1 = require("@nestjs/cqrs");
const logger_create_command_1 = require("../logger-create.command");
let LoggerCreateHandler = class LoggerCreateHandler {
    async execute(command, resolve) {
        resolve();
    }
};
LoggerCreateHandler = __decorate([
    cqrs_1.CommandHandler(logger_create_command_1.LoggerCreateCommand)
], LoggerCreateHandler);
exports.LoggerCreateHandler = LoggerCreateHandler;

//# sourceMappingURL=logger-create.handler.js.map
github notadd / next / src / logger / commands / handlers / logger-remove.handler.ts View on Github external
import { CommandHandler, ICommandHandler } from "@nestjs/cqrs";
import { LoggerRemoveCommand } from "../logger-remove.command";

@CommandHandler(LoggerRemoveCommand)
export class LoggerRemoveHandler implements ICommandHandler {
    /**
     * @param { LoggerRemoveCommand } command
     * @param { (value?) => void } resolve
     *
     * @returns { Promise }
     */
    async execute(command: LoggerRemoveCommand, resolve: (value?) => void) {
        resolve();
    }
}
github notadd / next / packages / injection / commands / handlers / module-install.command.handler.js View on Github external
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const cqrs_1 = require("@nestjs/cqrs");
const _1 = require("../");
let ModuleInstallCommandHandler = class ModuleInstallCommandHandler {
    execute(command, resolve) {
        return undefined;
    }
};
ModuleInstallCommandHandler = __decorate([
    cqrs_1.CommandHandler(_1.ModuleInstallCommand)
], ModuleInstallCommandHandler);
exports.ModuleInstallCommandHandler = ModuleInstallCommandHandler;

//# sourceMappingURL=module-install.command.handler.js.map
github xmlking / ngx-starter-kit / apps / api / src / app / notifications / notification / commands / handlers / notifications.handler.ts View on Github external
import { NotificationService } from '../../notification.service';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { GenericCommand } from '../../../../shared';
import { NotificationsDeleteCommand } from '../notifications-delete.command';
import { NotificationsMarkAsReadCommand } from '../notifications-make-as-read.command';
import { NotificationsMarkAllAsReadCommand } from '../notifications-make-all-as-read.command';
import { Logger } from '@nestjs/common';

@CommandHandler(GenericCommand)
export class NotificationsHandler implements ICommandHandler {
  private readonly logger = new Logger(NotificationsHandler.name);
  constructor(private readonly notificationService: NotificationService) {}

  public async execute(command: GenericCommand): Promise {
    const { type, payload, user } = command;
    switch (type) {
      case NotificationsDeleteCommand.type: {
        return await this.notificationService.onDeleteNotification(new NotificationsDeleteCommand(payload, user));
      }
      case NotificationsMarkAsReadCommand.type: {
        return await this.notificationService.onMarkAsRead(new NotificationsMarkAsReadCommand(payload, user));
      }
      case NotificationsMarkAllAsReadCommand.type: {
        return await this.notificationService.onMarkAllAsRead(new NotificationsMarkAllAsReadCommand(payload, user));
      }
github backstopmedia / nest-book-example / src / modules / keyword / commands / handlers / unlinkKeywordEntry.handler.ts View on Github external
import { Inject } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { Sequelize } from 'sequelize-typescript';
import { UnlinkKeywordEntryCommand } from '../impl/unlinkKeywordEntry.command';
import { Keyword } from '../../keyword.entity';

@CommandHandler(UnlinkKeywordEntryCommand)
export class UnlinkKeywordEntryCommandHandler implements ICommandHandler {
    constructor(
        @Inject('KeywordRepository') private readonly keywordRepository: typeof Keyword,
        @Inject('SequelizeInstance') private readonly sequelizeInstance: Sequelize
    ) { }

    async execute(command: UnlinkKeywordEntryCommand, resolve: (error?: Error) => void) {
        let caught: Error;

        try {
            await this.sequelizeInstance.transaction(async transaction => {
                const keyword = await this.keywordRepository.findOrCreate({
                    where: {
                        keyword: command.keyword
                    },
                    transaction
github notadd / next / packages / logger / commands / handlers / logger-list.handler.js View on Github external
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const cqrs_1 = require("@nestjs/cqrs");
const logger_list_command_1 = require("../logger-list.command");
let LoggerListHandler = class LoggerListHandler {
    async execute(command, resolve) {
        resolve();
    }
};
LoggerListHandler = __decorate([
    cqrs_1.CommandHandler(logger_list_command_1.LoggerListCommand)
], LoggerListHandler);
exports.LoggerListHandler = LoggerListHandler;

//# sourceMappingURL=logger-list.handler.js.map

@nestjs/cqrs

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

MIT
Latest version published 3 months ago

Package Health Score

86 / 100
Full package analysis

Similar packages