Guest User

Untitled

a guest
Nov 8th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const UserRepository = require('./UserRepository.js');
  2. const UserService = require('./UserService.js');
  3. const knex = require('knex');
  4. const express = require('express');
  5.  
  6. const app = express();
  7. const db = knex({
  8. client: 'mysql',
  9. connection: {
  10. host: 'localhost',
  11. user: 'sample',
  12. password: 'secret',
  13. database: 'sample',
  14. },
  15. });
  16.  
  17. const userRepository = new UserRepository(db);
  18. const userService = new UserService(userRepository);
  19.  
  20. app.get('/users/:user_id', (request, response) => {
  21. const userId = request.params.user_id;
  22.  
  23. userService.first(userId)
  24. .then((user) => {
  25. if (user) {
  26. return response.send(user);
  27. }
  28.  
  29. response.status(404).send({
  30. error: 'User not found!',
  31. });
  32. });
  33. });
  34.  
  35. app.listen(3000, () => console.log('Server running at port 3000'));
Add Comment
Please, Sign In to add comment