Created
October 16, 2019 11:28
-
-
Save royib/5a8bb38bfc63c2a99aa0cf92f32f5173 to your computer and use it in GitHub Desktop.
Node Clean Architecture -Controllers and Presenters - StudentController.js
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 AddStudent = require('../../application/use_cases/AddStudent'); | |
const GetAllStudents = require('../../application/use_cases/GetAllStudents'); | |
const GetStudent = require('../../application/use_cases/GetStudent'); | |
const AddEnrollment = require('../../application/use_cases/AddEnrollment'); | |
module.exports = (dependecies) => { | |
const { studentRepository } = dependecies.DatabaseService; | |
const { CrmServices } = dependecies; | |
const addNewStudent = (req, res, next) => { | |
// init use case | |
const AddStudentCommand = AddStudent(studentRepository, CrmServices); | |
// extract student properties | |
const { firstName, lastName, email } = req.body; | |
// here you can add data formatting logic | |
// call use case | |
AddStudentCommand.Execute(firstName, lastName, email).then((response) => { | |
// here you can add data formatting logic | |
res.json(response); | |
}, (err) => { | |
next(err); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment