-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #71: Create logic to handle meetings creation
- Loading branch information
João Victor Pessoa
committed
Jan 31, 2020
1 parent
227e551
commit 5867a75
Showing
20 changed files
with
348 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ src/environment/FirestoreDB/keys/serviceAccountKey.json | |
.nyc_output | ||
|
||
.DS_Store | ||
|
||
.idea |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const SchemaProvider = require('../schemas') | ||
const MeetingsMapper = require('../mapper/MeetingsMapper') | ||
|
||
class MeetingsController { | ||
constructor (service) { | ||
this.service = service | ||
this.schema = new SchemaProvider().provideMeetingsSchema() | ||
} | ||
|
||
async insertMeeting (req, res) { | ||
const rawMeeting = validateBody(req, res, this.schema.getInsertMeetingSchema()) | ||
const meeting = new MeetingsMapper().mapJsonToDomain(rawMeeting) | ||
|
||
const result = await this.service.insertMeeting(meeting) | ||
if (result.message) { | ||
res.status(500) | ||
res.send({ error: result.message }) | ||
return | ||
} | ||
res.send(result) | ||
} | ||
|
||
async getMeeting (req, res) { | ||
const meetings = await this.service.getMeeting(req.body) | ||
|
||
if (meetings.message) { | ||
res.status(500) | ||
res.send({ error: meetings.message }) | ||
} | ||
res.send(meetings) | ||
} | ||
|
||
async updateMeeting (req, res) { | ||
const meeting = validateBody(req, res, this.schema.getUpdateMeetingSchema()) | ||
const result = await this.service.updateMeeting(meeting) | ||
res.send(result) | ||
} | ||
|
||
async deleteMeeting (req, res) { | ||
const meetingId = req.params.meeting_id | ||
const result = await this.service.deleteMeeting(meetingId) | ||
res.send(result) | ||
} | ||
} | ||
|
||
function validateBody (req, res, validator) { | ||
const { error, value } = validator.validate(req.body) | ||
|
||
if (error) { | ||
res.status(400) | ||
res.send(error) | ||
return | ||
} | ||
return value | ||
} | ||
|
||
module.exports = MeetingsController |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const router = require('./../router') | ||
const controllers = require('../controllers') | ||
const schemas = require('../schemas') | ||
|
||
module.exports = { | ||
router: router, | ||
controllers: controllers | ||
controllers: controllers, | ||
schemas: schemas | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const Meeting = require('../model/Meeting') | ||
const Session = require('../model/Session') | ||
|
||
class MeetingsMapper { | ||
mapJsonToDomain (obj) { | ||
const meeting = new Meeting(obj.id, obj.team_id, obj.name, obj.date, obj.to, obj.location, []) | ||
|
||
if (obj.sessions !== undefined) { | ||
obj.sessions.map(session => { | ||
meeting.sessions.push(new Session(session.id, session.meeting_id, session.name, session.description, session.topics)) | ||
}) | ||
} | ||
return meeting | ||
} | ||
} | ||
|
||
module.exports = MeetingsMapper |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Meeting { | ||
constructor (id, teamId, name, date, to, location, sessions) { | ||
this.id = id | ||
this.teamId = teamId | ||
this.name = name | ||
this.date = date | ||
this.to = to | ||
this.location = location | ||
this.sessions = sessions | ||
} | ||
|
||
getMeeting () { | ||
return { | ||
team_id: this.teamId, | ||
name: this.name, | ||
date: this.date, | ||
to: this.to, | ||
location: this.location | ||
} | ||
} | ||
} | ||
|
||
module.exports = Meeting |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Session { | ||
constructor (id, meetingId, name, description, topics) { | ||
this.id = id | ||
this.meetingId = meetingId | ||
this.name = name | ||
this.description = description | ||
this.topics = topics | ||
} | ||
|
||
getSession () { | ||
return { | ||
meeting_id: this.meetingId, | ||
name: this.name, | ||
description: this.description, | ||
topics: this.topics | ||
} | ||
} | ||
} | ||
|
||
module.exports = Session |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class MeetingsRepository { | ||
constructor (db) { | ||
this.db = db | ||
} | ||
|
||
async insertMeeting (meeting) { | ||
return this.db.executeInsert('/meetings', meeting) | ||
} | ||
|
||
async getMeeting (filter) { | ||
return this.db.executeGetDB('/meetings', filter) | ||
} | ||
|
||
async updateMeeting (meetingId, meeting) { | ||
return this.db.executeUpdateDB('/meetings', meetingId, meeting) | ||
} | ||
|
||
async deleteMeeting (sessionId) { | ||
return this.db.executeDelete('/meetings', sessionId) | ||
} | ||
} | ||
|
||
module.exports = MeetingsRepository |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const express = require('express') | ||
|
||
class MeetingsRouter { | ||
constructor (meetingsController) { | ||
this.meetingsController = meetingsController | ||
this.app = express() | ||
} | ||
getRoutes () { | ||
this.app.post('/', async (req, res) => { | ||
await this.meetingsController.insertMeeting(req, res) | ||
}) | ||
|
||
this.app.get('/', async (req, res) => { | ||
await (this.meetingsController.getMeeting(req, res)) | ||
}) | ||
|
||
this.app.post('/edit', async (req, res) => { | ||
await (this.meetingsController.updateMeeting(req, res)) | ||
}) | ||
|
||
this.app.delete('/:meeting_id', async (req, res) => { | ||
await (this.meetingsController.deleteMeeting(req, res)) | ||
}) | ||
|
||
return this.app | ||
} | ||
} | ||
|
||
module.exports = MeetingsRouter |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const MeetingsSchema = require('./meetingsSchema') | ||
|
||
class SchemasProvider { | ||
provideMeetingsSchema () { | ||
return new MeetingsSchema() | ||
} | ||
} | ||
|
||
module.exports = SchemasProvider |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const Joi = require('joi') | ||
const sessionSchemas = require('./sessionsSchema') | ||
|
||
class MeetingsSchema { | ||
getInsertMeetingSchema () { | ||
return Joi.object().keys({ | ||
id: Joi.string(), | ||
team_id: Joi.string().required(), | ||
name: Joi.string().required(), | ||
date: Joi.date().timestamp().required(), | ||
to: Joi.date().timestamp().required(), | ||
location: Joi.string(), | ||
sessions: Joi.array().items(sessionSchemas) | ||
}) | ||
} | ||
|
||
getMeetingSchema () { | ||
return Joi.object().keys({ | ||
id: Joi.string(), | ||
team_id: Joi.string(), | ||
name: Joi.string(), | ||
date: Joi.date(), | ||
to: Joi.date(), | ||
location: Joi.string() | ||
}) | ||
} | ||
getUpdateMeetingSchema () { | ||
return Joi.object().keys({ | ||
id: Joi.string().required(), | ||
team_id: Joi.string(), | ||
name: Joi.string(), | ||
date: Joi.date().timestamp(), | ||
to: Joi.date().timestamp(), | ||
location: Joi.string() | ||
}) | ||
} | ||
} | ||
|
||
module.exports = MeetingsSchema |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const Joi = require('joi') | ||
|
||
module.exports = Joi.object().keys({ | ||
id: Joi.string(), | ||
meeting_id: Joi.string(), | ||
name: Joi.string(), | ||
description: Joi.string(), | ||
topics: Joi.array().items(Joi.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const Joi = require('joi') | ||
|
||
module.exports = Joi.object().keys({ | ||
administrator: Joi.string().email().required(), | ||
members: Joi.array().items(Joi.string().email().required()).required() | ||
}) |
Oops, something went wrong.