├── .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 |

2 | Nest Logo 3 |

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.get(OrderController); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(controller).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /order-microservice/src/order/order.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Logger, Inject, Post, Body, Param, HttpStatus, Res, HttpCode } from '@nestjs/common'; 2 | import { OrderService } from './order.service'; 3 | import { ClientProxy, MessagePattern, EventPattern } from '@nestjs/microservices'; 4 | import { ORDER_SERVICE } from './order.constants'; 5 | import { Observable, Subscription, from } from 'rxjs'; 6 | import { PaymentDetailsDto } from './dto/payment-details.dto'; 7 | import { CreateOrderDto } from './dto/create-order.dto'; 8 | import { IOrder } from './interfaces/order.interface'; 9 | import { OrderStatus } from './enums/order-status.enum'; 10 | import { Response } from 'express'; 11 | import { ApiOkResponse, ApiInternalServerErrorResponse, ApiImplicitParam, ApiUseTags } from '@nestjs/swagger'; 12 | 13 | @Controller('orders') 14 | @ApiUseTags('orders') 15 | export class OrderController { 16 | private readonly logger = new Logger('OrderController'); 17 | constructor( 18 | @Inject(ORDER_SERVICE) private readonly client: ClientProxy, 19 | private readonly service: OrderService 20 | ) { } 21 | 22 | @Get() 23 | index(): Observable { 24 | return from(this.service.findAll()); 25 | } 26 | 27 | @Post() 28 | async create(@Res() res: Response, @Body() createOrderDto: CreateOrderDto) { 29 | if (!createOrderDto || !createOrderDto.amount || createOrderDto.amount <= 0) 30 | return res.status(HttpStatus.BAD_REQUEST).send(); 31 | 32 | try { 33 | const order = await this.service.create(createOrderDto); 34 | this.client.emit('orderCreated', order.id); 35 | return res.status(HttpStatus.CREATED).send(order); 36 | } catch (error) { 37 | this.logger.log('error in create'); 38 | this.logger.log(JSON.stringify(error)); 39 | return res.status(HttpStatus.BAD_REQUEST).send(JSON.stringify(error)); 40 | } 41 | } 42 | 43 | @Get(':id') 44 | @ApiImplicitParam({ 45 | name: 'id', 46 | required: true, 47 | description: 'Order ID', 48 | }) 49 | async details(@Res() res: Response, @Param('id') id: string) { 50 | if (!id) 51 | return res.status(HttpStatus.BAD_REQUEST).send(); 52 | 53 | const order = await this.service.findById(id); 54 | if (!order) 55 | return res.status(HttpStatus.NOT_FOUND).send(); 56 | 57 | return res.send(order); 58 | } 59 | 60 | @Get(':id/status') 61 | @ApiImplicitParam({ 62 | name: 'id', 63 | required: true, 64 | description: 'Order ID', 65 | }) 66 | async status(@Res() res: Response, @Param('id') id: string) { 67 | if (!id) 68 | return res.status(HttpStatus.BAD_REQUEST).send(); 69 | 70 | const order = await this.service.findById(id); 71 | if (!order) 72 | return res.status(HttpStatus.NOT_FOUND).send(); 73 | 74 | return res.send(order.status); 75 | } 76 | 77 | @Post(':id/cancel') 78 | @ApiImplicitParam({ 79 | name: 'id', 80 | required: true, 81 | description: 'Order ID', 82 | }) 83 | async cancel(@Res() res: Response, @Param('id') id: string) { 84 | try { 85 | const order = await this.service.cancel(id); 86 | return res.send(order); 87 | } catch (error) { 88 | this.logger.log(error); 89 | return res.status(HttpStatus.BAD_REQUEST).send(error); 90 | } 91 | } 92 | 93 | @EventPattern('orderCreated') 94 | async orderCreated(id: string) { 95 | await this.service.initiatePayment(id); 96 | } 97 | 98 | @EventPattern('paymentProcessed') 99 | async paymentProcessed(data: PaymentDetailsDto) { 100 | const order = await this.service.updatePaymentStatus(data); 101 | 102 | if (order && order.status == OrderStatus.Confirmed) 103 | this.client.emit('orderConfirmed', order.id); 104 | } 105 | 106 | @EventPattern('orderConfirmed') 107 | async orderConfirmed(id: string) { 108 | await this.service.deliver(id); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /order-microservice/src/order/order.gateway.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { OrderGateway } from './order.gateway'; 3 | 4 | describe('OrderGateway', () => { 5 | let gateway: OrderGateway; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [OrderGateway], 10 | }).compile(); 11 | 12 | gateway = module.get(OrderGateway); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(gateway).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /order-microservice/src/order/order.gateway.ts: -------------------------------------------------------------------------------- 1 | import { SubscribeMessage, WebSocketGateway, OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect, WsResponse, WebSocketServer } from '@nestjs/websockets'; 2 | import { Logger } from '@nestjs/common'; 3 | import { Socket, Server } from 'socket.io'; 4 | import { IOrder } from './interfaces/order.interface'; 5 | 6 | @WebSocketGateway() 7 | export class OrderGateway { 8 | private readonly logger = new Logger('OrderGateway'); 9 | 10 | @WebSocketServer() 11 | wss: Server; 12 | 13 | newOrderAdded(payload: IOrder): void { 14 | this.wss.emit('newOrderAdded', payload); 15 | } 16 | 17 | orderStatusUpdated(payload: IOrder): void { 18 | this.wss.emit('orderStatusUpdated', payload); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /order-microservice/src/order/order.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { OrderService } from './order.service'; 3 | import { OrderController } from './order.controller'; 4 | import { MongooseModule } from '@nestjs/mongoose'; 5 | import { OrderSchema } from './schemas/order.schema'; 6 | import { ClientsModule, Transport } from '@nestjs/microservices'; 7 | import { ORDER_SERVICE } from './order.constants'; 8 | import { order_host } from '../config'; 9 | import { OrderGateway } from './order.gateway'; 10 | 11 | @Module({ 12 | imports: [ 13 | ClientsModule.register([{ 14 | name: ORDER_SERVICE, transport: Transport.TCP, options: { 15 | host: order_host, 16 | port: 8876 17 | } 18 | }]), 19 | MongooseModule.forFeature([{ name: 'Order', schema: OrderSchema }]) 20 | ], 21 | providers: [ 22 | OrderService, 23 | OrderGateway 24 | ], 25 | controllers: [OrderController] 26 | }) 27 | export class OrderModule { } 28 | -------------------------------------------------------------------------------- /order-microservice/src/order/order.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { OrderService } from './order.service'; 3 | 4 | describe('OrderService', () => { 5 | let service: OrderService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [OrderService], 10 | }).compile(); 11 | 12 | service = module.get(OrderService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /order-microservice/src/order/order.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Logger } from '@nestjs/common'; 2 | import { ClientOptions, Transport, ClientProxyFactory } from '@nestjs/microservices'; 3 | import { PaymentDetailsDto } from './dto/payment-details.dto'; 4 | import { PaymentStatus } from './dto/payment-status.enum'; 5 | import { InjectModel } from '@nestjs/mongoose'; 6 | import { Model } from 'mongoose'; 7 | import { IOrder } from './interfaces/order.interface'; 8 | import { CreateOrderDto } from './dto/create-order.dto'; 9 | import { OrderStatus } from './enums/order-status.enum'; 10 | import { PayOrderDto } from './dto/pay-order.dto'; 11 | import { payment_host } from '../config'; 12 | import { OrderGateway } from './order.gateway'; 13 | 14 | @Injectable() 15 | export class OrderService { 16 | private readonly logger = new Logger('OrderService'); 17 | 18 | private readonly paymentClient = ClientProxyFactory.create({ 19 | transport: Transport.TCP, 20 | options: { 21 | host: payment_host, 22 | port: 8875 23 | } 24 | }); 25 | 26 | constructor( 27 | @InjectModel('Order') private readonly model: Model, 28 | private readonly webSocket: OrderGateway 29 | ) { 30 | } 31 | 32 | async findAll(): Promise { 33 | return await this.model.find().sort({ createdAt: 'descending' }).exec(); 34 | } 35 | 36 | async findById(id: string) { 37 | return await this.model.findById(id); 38 | } 39 | 40 | async create(createOrderDto: CreateOrderDto): Promise { 41 | const order = new this.model(createOrderDto); 42 | this.webSocket.newOrderAdded(order); 43 | return await order.save(); 44 | } 45 | 46 | async initiatePayment(id: String) { 47 | const order = await this.model.findById(id); 48 | this.paymentClient.send('initiatePayment', new PayOrderDto(order)).subscribe(async (trxId) => { 49 | order.transactionId = trxId; 50 | await order.save() 51 | }); 52 | } 53 | 54 | async updatePaymentStatus(data: PaymentDetailsDto): Promise { 55 | const order = await this.model.findById(data.orderId); 56 | 57 | if (!order || order.status !== OrderStatus.Created) return; 58 | 59 | switch (data.status) { 60 | case PaymentStatus.Confirmed: 61 | order.status = OrderStatus.Confirmed; 62 | break; 63 | case PaymentStatus.Declined: 64 | order.status = OrderStatus.Canceled; 65 | break; 66 | 67 | default: 68 | break; 69 | } 70 | this.webSocket.orderStatusUpdated(order); 71 | return await order.save(); 72 | } 73 | 74 | async cancel(id: string): Promise { 75 | const order = await this.model.findById(id); 76 | switch (order.status) { 77 | case OrderStatus.Confirmed: 78 | case OrderStatus.Created: 79 | order.status = OrderStatus.Canceled; 80 | this.paymentClient.emit('paymentCanceled', order.transactionId); 81 | this.webSocket.orderStatusUpdated(order); 82 | break; 83 | 84 | default: 85 | throw "Cannot cancel due to wrong status"; 86 | } 87 | return await order.save(); 88 | } 89 | 90 | async deliver(id: string) { 91 | const wss = this.webSocket; 92 | const model = this.model; 93 | setTimeout(async function () { 94 | const order = await model.findById(id); 95 | 96 | if (order.status !== OrderStatus.Confirmed) 97 | throw "Cannot deliver due to wrong status"; 98 | 99 | order.status = OrderStatus.Delivered; 100 | wss.orderStatusUpdated(order); 101 | await order.save(); 102 | }, Math.floor((Math.random() * 3) + 1) * 3000); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /order-microservice/src/order/schemas/order.schema.ts: -------------------------------------------------------------------------------- 1 | import * as mongoose from 'mongoose'; 2 | import { OrderStatus } from '../enums/order-status.enum'; 3 | 4 | export const OrderSchema = new mongoose.Schema({ 5 | amount: Number, 6 | username: { type: String, default: 'mock-user' }, 7 | status: { type: String, default: OrderStatus.Created }, 8 | transactionId: String, 9 | createdAt: { type: Date, default: Date.now }, 10 | }); -------------------------------------------------------------------------------- /order-microservice/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import * as request from 'supertest'; 3 | import { AppModule } from './../src/app.module'; 4 | 5 | describe('AppController (e2e)', () => { 6 | let app; 7 | 8 | beforeEach(async () => { 9 | const moduleFixture: TestingModule = await Test.createTestingModule({ 10 | imports: [AppModule], 11 | }).compile(); 12 | 13 | app = moduleFixture.createNestApplication(); 14 | await app.init(); 15 | }); 16 | 17 | it('/ (GET)', () => { 18 | return request(app.getHttpServer()) 19 | .get('/') 20 | .expect(200) 21 | .expect('Hello World!'); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /order-microservice/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /order-microservice/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /order-microservice/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "target": "es2017", 9 | "sourceMap": true, 10 | "outDir": "./dist", 11 | "baseUrl": "./", 12 | "incremental": true 13 | }, 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /order-microservice/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended"], 4 | "jsRules": { 5 | "no-unused-expression": true 6 | }, 7 | "rules": { 8 | "quotemark": [true, "single"], 9 | "member-access": [false], 10 | "ordered-imports": [false], 11 | "max-line-length": [true, 150], 12 | "member-ordering": [false], 13 | "interface-name": [false], 14 | "arrow-parens": false, 15 | "object-literal-sort-keys": false 16 | }, 17 | "rulesDirectory": [] 18 | } 19 | -------------------------------------------------------------------------------- /order-web/.dockerignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /order-web/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /order-web/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /order-web/README.md: -------------------------------------------------------------------------------- 1 | ## Order Web 2 | 3 | Sample Order Management Web Application developed using [Angular](https://angular.io) framework: 4 | - Angular Material 5 | - WebSocket 6 | - Docker 7 | 8 | ## License 9 | 10 | MIT licensed. 11 | -------------------------------------------------------------------------------- /order-web/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "order-web": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/order-web", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": false, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 28 | "src/styles.css" 29 | ], 30 | "scripts": [] 31 | }, 32 | "configurations": { 33 | "production": { 34 | "fileReplacements": [ 35 | { 36 | "replace": "src/environments/environment.ts", 37 | "with": "src/environments/environment.prod.ts" 38 | } 39 | ], 40 | "optimization": true, 41 | "outputHashing": "all", 42 | "sourceMap": false, 43 | "extractCss": true, 44 | "namedChunks": false, 45 | "aot": true, 46 | "extractLicenses": true, 47 | "vendorChunk": false, 48 | "buildOptimizer": true, 49 | "budgets": [ 50 | { 51 | "type": "initial", 52 | "maximumWarning": "2mb", 53 | "maximumError": "5mb" 54 | }, 55 | { 56 | "type": "anyComponentStyle", 57 | "maximumWarning": "6kb", 58 | "maximumError": "10kb" 59 | } 60 | ] 61 | } 62 | } 63 | }, 64 | "serve": { 65 | "builder": "@angular-devkit/build-angular:dev-server", 66 | "options": { 67 | "browserTarget": "order-web:build" 68 | }, 69 | "configurations": { 70 | "production": { 71 | "browserTarget": "order-web:build:production" 72 | } 73 | } 74 | }, 75 | "extract-i18n": { 76 | "builder": "@angular-devkit/build-angular:extract-i18n", 77 | "options": { 78 | "browserTarget": "order-web:build" 79 | } 80 | }, 81 | "test": { 82 | "builder": "@angular-devkit/build-angular:karma", 83 | "options": { 84 | "main": "src/test.ts", 85 | "polyfills": "src/polyfills.ts", 86 | "tsConfig": "tsconfig.spec.json", 87 | "karmaConfig": "karma.conf.js", 88 | "assets": [ 89 | "src/favicon.ico", 90 | "src/assets" 91 | ], 92 | "styles": [ 93 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 94 | "src/styles.css" 95 | ], 96 | "scripts": [] 97 | } 98 | }, 99 | "lint": { 100 | "builder": "@angular-devkit/build-angular:tslint", 101 | "options": { 102 | "tsConfig": [ 103 | "tsconfig.app.json", 104 | "tsconfig.spec.json", 105 | "e2e/tsconfig.json" 106 | ], 107 | "exclude": [ 108 | "**/node_modules/**" 109 | ] 110 | } 111 | }, 112 | "e2e": { 113 | "builder": "@angular-devkit/build-angular:protractor", 114 | "options": { 115 | "protractorConfig": "e2e/protractor.conf.js", 116 | "devServerTarget": "order-web:serve" 117 | }, 118 | "configurations": { 119 | "production": { 120 | "devServerTarget": "order-web:serve:production" 121 | } 122 | } 123 | } 124 | } 125 | } 126 | }, 127 | "defaultProject": "order-web" 128 | } -------------------------------------------------------------------------------- /order-web/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /order-web/dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:12.10-slim 2 | 3 | WORKDIR /app 4 | COPY . . 5 | RUN npm install 6 | 7 | EXPOSE 4200 8 | 9 | CMD ["npm", "start"] 10 | -------------------------------------------------------------------------------- /order-web/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /order-web/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('order-web app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /order-web/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /order-web/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /order-web/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/order-web'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /order-web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "order-web", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve --host 0.0.0.0", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~8.2.9", 15 | "@angular/cdk": "~8.2.2", 16 | "@angular/common": "~8.2.9", 17 | "@angular/compiler": "~8.2.9", 18 | "@angular/core": "~8.2.9", 19 | "@angular/forms": "~8.2.9", 20 | "@angular/material": "^8.2.2", 21 | "@angular/platform-browser": "~8.2.9", 22 | "@angular/platform-browser-dynamic": "~8.2.9", 23 | "@angular/router": "~8.2.9", 24 | "hammerjs": "^2.0.8", 25 | "ngx-socket-io": "^3.0.1", 26 | "rxjs": "~6.4.0", 27 | "tslib": "^1.10.0", 28 | "zone.js": "~0.9.1" 29 | }, 30 | "devDependencies": { 31 | "@angular-devkit/build-angular": "~0.803.7", 32 | "@angular/cli": "~8.3.7", 33 | "@angular/compiler-cli": "~8.2.9", 34 | "@angular/language-service": "~8.2.9", 35 | "@types/jasmine": "~3.3.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "@types/node": "^8.10.54", 38 | "codelyzer": "^5.0.0", 39 | "jasmine-core": "~3.4.0", 40 | "jasmine-spec-reporter": "~4.2.1", 41 | "karma": "~4.1.0", 42 | "karma-chrome-launcher": "~2.2.0", 43 | "karma-coverage-istanbul-reporter": "~2.0.1", 44 | "karma-jasmine": "~2.0.1", 45 | "karma-jasmine-html-reporter": "^1.4.0", 46 | "protractor": "~5.4.0", 47 | "ts-node": "~7.0.0", 48 | "tslint": "~5.15.0", 49 | "typescript": "~3.5.3" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /order-web/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { OrdersComponent } from './orders/orders.component'; 4 | import { DashboardComponent } from './dashboard/dashboard.component'; 5 | 6 | 7 | const routes: Routes = [{ 8 | path: 'orders', 9 | component: OrdersComponent, 10 | data: { title: 'List of orders' } 11 | }, { 12 | path: '', 13 | component: DashboardComponent, 14 | data: { title: 'Dashboard' } 15 | }]; 16 | 17 | @NgModule({ 18 | imports: [RouterModule.forRoot(routes)], 19 | exports: [RouterModule] 20 | }) 21 | export class AppRoutingModule { } 22 | -------------------------------------------------------------------------------- /order-web/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .sidenav-container { 2 | height: 100%; 3 | } 4 | 5 | .sidenav { 6 | width: 200px; 7 | } 8 | 9 | .sidenav .mat-toolbar { 10 | background: inherit; 11 | } 12 | 13 | .mat-toolbar.mat-primary { 14 | position: sticky; 15 | top: 0; 16 | z-index: 1; 17 | } 18 | 19 | .container { 20 | margin: 20px; 21 | } -------------------------------------------------------------------------------- /order-web/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Order Management 5 | Orders 6 | 7 |
8 | 9 |
10 |
11 |
-------------------------------------------------------------------------------- /order-web/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture,TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | import { LayoutModule } from '@angular/cdk/layout'; 5 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; 6 | import { MatButtonModule } from '@angular/material/button'; 7 | import { MatIconModule } from '@angular/material/icon'; 8 | import { MatListModule } from '@angular/material/list'; 9 | import { MatSidenavModule } from '@angular/material/sidenav'; 10 | import { MatToolbarModule } from '@angular/material/toolbar'; 11 | 12 | describe('AppComponent', () => { 13 | let component: AppComponent; 14 | let fixture: ComponentFixture; 15 | beforeEach(async(() => { 16 | TestBed.configureTestingModule({ 17 | imports: [ 18 | NoopAnimationsModule, 19 | LayoutModule, 20 | MatButtonModule, 21 | MatIconModule, 22 | MatListModule, 23 | MatSidenavModule, 24 | MatToolbarModule, 25 | RouterTestingModule 26 | ], 27 | declarations: [ 28 | AppComponent 29 | ], 30 | }).compileComponents(); 31 | })); 32 | 33 | beforeEach(() => { 34 | fixture = TestBed.createComponent(AppComponent); 35 | component = fixture.componentInstance; 36 | fixture.detectChanges(); 37 | }); 38 | 39 | it('should compile', () => { 40 | expect(component).toBeTruthy(); 41 | }); 42 | it('should create the app', () => { 43 | const fixture = TestBed.createComponent(AppComponent); 44 | const app = fixture.debugElement.componentInstance; 45 | expect(app).toBeTruthy(); 46 | }); 47 | 48 | it(`should have as title 'order-web'`, () => { 49 | const fixture = TestBed.createComponent(AppComponent); 50 | const app = fixture.debugElement.componentInstance; 51 | expect(app.title).toEqual('order-web'); 52 | }); 53 | 54 | it('should render title', () => { 55 | const fixture = TestBed.createComponent(AppComponent); 56 | fixture.detectChanges(); 57 | const compiled = fixture.debugElement.nativeElement; 58 | expect(compiled.querySelector('.content span').textContent).toContain('order-web app is running!'); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /order-web/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; 3 | import { Observable } from 'rxjs'; 4 | import { map, shareReplay } from 'rxjs/operators'; 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | templateUrl: './app.component.html', 9 | styleUrls: ['./app.component.css'] 10 | }) 11 | export class AppComponent { 12 | 13 | isHandset$: Observable = this.breakpointObserver.observe(Breakpoints.Handset) 14 | .pipe( 15 | map(result => result.matches), 16 | shareReplay() 17 | ); 18 | 19 | constructor(private breakpointObserver: BreakpointObserver) {} 20 | title = 'order-web'; 21 | } 22 | -------------------------------------------------------------------------------- /order-web/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { LayoutModule } from '@angular/cdk/layout'; 7 | import { MatToolbarModule } from '@angular/material/toolbar'; 8 | import { MatButtonModule } from '@angular/material/button'; 9 | import { MatSidenavModule } from '@angular/material/sidenav'; 10 | import { MatIconModule } from '@angular/material/icon'; 11 | import { MatListModule } from '@angular/material/list'; 12 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 13 | import { OrdersComponent } from './orders/orders.component'; 14 | import { DashboardComponent } from './dashboard/dashboard.component'; 15 | import { MatGridListModule } from '@angular/material/grid-list'; 16 | import { MatCardModule } from '@angular/material/card'; 17 | import { MatMenuModule } from '@angular/material/menu'; 18 | import { MatTableModule } from '@angular/material/table'; 19 | import { MatPaginatorModule } from '@angular/material/paginator'; 20 | import { MatSortModule } from '@angular/material/sort'; 21 | import { HttpClientModule } from '@angular/common/http'; 22 | import { MatSnackBarModule } from '@angular/material/snack-bar'; 23 | import { AddOrderComponent } from './orders/add-order/add-order.component'; 24 | import { MatInputModule } from '@angular/material/input'; 25 | import { MatSelectModule } from '@angular/material/select'; 26 | import { MatRadioModule } from '@angular/material/radio'; 27 | import { ReactiveFormsModule, FormsModule } from '@angular/forms'; 28 | import { MatDialogModule } from '@angular/material/dialog'; 29 | import { ViewOrderComponent } from './orders/view-order/view-order.component'; 30 | import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io'; 31 | import { environment } from '../environments/environment'; 32 | 33 | const socketIoConfig: SocketIoConfig = { url: `${environment.api_protocol}${environment.api_host}:${environment.api_port}`, options: {} }; 34 | 35 | @NgModule({ 36 | declarations: [ 37 | AppComponent, 38 | OrdersComponent, 39 | DashboardComponent, 40 | AddOrderComponent, 41 | ViewOrderComponent 42 | ], 43 | imports: [ 44 | BrowserAnimationsModule, 45 | BrowserModule, 46 | HttpClientModule, 47 | AppRoutingModule, 48 | LayoutModule, 49 | MatToolbarModule, 50 | MatButtonModule, 51 | MatSidenavModule, 52 | MatIconModule, 53 | MatListModule, 54 | MatGridListModule, 55 | MatCardModule, 56 | MatMenuModule, 57 | MatTableModule, 58 | MatPaginatorModule, 59 | MatSortModule, 60 | MatSnackBarModule, 61 | MatInputModule, 62 | MatSelectModule, 63 | MatRadioModule, 64 | ReactiveFormsModule, 65 | MatDialogModule, 66 | FormsModule, 67 | SocketIoModule.forRoot(socketIoConfig), 68 | ], 69 | providers: [], 70 | bootstrap: [AppComponent], 71 | entryComponents:[ 72 | AddOrderComponent, 73 | ViewOrderComponent, 74 | ] 75 | }) 76 | export class AppModule { } 77 | -------------------------------------------------------------------------------- /order-web/src/app/dashboard/dashboard.component.css: -------------------------------------------------------------------------------- 1 | .grid-container { 2 | margin: 20px; 3 | } 4 | 5 | .dashboard-card { 6 | position: absolute; 7 | top: 15px; 8 | left: 15px; 9 | right: 15px; 10 | bottom: 15px; 11 | } 12 | 13 | .more-button { 14 | position: absolute; 15 | top: 5px; 16 | right: 10px; 17 | } 18 | 19 | .dashboard-card-content { 20 | text-align: center; 21 | } 22 | -------------------------------------------------------------------------------- /order-web/src/app/dashboard/dashboard.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Dashboard

3 | Welcome to order management application 4 |
-------------------------------------------------------------------------------- /order-web/src/app/dashboard/dashboard.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { LayoutModule } from '@angular/cdk/layout'; 2 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; 3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 4 | import { MatButtonModule } from '@angular/material/button'; 5 | import { MatCardModule } from '@angular/material/card'; 6 | import { MatGridListModule } from '@angular/material/grid-list'; 7 | import { MatIconModule } from '@angular/material/icon'; 8 | import { MatMenuModule } from '@angular/material/menu'; 9 | 10 | import { DashboardComponent } from './dashboard.component'; 11 | 12 | describe('DashboardComponent', () => { 13 | let component: DashboardComponent; 14 | let fixture: ComponentFixture; 15 | 16 | beforeEach(async(() => { 17 | TestBed.configureTestingModule({ 18 | declarations: [DashboardComponent], 19 | imports: [ 20 | NoopAnimationsModule, 21 | LayoutModule, 22 | MatButtonModule, 23 | MatCardModule, 24 | MatGridListModule, 25 | MatIconModule, 26 | MatMenuModule, 27 | ] 28 | }).compileComponents(); 29 | })); 30 | 31 | beforeEach(() => { 32 | fixture = TestBed.createComponent(DashboardComponent); 33 | component = fixture.componentInstance; 34 | fixture.detectChanges(); 35 | }); 36 | 37 | it('should compile', () => { 38 | expect(component).toBeTruthy(); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /order-web/src/app/dashboard/dashboard.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { map } from 'rxjs/operators'; 3 | import { Breakpoints, BreakpointObserver } from '@angular/cdk/layout'; 4 | 5 | @Component({ 6 | selector: 'app-dashboard', 7 | templateUrl: './dashboard.component.html', 8 | styleUrls: ['./dashboard.component.css'] 9 | }) 10 | export class DashboardComponent { 11 | /** Based on the screen size, switch from standard to one column per row */ 12 | cards = this.breakpointObserver.observe(Breakpoints.Handset).pipe( 13 | map(({ matches }) => { 14 | if (matches) { 15 | return [ 16 | { title: 'Card 1', cols: 1, rows: 1 }, 17 | { title: 'Card 2', cols: 1, rows: 1 }, 18 | { title: 'Card 3', cols: 1, rows: 1 }, 19 | { title: 'Card 4', cols: 1, rows: 1 } 20 | ]; 21 | } 22 | 23 | return [ 24 | { title: 'Card 1', cols: 2, rows: 1 }, 25 | { title: 'Card 2', cols: 1, rows: 1 }, 26 | { title: 'Card 3', cols: 1, rows: 2 }, 27 | { title: 'Card 4', cols: 1, rows: 1 } 28 | ]; 29 | }) 30 | ); 31 | 32 | constructor(private breakpointObserver: BreakpointObserver) {} 33 | } 34 | -------------------------------------------------------------------------------- /order-web/src/app/orders/add-order/add-order.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibghz/nestjs-microservices-docker/8075170fc4e6033a586f7cadd9a364697d92353e/order-web/src/app/orders/add-order/add-order.component.css -------------------------------------------------------------------------------- /order-web/src/app/orders/add-order/add-order.component.html: -------------------------------------------------------------------------------- 1 |

New Order

2 |
3 |
4 |
5 | 6 | 7 | 8 |
9 |
10 |
11 |
12 | 13 | 15 |
-------------------------------------------------------------------------------- /order-web/src/app/orders/add-order/add-order.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { MatDialogRef } from '@angular/material/dialog'; 3 | 4 | @Component({ 5 | selector: 'app-add-order', 6 | templateUrl: './add-order.component.html', 7 | styleUrls: ['./add-order.component.css'] 8 | }) 9 | export class AddOrderComponent { 10 | amount: number = 0; 11 | 12 | constructor( 13 | public dialogRef: MatDialogRef 14 | ) { } 15 | 16 | onCancel(): void { 17 | this.dialogRef.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /order-web/src/app/orders/order.interface.ts: -------------------------------------------------------------------------------- 1 | export interface IOrder { 2 | _id: string; 3 | amount: number; 4 | status: string; 5 | username: string; 6 | transactionId: string; 7 | createdAt: Date; 8 | } -------------------------------------------------------------------------------- /order-web/src/app/orders/orders-datasource.ts: -------------------------------------------------------------------------------- 1 | import { DataSource } from '@angular/cdk/collections'; 2 | import { MatPaginator } from '@angular/material/paginator'; 3 | import { MatSort } from '@angular/material/sort'; 4 | import { map } from 'rxjs/operators'; 5 | import { Observable, of as observableOf, merge } from 'rxjs'; 6 | import { Injectable } from '@angular/core'; 7 | import { IOrder } from './order.interface'; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class OrdersDataSource extends DataSource { 13 | data: IOrder[] = []; 14 | paginator: MatPaginator; 15 | sort: MatSort; 16 | 17 | constructor() { 18 | super(); 19 | } 20 | 21 | connect(): Observable { 22 | const dataMutations = [ 23 | observableOf(this.data), 24 | this.paginator.page, 25 | this.sort.sortChange 26 | ]; 27 | 28 | return merge(...dataMutations).pipe(map(() => { 29 | return this.getPagedData(this.getSortedData([...this.data])); 30 | })); 31 | } 32 | 33 | disconnect() { } 34 | 35 | private getPagedData(data: IOrder[]) { 36 | const startIndex = this.paginator.pageIndex * this.paginator.pageSize; 37 | return data.splice(startIndex, this.paginator.pageSize); 38 | } 39 | 40 | private getSortedData(data: IOrder[]) { 41 | if (!this.sort.active || this.sort.direction === '') { 42 | return data; 43 | } 44 | 45 | return data.sort((a, b) => { 46 | const isAsc = this.sort.direction === 'asc'; 47 | switch (this.sort.active) { 48 | case 'createdAt': return compare(a.createdAt, b.createdAt, isAsc); 49 | case 'amount': return compare(a.amount, b.amount, isAsc); 50 | case 'id': return compare(+a._id, +b._id, isAsc); 51 | case 'transactionId': return compare(a.transactionId, b.transactionId, isAsc); 52 | case 'status': return compare(a.status, b.status, isAsc); 53 | case 'username': return compare(a.username, b.username, isAsc); 54 | default: return 0; 55 | } 56 | }); 57 | } 58 | } 59 | 60 | /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ 61 | function compare(a, b, isAsc) { 62 | return (a < b ? -1 : 1) * (isAsc ? 1 : -1); 63 | } 64 | -------------------------------------------------------------------------------- /order-web/src/app/orders/orders.component.css: -------------------------------------------------------------------------------- 1 | .full-width-table { 2 | width: 100%; 3 | } 4 | 5 | .btn-new { 6 | position: fixed; 7 | bottom: 10px; 8 | right: 40px; 9 | } 10 | 11 | .pd-20 { 12 | padding: 20px; 13 | } 14 | 15 | .label { 16 | display: inline; 17 | padding: .5em; 18 | color: #fff; 19 | text-align: center; 20 | white-space: nowrap; 21 | vertical-align: baseline; 22 | border-radius: .25em; 23 | } 24 | 25 | .created { 26 | background-color: #007bff; 27 | } 28 | 29 | .confirmed { 30 | background-color: #28a745; 31 | } 32 | 33 | .delivered { 34 | background-color: #aaa; 35 | } 36 | 37 | .canceled { 38 | background-color: #dc3545; 39 | } -------------------------------------------------------------------------------- /order-web/src/app/orders/orders.component.html: -------------------------------------------------------------------------------- 1 | 4 |

Orders

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 44 | 45 | 46 | 47 | 48 |
Date{{row.createdAt| date:'yyyy-MM-dd HH:mm'}}Id{{row._id}}Username{{row.username}}Amount{{row.amount}}Status{{row.status | uppercase}}Actions 36 | 39 | 43 |
49 | 50 | 52 | 53 |
54 |
-------------------------------------------------------------------------------- /order-web/src/app/orders/orders.component.ts: -------------------------------------------------------------------------------- 1 | import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core'; 2 | import { MatPaginator } from '@angular/material/paginator'; 3 | import { MatSort } from '@angular/material/sort'; 4 | import { MatTable } from '@angular/material/table'; 5 | import { MatSnackBar } from '@angular/material/snack-bar'; 6 | import { OrdersDataSource } from './orders-datasource'; 7 | import { OrdersService } from './orders.service'; 8 | import { MatDialog } from '@angular/material/dialog'; 9 | import { AddOrderComponent } from './add-order/add-order.component'; 10 | import { ViewOrderComponent } from './view-order/view-order.component'; 11 | import { IOrder } from './order.interface'; 12 | 13 | @Component({ 14 | selector: 'app-orders', 15 | templateUrl: './orders.component.html', 16 | styleUrls: ['./orders.component.css'] 17 | }) 18 | export class OrdersComponent implements AfterViewInit, OnInit { 19 | 20 | @ViewChild(MatPaginator, { static: false }) 21 | paginator: MatPaginator; 22 | 23 | @ViewChild(MatSort, { static: false }) 24 | sort: MatSort; 25 | 26 | @ViewChild(MatTable, { static: false }) 27 | table: MatTable; 28 | 29 | constructor( 30 | private service: OrdersService, 31 | private dataSource: OrdersDataSource, 32 | private alert: MatSnackBar, 33 | public dialog: MatDialog 34 | ) { } 35 | 36 | displayedColumns = ['createdAt', 'username', 'amount', 'status', 'actions']; 37 | 38 | ngOnInit() { 39 | this.service.findAll().subscribe((data: IOrder[]) => { 40 | this.dataSource.data = data; 41 | this.table.dataSource = this.dataSource; 42 | }); 43 | 44 | this.service.newOrderAdded.subscribe(order => { 45 | this.dataSource.data.unshift(order); 46 | this.table.dataSource = []; 47 | this.table.dataSource = this.dataSource; 48 | this.table.renderRows(); 49 | }); 50 | 51 | this.service.orderStatusUpdated.subscribe(order => { 52 | const data = []; 53 | for (const item of this.dataSource.data) { 54 | if (order._id === item._id) 55 | data.push(order); 56 | else 57 | data.push(item); 58 | } 59 | this.dataSource.data = data; 60 | this.table.dataSource = []; 61 | this.table.dataSource = this.dataSource; 62 | this.table.renderRows(); 63 | }); 64 | } 65 | 66 | ngAfterViewInit() { 67 | this.dataSource.sort = this.sort; 68 | this.dataSource.paginator = this.paginator; 69 | } 70 | 71 | onCancel(id: string) { 72 | this.service.cancelOrder(id).subscribe(() => this.showAlert("Order canceled successfully"), 73 | error => { 74 | this.showAlert(error); 75 | }); 76 | } 77 | 78 | onCreate(): void { 79 | const dialogRef = this.dialog.open(AddOrderComponent); 80 | try { 81 | dialogRef.afterClosed().subscribe(amount => { 82 | this.service.createOrder(amount).subscribe(() => this.showAlert("Order created successfully"), 83 | error => { 84 | this.showAlert(error); 85 | }); 86 | }); 87 | } finally { } 88 | } 89 | 90 | onView(id: string): void { 91 | this.service.find(id).subscribe(order => { 92 | this.dialog.open(ViewOrderComponent, { 93 | data: order, 94 | }); 95 | }); 96 | } 97 | 98 | showAlert(msg: string): void { 99 | this.alert.open(msg, '', { duration: 5000 }) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /order-web/src/app/orders/orders.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Socket } from 'ngx-socket-io'; 4 | import { IOrder } from './order.interface'; 5 | import { environment } from '../../environments/environment'; 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class OrdersService { 11 | private readonly api_root: string = `${environment.api_protocol}${environment.api_host}:${environment.api_port}/api/orders`; 12 | newOrderAdded = this.socket.fromEvent('newOrderAdded'); 13 | orderStatusUpdated = this.socket.fromEvent('orderStatusUpdated'); 14 | 15 | constructor( 16 | private http: HttpClient, 17 | private socket: Socket, 18 | ) { } 19 | 20 | findAll() { 21 | return this.http.get(this.api_root); 22 | } 23 | 24 | find(id: string) { 25 | if (!id) return; 26 | return this.http.get(this.api_root + '/' + id) 27 | } 28 | 29 | createOrder(amount: number) { 30 | if (!amount) return; 31 | return this.http.post(this.api_root, { amount }); 32 | } 33 | 34 | cancelOrder(id: string) { 35 | const confirmed = confirm("Are you sure to cancel this order?"); 36 | if (!confirmed) return; 37 | return this.http.post(this.api_root + "/" + id + "/cancel", id); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /order-web/src/app/orders/view-order/view-order.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibghz/nestjs-microservices-docker/8075170fc4e6033a586f7cadd9a364697d92353e/order-web/src/app/orders/view-order/view-order.component.css -------------------------------------------------------------------------------- /order-web/src/app/orders/view-order/view-order.component.html: -------------------------------------------------------------------------------- 1 |

Order

2 |
3 |
4 |
5 | Date: 6 | {{order.createdAt|date:'yyyy-MM-dd HH:mm'}} 7 |
8 |
9 | Username: 10 | {{order.username}} 11 |
12 |
13 | Amount: 14 | {{order.amount}} 15 |
16 |
17 | Transaction Id: 18 | {{order.transactionId}} 19 |
20 |
21 | Status: 22 | {{order.status | uppercase}} 23 |
24 |
25 |
26 |
27 | 28 |
-------------------------------------------------------------------------------- /order-web/src/app/orders/view-order/view-order.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Inject } from '@angular/core'; 2 | import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; 3 | import { IOrder } from '../order.interface'; 4 | 5 | @Component({ 6 | selector: 'app-view-order', 7 | templateUrl: './view-order.component.html', 8 | styleUrls: ['./view-order.component.css'] 9 | }) 10 | export class ViewOrderComponent implements OnInit { 11 | 12 | constructor( 13 | public dialogRef: MatDialogRef, 14 | @Inject(MAT_DIALOG_DATA) public order: IOrder 15 | ) { } 16 | 17 | onCancel(): void { 18 | this.dialogRef.close(); 19 | } 20 | 21 | ngOnInit() { 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /order-web/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibghz/nestjs-microservices-docker/8075170fc4e6033a586f7cadd9a364697d92353e/order-web/src/assets/.gitkeep -------------------------------------------------------------------------------- /order-web/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | api_protocol: 'http://', 4 | api_host: 'localhost', 5 | api_port: '8877', 6 | }; 7 | -------------------------------------------------------------------------------- /order-web/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | api_protocol: 'http://', 8 | api_host: 'localhost', 9 | api_port: '8877', 10 | }; 11 | 12 | /* 13 | * For easier debugging in development mode, you can import the following file 14 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 15 | * 16 | * This import should be commented out in production mode because it will have a negative impact 17 | * on performance if an error is thrown. 18 | */ 19 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 20 | -------------------------------------------------------------------------------- /order-web/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibghz/nestjs-microservices-docker/8075170fc4e6033a586f7cadd9a364697d92353e/order-web/src/favicon.ico -------------------------------------------------------------------------------- /order-web/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | OrderWeb 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /order-web/src/main.ts: -------------------------------------------------------------------------------- 1 | import 'hammerjs'; 2 | import { enableProdMode } from '@angular/core'; 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | 5 | import { AppModule } from './app/app.module'; 6 | import { environment } from './environments/environment'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule) 13 | .catch(err => console.error(err)); 14 | -------------------------------------------------------------------------------- /order-web/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /order-web/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, body { height: 100%; } 4 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 5 | -------------------------------------------------------------------------------- /order-web/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /order-web/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.ts" 13 | ], 14 | "exclude": [ 15 | "src/test.ts", 16 | "src/**/*.spec.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /order-web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } -------------------------------------------------------------------------------- /order-web/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /order-web/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-var-requires": false, 64 | "object-literal-key-quotes": [ 65 | true, 66 | "as-needed" 67 | ], 68 | "object-literal-sort-keys": false, 69 | "ordered-imports": false, 70 | "quotemark": [ 71 | true, 72 | "single" 73 | ], 74 | "trailing-comma": false, 75 | "no-conflicting-lifecycle": true, 76 | "no-host-metadata-property": true, 77 | "no-input-rename": true, 78 | "no-inputs-metadata-property": true, 79 | "no-output-native": true, 80 | "no-output-on-prefix": true, 81 | "no-output-rename": true, 82 | "no-outputs-metadata-property": true, 83 | "template-banana-in-box": true, 84 | "template-no-negated-async": true, 85 | "use-lifecycle-interface": true, 86 | "use-pipe-transform-interface": true 87 | }, 88 | "rulesDirectory": [ 89 | "codelyzer" 90 | ] 91 | } -------------------------------------------------------------------------------- /payment-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 -------------------------------------------------------------------------------- /payment-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 -------------------------------------------------------------------------------- /payment-microservice/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /payment-microservice/README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 | ## Description 6 | 7 | Sample Payment Service developed using [Nest](https://github.com/nestjs/nest) framework: 8 | - Event-based and Message-based microservices with TCP:8875 9 | - Docker 10 | 11 | ## License 12 | 13 | MIT licensed. 14 | -------------------------------------------------------------------------------- /payment-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 8875 9 | 10 | CMD ["npm", "run", "start:prod"] 11 | -------------------------------------------------------------------------------- /payment-microservice/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /payment-microservice/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "payment-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/platform-express": "^6.0.0", 26 | "reflect-metadata": "^0.1.12", 27 | "rimraf": "^2.6.2", 28 | "rxjs": "^6.3.3" 29 | }, 30 | "devDependencies": { 31 | "@nestjs/testing": "^6.0.0", 32 | "@types/express": "4.16.1", 33 | "@types/jest": "24.0.11", 34 | "@types/node": "11.13.4", 35 | "@types/supertest": "2.0.7", 36 | "jest": "24.7.1", 37 | "prettier": "1.17.0", 38 | "supertest": "4.0.2", 39 | "ts-jest": "24.0.2", 40 | "ts-node": "8.1.0", 41 | "tsc-watch": "2.2.1", 42 | "tsconfig-paths": "3.8.0", 43 | "tslint": "5.16.0", 44 | "typescript": "3.4.3" 45 | }, 46 | "jest": { 47 | "moduleFileExtensions": [ 48 | "js", 49 | "json", 50 | "ts" 51 | ], 52 | "rootDir": "src", 53 | "testRegex": ".spec.ts$", 54 | "transform": { 55 | "^.+\\.(t|j)s$": "ts-jest" 56 | }, 57 | "coverageDirectory": "../coverage", 58 | "testEnvironment": "node" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /payment-microservice/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { PaymentModule } from './payment/payment.module'; 3 | 4 | @Module({ 5 | imports: [PaymentModule], 6 | controllers: [], 7 | providers: [], 8 | }) 9 | export class AppModule {} 10 | -------------------------------------------------------------------------------- /payment-microservice/src/config.ts: -------------------------------------------------------------------------------- 1 | export const order_host = process.env.ORDER_HOST || 'order'; 2 | export const payment_host = process.env.PAYMENT_HOST || 'payment'; 3 | -------------------------------------------------------------------------------- /payment-microservice/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | import { Transport } from '@nestjs/common/enums/transport.enum'; 4 | import { Logger } from '@nestjs/common'; 5 | import { payment_host } from './config'; 6 | 7 | const logger = new Logger('Main'); 8 | 9 | const microserviceOptions = { 10 | transport: Transport.TCP, 11 | options: { 12 | host: payment_host, 13 | port: 8875, 14 | }, 15 | }; 16 | 17 | async function bootstrap() { 18 | const app = await NestFactory.createMicroservice(AppModule, microserviceOptions); 19 | app.listen(() => { 20 | logger.log('Payment microservice is listening...'); 21 | }); 22 | } 23 | bootstrap(); 24 | -------------------------------------------------------------------------------- /payment-microservice/src/payment/dto/pay-order.dto.ts: -------------------------------------------------------------------------------- 1 | export class PayOrderDto { 2 | id: string; 3 | amount: number; 4 | status: string; 5 | username: string; 6 | } -------------------------------------------------------------------------------- /payment-microservice/src/payment/dto/payment-details.dto.ts: -------------------------------------------------------------------------------- 1 | import { PaymentStatus } from "./payment-status.enum"; 2 | import { uuid } from 'uuid'; 3 | export class PaymentDetailsDto { 4 | constructor(orderId: string) { 5 | this.orderId = orderId; 6 | this.status = PaymentStatus.Declined; 7 | this.transactionId = (Math.round(Math.random() * 999999)).toString(); 8 | } 9 | orderId: string; 10 | status: PaymentStatus; 11 | transactionId: string; 12 | } -------------------------------------------------------------------------------- /payment-microservice/src/payment/dto/payment-status.enum.ts: -------------------------------------------------------------------------------- 1 | export enum PaymentStatus { 2 | Declined = 'declined', 3 | Confirmed = 'confirmed', 4 | } -------------------------------------------------------------------------------- /payment-microservice/src/payment/payment.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { PaymentController } from './payment.controller'; 3 | 4 | describe('Payment Controller', () => { 5 | let controller: PaymentController; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | controllers: [PaymentController], 10 | }).compile(); 11 | 12 | controller = module.get(PaymentController); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(controller).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /payment-microservice/src/payment/payment.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Logger } from '@nestjs/common'; 2 | import { PaymentService } from './payment.service'; 3 | import { MessagePattern, EventPattern } from '@nestjs/microservices'; 4 | import { PayOrderDto } from './dto/pay-order.dto'; 5 | 6 | @Controller('api/payment') 7 | export class PaymentController { 8 | private logger = new Logger('PaymentController'); 9 | 10 | constructor(private readonly service: PaymentService) { } 11 | 12 | @MessagePattern('initiatePayment') 13 | async initiatePayment(order: PayOrderDto): Promise { 14 | return this.service.initiatePayment(order); 15 | } 16 | 17 | @EventPattern('paymentCanceled') 18 | async paymentCanceled(trxId: string) { 19 | this.service.cancelPayment(trxId); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /payment-microservice/src/payment/payment.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { PaymentService } from './payment.service'; 3 | import { PaymentController } from './payment.controller'; 4 | 5 | @Module({ 6 | providers: [PaymentService], 7 | controllers: [PaymentController] 8 | }) 9 | export class PaymentModule {} 10 | -------------------------------------------------------------------------------- /payment-microservice/src/payment/payment.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { PaymentService } from './payment.service'; 3 | 4 | describe('PaymentService', () => { 5 | let service: PaymentService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [PaymentService], 10 | }).compile(); 11 | 12 | service = module.get(PaymentService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /payment-microservice/src/payment/payment.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Logger } from '@nestjs/common'; 2 | import { PayOrderDto } from './dto/pay-order.dto'; 3 | import { PaymentDetailsDto } from './dto/payment-details.dto'; 4 | import { PaymentStatus } from './dto/payment-status.enum'; 5 | import { ClientOptions, Transport, ClientProxyFactory } from '@nestjs/microservices'; 6 | import { order_host } from '../config'; 7 | 8 | const orderClient = ClientProxyFactory.create({ 9 | transport: Transport.TCP, 10 | options: { 11 | host: order_host, 12 | port: 8876 13 | } 14 | }); 15 | let canceledPayments: string[] = [] 16 | @Injectable() 17 | export class PaymentService { 18 | private readonly logger = new Logger('Payment Service'); 19 | 20 | initiatePayment(order: PayOrderDto): string { 21 | var payment = new PaymentDetailsDto(order.id); 22 | 23 | if (order.status !== 'created') 24 | throw "Wrong Order Status"; 25 | 26 | if (Math.random() * 10 >= 4) 27 | payment.status = PaymentStatus.Confirmed; 28 | 29 | // assume this is a multi step process, so when it is done we emit an event 30 | setTimeout(async function () { 31 | if (canceledPayments.find(x => x == payment.transactionId)) { 32 | canceledPayments = canceledPayments.filter(x => x == payment.transactionId); 33 | return; 34 | } 35 | orderClient.emit('paymentProcessed', payment).subscribe(); 36 | }, Math.floor((Math.random() * 2) + 1) * 3000); 37 | 38 | return payment.transactionId; 39 | } 40 | 41 | cancelPayment(trxId: string) { 42 | canceledPayments.push(trxId); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /payment-microservice/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import * as request from 'supertest'; 3 | import { AppModule } from './../src/app.module'; 4 | 5 | describe('AppController (e2e)', () => { 6 | let app; 7 | 8 | beforeEach(async () => { 9 | const moduleFixture: TestingModule = await Test.createTestingModule({ 10 | imports: [AppModule], 11 | }).compile(); 12 | 13 | app = moduleFixture.createNestApplication(); 14 | await app.init(); 15 | }); 16 | 17 | it('/ (GET)', () => { 18 | return request(app.getHttpServer()) 19 | .get('/') 20 | .expect(200) 21 | .expect('Hello World!'); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /payment-microservice/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /payment-microservice/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /payment-microservice/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "target": "es2017", 9 | "sourceMap": true, 10 | "outDir": "./dist", 11 | "baseUrl": "./", 12 | "incremental": true 13 | }, 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /payment-microservice/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended"], 4 | "jsRules": { 5 | "no-unused-expression": true 6 | }, 7 | "rules": { 8 | "quotemark": [true, "single"], 9 | "member-access": [false], 10 | "ordered-imports": [false], 11 | "max-line-length": [true, 150], 12 | "member-ordering": [false], 13 | "interface-name": [false], 14 | "arrow-parens": false, 15 | "object-literal-sort-keys": false 16 | }, 17 | "rulesDirectory": [] 18 | } 19 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Order Management System 2 | 3 | Sample projects to demonstrate microservices, restful web api as well as ui. 4 | The system consists of 3 following projects: 5 | - Order Microservices 6 | - Payment Microservices 7 | - Order Web 8 | 9 | ## Order Microservices 10 | 11 | It is responsible for orders management. When an order is created, it triggers the payment microservice to proceed the payment. It also has the endpoints to list, cancel and check the order status. 12 | 13 | The project developed in NestJS, backed by Mongodb, handles both TCP and HTTP requests (mixed mode) and used web sockets to update clients on the status of orders. 14 | 15 | ### Technologies 16 | 17 | - Event-based and Message-based microservices on TCP:8876 18 | - REST api on port HTTP:8877 19 | - Swagger (http://localhost:8877/doc) 20 | - WebSocket 21 | - Mongodb 22 | - Docker 23 | 24 | ## Payment Microservices 25 | 26 | This service is responsible for handling requests made by orders app to verify payment transaction and confirm or decline it. When the service proceed the payment, it emits an event and let the order app to know the result of payment, so, the order service will update the status of that specific order. 27 | 28 | ### Technologies 29 | 30 | - Nestjs microservices on TCP:8875 31 | - Mongodb 32 | - Docker 33 | 34 | ## Order Web 35 | 36 | A Single Page Application developed using Angular which is the client-side interface for users to manage and to check the orders. 37 | A user can see the list of orders, check their statuses in real-time (websocket), and create or cancel an order. 38 | 39 | ### Technologies 40 | 41 | - Angular 42 | - socket-io 43 | - rxjs 44 | - docker 45 | 46 | ## Running the app 47 | 48 | Install Docker Desktop if you do not have it. Run docker package using docker-compose command 49 | 50 | ```bash 51 | # docker 52 | $ docker-compose up #--build 53 | ``` 54 | 55 | Then browse http://localhost:8085/orders 56 | 57 | Web Api can be checked through http://localhost:8877/api/orders and you can access api documentation through http://localhost:8877/doc 58 | 59 | Note: port 8875 and 8876 are not exposed by default in docker-compose.yml configuration. If you need them, you easily can change the config. 60 | 61 | ## License 62 | 63 | MIT licensed. 64 | --------------------------------------------------------------------------------