Node Clean Architecture -Controllers and Presenters - StudentController.js
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