Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ES Module for the example #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "Nest CQRS module usage example",
"license": "MIT",
"type": "module",
"scripts": {
"start": "nest start --watch"
},
Expand Down
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Module } from '@nestjs/common';
import { HeroesGameModule } from './heroes/heroes.module';
import { HeroesGameModule } from './heroes/heroes.module.js';

@Module({
imports: [HeroesGameModule],
Expand Down
4 changes: 2 additions & 2 deletions src/heroes/commands/handlers/drop-ancient-item.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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';
import { HeroRepository } from '../../repository/hero.repository.js';
import { DropAncientItemCommand } from '../impl/drop-ancient-item.command.js';

@CommandHandler(DropAncientItemCommand)
export class DropAncientItemHandler
Expand Down
4 changes: 2 additions & 2 deletions src/heroes/commands/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KillDragonHandler } from './kill-dragon.handler';
import { DropAncientItemHandler } from './drop-ancient-item.handler';
import { KillDragonHandler } from './kill-dragon.handler.js';
import { DropAncientItemHandler } from './drop-ancient-item.handler.js';

export const CommandHandlers = [KillDragonHandler, DropAncientItemHandler];
4 changes: 2 additions & 2 deletions src/heroes/commands/handlers/kill-dragon.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
import * as clc from 'cli-color';
import { HeroRepository } from '../../repository/hero.repository';
import { KillDragonCommand } from '../impl/kill-dragon.command';
import { HeroRepository } from '../../repository/hero.repository.js';
import { KillDragonCommand } from '../impl/kill-dragon.command.js';

@CommandHandler(KillDragonCommand)
export class KillDragonHandler implements ICommandHandler<KillDragonCommand> {
Expand Down
2 changes: 1 addition & 1 deletion src/heroes/events/handlers/hero-found-item.handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import * as clc from 'cli-color';
import { HeroFoundItemEvent } from '../impl/hero-found-item.event';
import { HeroFoundItemEvent } from '../impl/hero-found-item.event.js';

@EventsHandler(HeroFoundItemEvent)
export class HeroFoundItemHandler implements IEventHandler<HeroFoundItemEvent> {
Expand Down
4 changes: 2 additions & 2 deletions src/heroes/events/handlers/hero-killed-dragon.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IEventHandler } from '@nestjs/cqrs';
import { EventsHandler } from '@nestjs/cqrs/dist/decorators/events-handler.decorator';
import { EventsHandler } from '@nestjs/cqrs/dist/decorators/events-handler.decorator.js';
import * as clc from 'cli-color';
import { HeroKilledDragonEvent } from '../impl/hero-killed-dragon.event';
import { HeroKilledDragonEvent } from '../impl/hero-killed-dragon.event.js';

@EventsHandler(HeroKilledDragonEvent)
export class HeroKilledDragonHandler
Expand Down
4 changes: 2 additions & 2 deletions src/heroes/events/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HeroKilledDragonHandler } from './hero-killed-dragon.handler';
import { HeroFoundItemHandler } from './hero-found-item.handler';
import { HeroKilledDragonHandler } from './hero-killed-dragon.handler.js';
import { HeroFoundItemHandler } from './hero-found-item.handler.js';

export const EventHandlers = [HeroKilledDragonHandler, HeroFoundItemHandler];
8 changes: 4 additions & 4 deletions src/heroes/heroes.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { CommandBus, QueryBus } from '@nestjs/cqrs';
import { KillDragonCommand } from './commands/impl/kill-dragon.command';
import { KillDragonDto } from './interfaces/kill-dragon-dto.interface';
import { Hero } from './models/hero.model';
import { GetHeroesQuery } from './queries/impl';
import { KillDragonCommand } from './commands/impl/kill-dragon.command.js';
import { KillDragonDto } from './interfaces/kill-dragon-dto.interface.js';
import { Hero } from './models/hero.model.js';
import { GetHeroesQuery } from './queries/impl/index.js';

@Controller('hero')
export class HeroesGameController {
Expand Down
12 changes: 6 additions & 6 deletions src/heroes/heroes.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { CommandHandlers } from './commands/handlers';
import { EventHandlers } from './events/handlers';
import { HeroesGameController } from './heroes.controller';
import { QueryHandlers } from './queries/handlers';
import { HeroRepository } from './repository/hero.repository';
import { HeroesGameSagas } from './sagas/heroes.sagas';
import { CommandHandlers } from './commands/handlers/index.js';
import { EventHandlers } from './events/handlers/index.js';
import { HeroesGameController } from './heroes.controller.js';
import { QueryHandlers } from './queries/handlers/index.js';
import { HeroRepository } from './repository/hero.repository.js';
import { HeroesGameSagas } from './sagas/heroes.sagas.js';

@Module({
imports: [CqrsModule],
Expand Down
4 changes: 2 additions & 2 deletions src/heroes/models/hero.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AggregateRoot } from '@nestjs/cqrs';
import { HeroFoundItemEvent } from '../events/impl/hero-found-item.event';
import { HeroKilledDragonEvent } from '../events/impl/hero-killed-dragon.event';
import { HeroFoundItemEvent } from '../events/impl/hero-found-item.event.js';
import { HeroKilledDragonEvent } from '../events/impl/hero-killed-dragon.event.js';

export class Hero extends AggregateRoot {
constructor(private readonly id: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/heroes/queries/handlers/get-heroes.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import * as clc from 'cli-color';
import { HeroRepository } from '../../repository/hero.repository';
import { GetHeroesQuery } from '../impl';
import { HeroRepository } from '../../repository/hero.repository.js';
import { GetHeroesQuery } from '../impl/index.js';

@QueryHandler(GetHeroesQuery)
export class GetHeroesHandler implements IQueryHandler<GetHeroesQuery> {
Expand Down
2 changes: 1 addition & 1 deletion src/heroes/queries/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { GetHeroesHandler } from './get-heroes.handler';
import { GetHeroesHandler } from './get-heroes.handler.js';

export const QueryHandlers = [GetHeroesHandler];
2 changes: 1 addition & 1 deletion src/heroes/queries/impl/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './get-heroes.query';
export * from './get-heroes.query.js';
2 changes: 1 addition & 1 deletion src/heroes/repository/fixtures/user.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Hero } from '../../models/hero.model';
import { Hero } from '../../models/hero.model.js';

export const userHero = new Hero('1234');
4 changes: 2 additions & 2 deletions src/heroes/repository/hero.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Hero } from '../models/hero.model';
import { userHero } from './fixtures/user';
import { Hero } from '../models/hero.model.js';
import { userHero } from './fixtures/user.js';

@Injectable()
export class HeroRepository {
Expand Down
4 changes: 2 additions & 2 deletions src/heroes/sagas/heroes.sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ICommand, ofType, Saga } from '@nestjs/cqrs';
import * as clc from 'cli-color';
import { Observable } from 'rxjs';
import { delay, map } from 'rxjs/operators';
import { DropAncientItemCommand } from '../commands/impl/drop-ancient-item.command';
import { HeroKilledDragonEvent } from '../events/impl/hero-killed-dragon.event';
import { DropAncientItemCommand } from '../commands/impl/drop-ancient-item.command.js';
import { HeroKilledDragonEvent } from '../events/impl/hero-killed-dragon.event.js';

const itemId = '0';

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './app.module';
import { ApplicationModule } from './app.module.js';

async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"declaration": false,
"noImplicitAny": false,
"noUnusedLocals": true,
Expand Down