Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor users route to be split into controller/service/repository layers #105

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add/remove comments
  • Loading branch information
jazhen committed Sep 1, 2022
commit 3355606e873725226c94dc047b5f7892a531759c
2 changes: 0 additions & 2 deletions server/routes/users/users-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function buildUsersController({ usersService }) {
};

function buildGetRequestUserDTO({ query: { email } }) {
// maybe do these existence validations in a middleware
if (!email) {
throw new AppError(400, 'Missing required parameter: email.');
}
Expand All @@ -57,7 +56,6 @@ export function buildUsersController({ usersService }) {
}

function buildPostRequestUserDTO({ body: { email, name, nickname } }) {
// maybe do these existence validations in a middleware
if (!email) {
throw new AppError(400, 'Missing required parameter: email.');
}
Expand Down
8 changes: 6 additions & 2 deletions server/routes/users/users-service.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
export const buildUsersService = ({ usersRepository }) => {
return {
async getUser({ userDTO: { email } }) {
// validate business logic of email
// validate business logic here
// check if userDTO.email is an email
// if not, throw error?
return usersRepository.findUser({ email });
},
async createUser({ userDTO }) {
// validate business logic of userDTO fields
// validate business logic here
// add check that the fields in userDTO are valid to add to the database
// this will help prevent irregular data from sneaking into our database
return usersRepository.createUser({ user: userDTO });
},
};
Expand Down