This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createContainer, asValue, asFunction, asClass } = require('awilix') | |
function initDI ({serverSettings, dbSettings, database, models, services}, mediator) { | |
mediator.once('init', () => { | |
mediator.on('db.ready', (db) => { | |
const container = createContainer() | |
// loading dependecies in a single source of truth | |
container.register({ | |
database: asValue(db).singleton(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const {EventEmitter} = require('events') | |
const server = require('./server/server') | |
const repository = require('./repository/repository') | |
const di = require('./config') | |
const mediator = new EventEmitter() | |
console.log('--- Booking Service ---') | |
console.log('Connecting to movies repository...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const morgan = require('morgan') | |
const helmet = require('helmet') | |
const bodyparser = require('body-parser') | |
const cors = require('cors') | |
const spdy = require('spdy') | |
const _api = require('../api/booking') | |
const start = (container) => { | |
return new Promise((resolve, reject) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const repository = (container) => { | |
// we get the db object via the container | |
const {db} = container.resolve('database') | |
const makeBooking = (user, booking) => { | |
return new Promise((resolve, reject) => { | |
// payload to be insterted to the booking collection | |
const payload = { | |
city: booking.city, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createContainer, asValue } = require('awilix') | |
const stripe = require('stripe') | |
// here we include the stripeSettings | |
function initDI ({serverSettings, dbSettings, database, models, stripeSettings}, mediator) { | |
mediator.once('init', () => { | |
mediator.on('db.ready', (db) => { | |
const container = createContainer() | |
container.register({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const status = require('http-status') | |
module.exports = ({repo}, app) => { | |
app.post('/payment/makePurchase', (req, res, next) => { | |
const {validate} = req.container.cradle | |
validate(req.body.paymentOrder, 'payment') | |
.then(payment => { | |
return repo.registerPurchase(payment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this the function that makes the charge, when it's done | |
// returns the charge object returned by stripe | |
const makePurchase = (payment) => { | |
return new Promise((resolve, reject) => { | |
// here we retrieve or stripe dependecy | |
const {stripe} = container.cradle | |
// we create the charge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = ({repo}, app) => { | |
// this our endpoint where is going to validate our email, and the create and finally send it | |
app.post('/notifiaction/sendEmail', (req, res, next) => { | |
const {validate} = req.container.cradle | |
validate(req.body.payload, 'notification') | |
.then(payload => { | |
return repo.sendEmail(payload) | |
}) | |
.then(ok => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%RAML 1.0 | |
title: Booking Service | |
version: v1 | |
baseUri: /booking | |
/: | |
type: { POST: {item : Booking, item2 : User, item3: Ticket} } | |
/verify/{orderId}: | |
type: { GET: {item : Ticket} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const serverSettings = { | |
port: process.env.PORT || 8080, | |
ssl: require('./ssl') | |
} | |
const machine = process.env.DOCKER_HOST | |
const tls = process.env.DOCKER_TLS_VERIFY | |
const certDir = process.env.DOCKER_CERT_PATH |