Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

Move all logic into controllers #120

Merged
merged 28 commits into from
Oct 20, 2017
Merged

Move all logic into controllers #120

merged 28 commits into from
Oct 20, 2017

Conversation

goto-bus-stop
Copy link
Member

These patches move all request handling logic to controller functions. Route files now only map routes to controller functions. This is more similar to what Sooyou had set up before. When I pulled some "business logic" (like playlist handling) into core I dropped the controller files and called the core APIs straight from route files. This patch instead takes a few clues from https://github.com/KunalKapadia/express-mongoose-es6-rest-api and puts all logic into controllers, even if it's just a single function call. This makes it much clearer where the work happens (always in the controllers/ directory).


The second patch also removes most by-hand validation from controllers and instead uses the validation library Joi. Nice thing about Joi is that validators are written in the shape of the data you expect, so instead of doing

Array.isArray(body.items) && (typeof body.after === 'string' || body.after === -1)

we can do

joi.object({
  items: joi.array().required(),
  after: [
    objectID, // Insert after ID
    joi.number().valid(-1), // Prepend
  ],
})

which makes it more obvious what the incoming data actually looks like. (Also, the former doesn't check that the after property is actually a valid MongoDB ObjectID, whilst the latter does, so it's more robust as well!)

@goto-bus-stop goto-bus-stop force-pushed the feature/controllers branch 3 times, most recently from 1d09f7d to e7e447f Compare September 7, 2017 12:21
@goto-bus-stop goto-bus-stop mentioned this pull request Sep 8, 2017
@goto-bus-stop
Copy link
Member Author

Sockets aren't converting from GuestConnection to AuthedConnection correctly yet, I think.

@goto-bus-stop
Copy link
Member Author

this needs some more work but I'll merge now because this is going to be the next version anyway and i don't want to rebase it whenever I do something else

@goto-bus-stop goto-bus-stop merged commit 3452c9b into master Oct 20, 2017
@goto-bus-stop goto-bus-stop deleted the feature/controllers branch October 20, 2017 11:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant