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: Cinema Catalog Service | |
version: v1 | |
baseUri: / | |
uses: | |
object: types.raml | |
stack: ../movies-service/api.raml | |
types: | |
Cinemas: object.Cinema [] |
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
// more code above | |
const getCinemasByCity = (cityId) => { | |
return new Promise((resolve, reject) => { | |
const cinemas = [] | |
const query = {city_id: cityId} | |
const projection = {_id: 1, name: 1} | |
// example of making a find query to mongoDB, | |
// passign a query and projection objects. | |
const cursor = db.collection('cinemas').find(query, projection) |
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 = (app, options) => { | |
const {repo} = options | |
app.get('/cinemas', (req, res, next) => { | |
repo.getCinemasByCity(req.query.cityId) | |
.then(cinemas => { | |
res.status(status.OK).json(cinemas) |
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
/* eslint-env mocha */ | |
const request = require('supertest') | |
const server = require('../server/server') | |
process.env.NODE = 'test' | |
describe('Movies API', () => { | |
let app = null | |
const testCinemasCity = [{ | |
'_id': '588ac3a02d029a6d15d0b5c4', | |
'name': 'Plaza Morelia' |
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
// more code | |
mediator.on('db.ready', (db) => { | |
let rep | |
// here we are making DI to the repository | |
// we are injecting the database object and the ObjectID object | |
repository.connect({ | |
db, | |
ObjectID: config.ObjectID | |
}) |
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: / | |
types: | |
Booking: | |
properties: | |
city: string | |
cinema: string |
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 bookingSchema = (joi) => ({ | |
bookingSchema: joi.object().keys({ | |
city: joi.string(), | |
schedule: joi.date().min('now'), | |
movie: joi.string(), | |
cinemaRoom: joi.number(), | |
seats: joi.array().items(joi.string()).single(), | |
totalAmount: joi.number() | |
}) | |
}) |
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 joi = require('joi') | |
const user = require('./user.model')(joi) | |
const booking = require('./booking.model')(joi) | |
const ticket = require('./ticket.model')(joi) | |
const schemas = Object.create({user, booking, ticket}) | |
const schemaValidator = (object, type) => { | |
return new Promise((resolve, reject) => { | |
if (!object) { |
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
/* eslint-env mocha */ | |
const test = require('assert') | |
const {validate} = require('./') | |
console.log(Object.getPrototypeOf(validate)) | |
describe('Schemas Validation', () => { | |
it('can validate a booking object', (done) => { | |
const now = new Date() | |
now.setDate(now.getDate() + 1) |
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('/booking', (req, res, next) => { | |
// we grab the dependencies need it for this route | |
const validate = req.container.resolve('validate') | |
const paymentService = req.container.resolve('paymentService') | |
const notificationService = req.container.resolve('notificationService') |