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

Implementing CQRS in NestJS #3

Merged
merged 3 commits into from
Jun 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

strategy:
matrix:
app: [driver, notification, nuber-app, ride, user-service, auth]
app: [driver, notification, nuber-app, ride, user-service]

steps:
- name: Checkout code
Expand Down
22 changes: 0 additions & 22 deletions apps/auth/src/auth.controller.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions apps/auth/src/auth.controller.ts

This file was deleted.

32 changes: 0 additions & 32 deletions apps/auth/src/auth.module.ts

This file was deleted.

26 changes: 0 additions & 26 deletions apps/auth/src/auth.service.ts

This file was deleted.

8 changes: 0 additions & 8 deletions apps/auth/src/email/email.module.ts

This file was deleted.

27 changes: 0 additions & 27 deletions apps/auth/src/email/email.service.ts

This file was deleted.

17 changes: 0 additions & 17 deletions apps/auth/src/main.ts

This file was deleted.

50 changes: 0 additions & 50 deletions apps/auth/src/queues/producer.email.ts

This file was deleted.

24 changes: 0 additions & 24 deletions apps/auth/test/app.e2e-spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions apps/auth/test/jest-e2e.json

This file was deleted.

14 changes: 0 additions & 14 deletions apps/driver/src/config/db.ts

This file was deleted.

24 changes: 0 additions & 24 deletions apps/driver/src/database/database.module.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/driver/src/driver.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Controller, Get } from '@nestjs/common';
import { DriverService } from './driver.service';
import { MessagePattern } from '@nestjs/microservices';
import { DriverCreateCmd } from '@app/common/driver/cmd/driver.create.cmd';
import { DriverDto } from '@app/common/driver/event/driver.dto';
import { DriverDto } from '@app/shared/events/driver/driver.dto';
import { mapDriversToDtos } from './utils/driver.mapper';
import { DriverCreateCmd } from '@app/shared/commands/driver/driver.create.cmd';

@Controller('drivers')
export class DriverController {
Expand Down
28 changes: 21 additions & 7 deletions apps/driver/src/driver.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import { Module } from '@nestjs/common';
import { DatabaseModule } from '@app/database';
import { MongooseModule } from '@nestjs/mongoose';
import { DriverController } from './driver.controller';
import { DriverService } from './driver.service';
import { MongooseModule } from '@nestjs/mongoose';
import { DatabaseModule } from './database/database.module';
import dabaConfig from './utils/daba.config';

import { Driver, DriverSchema } from './models/driver.schema';
import { LocationSchema, Location } from './models/location.schema';
import { VehicleSchema, Vehicle } from './models/vehicle.schema';
import * as dotenv from 'dotenv';

dotenv.config();

@Module({
imports: [
MongooseModule.forFeature(dabaConfig),
DatabaseModule
MongooseModule.forFeature(
[
{ name: Driver.name, schema: DriverSchema },
{ name: Location.name, schema: LocationSchema },
{ name: Vehicle.name, schema: VehicleSchema }
]
),
DatabaseModule.forRoot(process.env.MONGODB_URI, 'drivers'),
],
controllers: [DriverController],
providers: [DriverService],
})
export class DriverModule {}
export class DriverModule{
constructor() {
// call logConnection after database connection is established
DatabaseModule.logConnection('drivers');
}
}
4 changes: 1 addition & 3 deletions apps/driver/src/driver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { Model } from 'mongoose';
import * as bcrypt from 'bcrypt';
import { Driver } from './models/driver.schema';
import { DriverStatus } from './enums/driver.status';
import { mapDriverToDto, mapDriversToDtos } from './utils/driver.mapper';
import { DriverCreateCmd } from '@app/common/driver/cmd/driver.create.cmd';
import { DriverDto } from '@app/common/driver/event/driver.dto';
import { DriverCreateCmd } from '@app/shared/commands/driver/driver.create.cmd';

@Injectable()
export class DriverService {
Expand Down
5 changes: 5 additions & 0 deletions apps/driver/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { NestFactory } from '@nestjs/core';
import { DriverModule } from './driver.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import * as dotenv from 'dotenv';


dotenv.config();

async function bootstrap() {

const app = await NestFactory.createMicroservice<MicroserviceOptions>(
DriverModule,
{
Expand Down
1 change: 0 additions & 1 deletion apps/driver/src/models/driver.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { DriverStatus, DriverStatusType } from "../enums/driver.status";
import { Vehicle } from "./vehicle.schema";
import { Types } from "mongoose";


Expand Down
2 changes: 1 addition & 1 deletion apps/driver/src/utils/driver.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DriverDto } from "@app/common/driver/event/driver.dto";
import { DriverDto } from "@app/shared/events/driver/driver.dto";
import { Driver } from "../models/driver.schema";


Expand Down
4 changes: 2 additions & 2 deletions apps/nuber-app/src/rest/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { UserService } from '../services/user-service';
import { DriverCreateCmd } from "@app/common/driver/cmd/driver.create.cmd";
import { UserCreateCommand } from "@app/common/user/cmd/user.create.cmd";
import { UserCreateCommand } from '@app/shared/commands/auth/user.create.cmd';
import { DriverCreateCmd } from '@app/shared/commands/driver/driver.create.cmd';



Expand Down
2 changes: 1 addition & 1 deletion apps/nuber-app/src/rest/driver.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get } from "@nestjs/common";
import { DriverService } from "../services/driver-service";
import { DriverDto } from "@app/common/driver/event/driver.dto";
import { DriverDto } from "@app/shared/events/driver/driver.dto";



Expand Down
Loading
Loading