route.post('/',
validators.userSignup, // this middleware take care of validation
async (req, res, next) => {
// The actual responsability of the route layer.
const userDTO = req.body;
// Call to service layer.
// Abstraction on how to access the data layer and the business logic.
const { user, company } = await UserService.Signup(userDTO);
// Return a response to client.
return res.json({ user, company });
});
import UserModel from '../models/user';
import CompanyModel from '../models/company';
export default class UserService() {
async Signup(user) {
const userRecord = await UserModel.create(user);
const companyRecord = await CompanyModel.create(userRecord); // needs userRecord to have the database id
const salaryRecord = await SalaryModel.create(userRecord, companyRecord); // depends on user and company to be created
...whatever
await EmailService.startSignupSequence(userRecord)
...do more stuff
return { user: userRecord, company: companyRecord };
}
}
회원가입을 예로 들면, 사용자가 회원가입 양식 폼을 작성하고 회원가입 버튼을 누르면 회원가입이 진행된다. 이 과정에서 프로그래머는 아이디 중복 검사, 본인인증, 비밀번호 재검사를 수행한다.
먼저 프로그래머는 아이디 중복 검사를 위해 데이터베이스를 확인한다.(1)
중복된 아이디가 없으면 해당 아이디를 사용해도 된다고 사용자에게 표시해준다.(2)
(1)의 경우를 로직 or 모델 영역
(2)의 경우를 프레젠테이션 or 뷰 영역이라 한다.
즉, 비즈니스 로직이란 사용자가 요청한 데이터를 올바르게 도출하기 위해 데이터를 생성, 표시, 저장, 변경하는 코드 로직을 의미한다.
https://dev.to/santypk4/bulletproof-node-js-project-architecture-4epf#architecture