Skip to content

Instantly share code, notes, and snippets.

@royib
Created October 16, 2019 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royib/5a8bb38bfc63c2a99aa0cf92f32f5173 to your computer and use it in GitHub Desktop.
Save royib/5a8bb38bfc63c2a99aa0cf92f32f5173 to your computer and use it in GitHub Desktop.
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