Skip to content

Commit

Permalink
Update SessionRepository to use new db
Browse files Browse the repository at this point in the history
Update DBFactory to create a single db
Update config to the single db type
Create Session model
Create Session Mapper
Update Session Router to class
Create GenericRouter

Create session tests
Separeted Auth stub to its own class
Commented prints on index.js
Created npm script to lint-fix
  • Loading branch information
Eduardo Maia committed Jun 27, 2019
1 parent 227e551 commit da916b1
Show file tree
Hide file tree
Showing 27 changed files with 381 additions and 478 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ We need to send the following information in a `JSON` format
"timestamp": "<timestamp you want your session to happen>"
}
```


#### **Close Session**
To close a `Session`, we do a `POST` to the following:
#### **Delete Session**
To delete a `Session`, we do a `DELETE` to the following:
```
/sessions/close/:id
/sessions/:session_id
```
Where `id` is the `id` of the `session` which you want to close.

#### **Add Note**
To add a new `Note` to a `Session`, we do a `POST` to the following:
Expand Down
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
port: 3000,
db: 'firestore2'
db: 'firestore'
}
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ const RepositoriesProvider = require('./src/repositories')
const envPath = './src/environment/'
const dbFactory = require(envPath + 'DBFactory')
const db = dbFactory.getDB(config.db)
const db2 = dbFactory.getDB('firestore')

const repositories = new RepositoriesProvider(db, db2)
const repositories = new RepositoriesProvider(db)
const notesRepository = repositories.provideNotesRepository()
const sessionsRepository = repositories.provideSessionsRepository()

Expand All @@ -35,8 +34,9 @@ const routerProvider = new RouterProvider(app, controllersProvider, auth)
const Server = require('./server')
const server = new Server(app, config, routerProvider)

console.log(config)
console.log(server)
// todo: if production env log this.
// console.log(config)
// console.log(server)

server.start()

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"start": "./node_modules/eslint/bin/eslint.js . && node index.js",
"lint": "./node_modules/eslint/bin/eslint.js .",
"lint-fix": "./node_modules/eslint/bin/eslint.js . --fix",
"test": "mocha --recursive --exit --timeout 30000",
"test-coverage": "nyc --all true npm run test",
"test-coveralls": "nyc report --reporter=text-lcov | coveralls"
Expand Down
13 changes: 7 additions & 6 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const NotesController = require('./notesController')
const NoteController = require('./noteController')
const SessionController = require('./sessionController')

class ControllersProvider {
constructor (notesRepository, sessionsRepository) {
this.notesRepository = notesRepository
this.sessionsRepository = sessionsRepository
constructor (noteRepository, sessionRepository) {
this.noteRepository = noteRepository
this.sessionRepository = sessionRepository
}

provideNotesController () {
return new NotesController(this.notesRepository)
return new NoteController(this.noteRepository)
}

getSessionsController () {
return require('./sessionsController')(this.sessionsRepository)
return new SessionController(this.sessionRepository)
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/controllers/noteController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class NoteController {
constructor (noteRepository) {
this.noteRepository = noteRepository
}

async getNotesFromSession (note) {
return this.noteRepository.getNotes(note.getNote())
}

async addNewNoteToSession (note) {
return this.noteRepository.addNewNoteToSession(note.getNote())
}

async deleteNote (note) {
return this.noteRepository.deleteNote(note.id)
}

async editNote (note) {
return this.noteRepository.editNote(note.id, note.getNote())
}
}

module.exports = NoteController
23 changes: 0 additions & 23 deletions src/controllers/notesController.js

This file was deleted.

52 changes: 52 additions & 0 deletions src/controllers/sessionController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const Joi = require('joi')

class SessionController {
constructor (sessionRepository) {
this.sessionRepository = sessionRepository
}

async getAllSessions (meeting) {
return this.sessionRepository.getAllSessions(meeting)
}

async getSession (session) {
this.validateSessionId(session)
return this.sessionRepository.getSession(session.getIdObject())
}

async createSession (session) {
this.validateSession(session)
return this.sessionRepository.createSession(session.getSession())
}

async deleteSession (session) {
this.validateSessionId(session)
return this.sessionRepository.deleteSession(session.id)
}

async editSession (session) {
this.validateFullSession(session)
return this.sessionRepository.editSession(session.id, session.getSession())
}

validateSessionId (session) {
Joi.validate(session, Joi.object({
id: Joi.string().required()
}))
}

validateFullSession (session) {
Joi.validate(session, Joi.object({
id: Joi.string().required(),
topics: Joi.array().items(Joi.string()).required(),
timestamp: Joi.date().timestamp().required()
}))
}

validateSession (session) {
Joi.validate(session, Joi.object({
topics: Joi.array().items(Joi.string()).required()
}))
}
}
module.exports = SessionController
92 changes: 0 additions & 92 deletions src/controllers/sessionsController.js

This file was deleted.

7 changes: 2 additions & 5 deletions src/environment/DBFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ module.exports = {
getDB: function (dbType) {
var db
switch (dbType) {
case 'firestore2':
const FirestoreDB = require('./FirestoreDB')
db = new FirestoreDB()
break
case 'firestore':
default:
db = require('./FirestoreDB/firestoreOld')
const FirestoreDB = require('./FirestoreDB')
db = new FirestoreDB()
break
}
return db
Expand Down
Loading

0 comments on commit da916b1

Please sign in to comment.