├── .gitignore ├── docker-compose.yml ├── order-microservice ├── .dockerignore ├── .gitignore ├── .prettierrc ├── README.md ├── dockerfile ├── nest-cli.json ├── package-lock.json ├── package.json ├── src │ ├── app.module.ts │ ├── config.ts │ ├── main.ts │ └── order │ │ ├── dto │ │ ├── create-order.dto.ts │ │ ├── pay-order.dto.ts │ │ ├── payment-details.dto.ts │ │ └── payment-status.enum.ts │ │ ├── enums │ │ └── order-status.enum.ts │ │ ├── interfaces │ │ └── order.interface.ts │ │ ├── order.constants.ts │ │ ├── order.controller.spec.ts │ │ ├── order.controller.ts │ │ ├── order.gateway.spec.ts │ │ ├── order.gateway.ts │ │ ├── order.module.ts │ │ ├── order.service.spec.ts │ │ ├── order.service.ts │ │ └── schemas │ │ └── order.schema.ts ├── test │ ├── app.e2e-spec.ts │ └── jest-e2e.json ├── tsconfig.build.json ├── tsconfig.json └── tslint.json ├── order-web ├── .dockerignore ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── dockerfile ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── dashboard │ │ │ ├── dashboard.component.css │ │ │ ├── dashboard.component.html │ │ │ ├── dashboard.component.spec.ts │ │ │ └── dashboard.component.ts │ │ └── orders │ │ │ ├── add-order │ │ │ ├── add-order.component.css │ │ │ ├── add-order.component.html │ │ │ └── add-order.component.ts │ │ │ ├── order.interface.ts │ │ │ ├── orders-datasource.ts │ │ │ ├── orders.component.css │ │ │ ├── orders.component.html │ │ │ ├── orders.component.ts │ │ │ ├── orders.service.ts │ │ │ └── view-order │ │ │ ├── view-order.component.css │ │ │ ├── view-order.component.html │ │ │ └── view-order.component.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json ├── payment-microservice ├── .dockerignore ├── .gitignore ├── .prettierrc ├── README.md ├── dockerfile ├── nest-cli.json ├── package-lock.json ├── package.json ├── src │ ├── app.module.ts │ ├── config.ts │ ├── main.ts │ └── payment │ │ ├── dto │ │ ├── pay-order.dto.ts │ │ ├── payment-details.dto.ts │ │ └── payment-status.enum.ts │ │ ├── payment.controller.spec.ts │ │ ├── payment.controller.ts │ │ ├── payment.module.ts │ │ ├── payment.service.spec.ts │ │ └── payment.service.ts ├── test │ ├── app.e2e-spec.ts │ └── jest-e2e.json ├── tsconfig.build.json ├── tsconfig.json └── tslint.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # OS 14 | .DS_Store 15 | 16 | # Tests 17 | /coverage 18 | /.nyc_output 19 | 20 | # IDEs and editors 21 | /.idea 22 | .project 23 | .classpath 24 | .c9/ 25 | *.launch 26 | .settings/ 27 | *.sublime-workspace 28 | 29 | # IDE - VSCode 30 | /.vs 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | web: 4 | build: ./order-web 5 | ports: 6 | - 8085:4200 7 | order: 8 | build: ./order-microservice 9 | ports: 10 | # - 8876:8876 11 | - 8877:8877 12 | environment: 13 | DB_HOST: mongo 14 | PAYMENT_HOST: payment 15 | ORDER_HOST: order 16 | links: 17 | - mongo 18 | payment: 19 | build: ./payment-microservice 20 | # ports: 21 | # - 8875:8875 22 | environment: 23 | PAYMENT_HOST: payment 24 | ORDER_HOST: order 25 | mongo: 26 | image: mongo 27 | restart: always 28 | # ports: 29 | # - 27017:27017 30 | -------------------------------------------------------------------------------- /order-microservice/.dockerignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | dist 3 | node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # OS 14 | .DS_Store 15 | 16 | # Tests 17 | /coverage 18 | /.nyc_output 19 | 20 | # IDEs and editors 21 | /.idea 22 | .project 23 | .classpath 24 | .c9/ 25 | *.launch 26 | .settings/ 27 | *.sublime-workspace 28 | 29 | # IDE - VSCode 30 | .vscode/* 31 | !.vscode/settings.json 32 | !.vscode/tasks.json 33 | !.vscode/launch.json 34 | !.vscode/extensions.json -------------------------------------------------------------------------------- /order-microservice/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # OS 14 | .DS_Store 15 | 16 | # Tests 17 | /coverage 18 | /.nyc_output 19 | 20 | # IDEs and editors 21 | /.idea 22 | .project 23 | .classpath 24 | .c9/ 25 | *.launch 26 | .settings/ 27 | *.sublime-workspace 28 | 29 | # IDE - VSCode 30 | .vscode/* 31 | !.vscode/settings.json 32 | !.vscode/tasks.json 33 | !.vscode/launch.json 34 | !.vscode/extensions.json -------------------------------------------------------------------------------- /order-microservice/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /order-microservice/README.md: -------------------------------------------------------------------------------- 1 |
4 | 5 | ## Description 6 | 7 | Sample Order Management Service developed using [Nest](https://github.com/nestjs/nest) framework: 8 | - Event-based and Message-based microservices on TCP:8876 9 | - REST Api on port HTTP:8877 10 | - Swagger (http://localhost:8877/doc) 11 | - WebSocket 12 | - MongoDb 13 | - Docker 14 | 15 | ## License 16 | 17 | MIT licensed. 18 | -------------------------------------------------------------------------------- /order-microservice/dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:12.10-slim 2 | 3 | WORKDIR /app 4 | COPY . . 5 | RUN npm install 6 | RUN npm run build 7 | 8 | EXPOSE 8876 9 | EXPOSE 8877 10 | 11 | CMD ["npm", "run", "start:prod"] 12 | -------------------------------------------------------------------------------- /order-microservice/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /order-microservice/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "order-microservice", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "license": "MIT", 7 | "scripts": { 8 | "build": "rimraf dist && tsc -p tsconfig.build.json", 9 | "format": "prettier --write \"src/**/*.ts\"", 10 | "start": "ts-node -r tsconfig-paths/register src/main.ts", 11 | "start:dev": "tsc-watch -p tsconfig.build.json --onSuccess \"node dist/main.js\"", 12 | "start:debug": "tsc-watch -p tsconfig.build.json --onSuccess \"node --inspect-brk dist/main.js\"", 13 | "start:prod": "node dist/main.js", 14 | "lint": "tslint -p tsconfig.json -c tslint.json", 15 | "test": "jest", 16 | "test:watch": "jest --watch", 17 | "test:cov": "jest --coverage", 18 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 19 | "test:e2e": "jest --config ./test/jest-e2e.json" 20 | }, 21 | "dependencies": { 22 | "@nestjs/common": "^6.0.0", 23 | "@nestjs/core": "^6.0.0", 24 | "@nestjs/microservices": "^6.8.0", 25 | "@nestjs/mongoose": "^6.1.2", 26 | "@nestjs/platform-express": "^6.0.0", 27 | "@nestjs/platform-socket.io": "^6.8.2", 28 | "@nestjs/swagger": "^3.1.0", 29 | "@nestjs/websockets": "^6.8.2", 30 | "mongoose": "^5.7.5", 31 | "reflect-metadata": "^0.1.12", 32 | "rimraf": "^2.6.2", 33 | "rxjs": "^6.3.3", 34 | "swagger-ui-express": "^4.1.1" 35 | }, 36 | "devDependencies": { 37 | "@nestjs/testing": "^6.0.0", 38 | "@types/express": "4.16.1", 39 | "@types/jest": "24.0.11", 40 | "@types/mongoose": "^5.5.18", 41 | "@types/node": "11.13.4", 42 | "@types/socket.io": "^2.1.3", 43 | "@types/supertest": "2.0.7", 44 | "jest": "24.7.1", 45 | "prettier": "1.17.0", 46 | "supertest": "4.0.2", 47 | "ts-jest": "24.0.2", 48 | "ts-node": "8.1.0", 49 | "tsc-watch": "2.2.1", 50 | "tsconfig-paths": "3.8.0", 51 | "tslint": "5.16.0", 52 | "typescript": "3.4.3" 53 | }, 54 | "jest": { 55 | "moduleFileExtensions": [ 56 | "js", 57 | "json", 58 | "ts" 59 | ], 60 | "rootDir": "src", 61 | "testRegex": ".spec.ts$", 62 | "transform": { 63 | "^.+\\.(t|j)s$": "ts-jest" 64 | }, 65 | "coverageDirectory": "../coverage", 66 | "testEnvironment": "node" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /order-microservice/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { MongooseModule } from '@nestjs/mongoose'; 3 | import { OrderModule } from './order/order.module'; 4 | import { db_host, db_name } from './config'; 5 | 6 | @Module({ 7 | imports: [ 8 | MongooseModule.forRoot(`mongodb://${db_host}/${db_name}`), 9 | OrderModule 10 | ], 11 | controllers: [], 12 | providers: [], 13 | }) 14 | export class AppModule { } 15 | -------------------------------------------------------------------------------- /order-microservice/src/config.ts: -------------------------------------------------------------------------------- 1 | export const db_host = process.env.DB_HOST || 'localhost:27017'; 2 | export const db_name = process.env.DB_NAME || 'ordermgmt'; 3 | export const order_host = process.env.ORDER_HOST || 'order'; 4 | export const payment_host = process.env.PAYMENT_HOST || 'payment'; 5 | -------------------------------------------------------------------------------- /order-microservice/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; 3 | import { AppModule } from './app.module'; 4 | import { Transport } from '@nestjs/common/enums/transport.enum'; 5 | import { order_host } from './config'; 6 | 7 | async function bootstrap() { 8 | const app = await NestFactory.create(AppModule); 9 | app.connectMicroservice({ 10 | transport: Transport.TCP, 11 | options: { 12 | retryAttempts: 5, 13 | retryDelay: 3000, 14 | host: order_host, 15 | port: 8876, 16 | }, 17 | }); 18 | 19 | await app.startAllMicroservicesAsync(); 20 | app.setGlobalPrefix('api'); 21 | app.enableCors(); 22 | const options = new DocumentBuilder() 23 | .setTitle('Orders Service') 24 | .setDescription('Manages orders') 25 | .setVersion('1.0') 26 | .addTag('orders') 27 | .setBasePath('/api') 28 | .build(); 29 | const document = SwaggerModule.createDocument(app, options); 30 | SwaggerModule.setup('doc', app, document); 31 | 32 | await app.listen(8877); 33 | } 34 | bootstrap(); 35 | -------------------------------------------------------------------------------- /order-microservice/src/order/dto/create-order.dto.ts: -------------------------------------------------------------------------------- 1 | import { OrderStatus } from "../enums/order-status.enum"; 2 | import { ApiModelProperty } from "@nestjs/swagger"; 3 | 4 | export class CreateOrderDto { 5 | @ApiModelProperty() 6 | amount: number; 7 | } -------------------------------------------------------------------------------- /order-microservice/src/order/dto/pay-order.dto.ts: -------------------------------------------------------------------------------- 1 | import { IOrder } from "../interfaces/order.interface"; 2 | import { ApiModelProperty } from "@nestjs/swagger"; 3 | 4 | export class PayOrderDto { 5 | constructor(order: IOrder) { 6 | this.id = order.id; 7 | this.amount = order.amount; 8 | this.status = order.status; 9 | this.username = order.username; 10 | } 11 | @ApiModelProperty() 12 | id: string; 13 | @ApiModelProperty() 14 | amount: number; 15 | @ApiModelProperty() 16 | status: string; 17 | @ApiModelProperty() 18 | username: string; 19 | } -------------------------------------------------------------------------------- /order-microservice/src/order/dto/payment-details.dto.ts: -------------------------------------------------------------------------------- 1 | import { PaymentStatus } from "./payment-status.enum"; 2 | import { uuid } from 'uuid'; 3 | import { ApiModelProperty } from "@nestjs/swagger"; 4 | export class PaymentDetailsDto { 5 | constructor(orderId: String) { 6 | this.orderId = orderId; 7 | this.status = PaymentStatus.Declined; 8 | this.transactionId = (Math.round(Math.random() * 999999)).toString(); 9 | } 10 | @ApiModelProperty() 11 | orderId: String; 12 | @ApiModelProperty() 13 | status: PaymentStatus; 14 | @ApiModelProperty() 15 | transactionId: String; 16 | } -------------------------------------------------------------------------------- /order-microservice/src/order/dto/payment-status.enum.ts: -------------------------------------------------------------------------------- 1 | export enum PaymentStatus { 2 | Declined = 'declined', 3 | Confirmed = 'confirmed', 4 | } -------------------------------------------------------------------------------- /order-microservice/src/order/enums/order-status.enum.ts: -------------------------------------------------------------------------------- 1 | export enum OrderStatus { 2 | Created = "created", 3 | Confirmed = "confirmed", 4 | Delivered = "delivered", 5 | Canceled = "canceled", 6 | } -------------------------------------------------------------------------------- /order-microservice/src/order/interfaces/order.interface.ts: -------------------------------------------------------------------------------- 1 | import { OrderStatus } from "../enums/order-status.enum"; 2 | import { Document } from 'mongoose'; 3 | 4 | export interface IOrder extends Document{ 5 | amount: number; 6 | username: string; 7 | status: OrderStatus; 8 | transactionId: string; 9 | createdAt: Date; 10 | } -------------------------------------------------------------------------------- /order-microservice/src/order/order.constants.ts: -------------------------------------------------------------------------------- 1 | export const ORDER_SERVICE = 'ORDER_SERVICE' -------------------------------------------------------------------------------- /order-microservice/src/order/order.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { OrderController } from './order.controller'; 3 | 4 | describe('Order Controller', () => { 5 | let controller: OrderController; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | controllers: [OrderController], 10 | }).compile(); 11 | 12 | controller = module.getDate | 10 |{{row.createdAt| date:'yyyy-MM-dd HH:mm'}} | 11 |Id | 15 |{{row._id}} | 16 |Username | 20 |{{row.username}} | 21 |Amount | 25 |{{row.amount}} | 26 |Status | 30 |{{row.status | uppercase}} | 31 |Actions | 35 |36 | 39 | 43 | | 44 |
---|