|
| 1 | +"use strict"; |
| 2 | +var _ = require("lodash"); |
| 3 | +var errorHandler_1 = require("../../api/responses/errorHandler"); |
| 4 | +var successHandler_1 = require("../../api/responses/successHandler"); |
| 5 | +var dbErrorHandler_1 = require("../../config/dbErrorHandler"); |
| 6 | +var service_1 = require("./service"); |
| 7 | +var UserController = (function () { |
| 8 | + function UserController() { |
| 9 | + this.UserService = new service_1.User(); |
| 10 | + } |
| 11 | + UserController.prototype.getAll = function (req, res) { |
| 12 | + this.UserService.getAll() |
| 13 | + .then(_.partial(successHandler_1.onSuccess, res)) |
| 14 | + .catch(_.partial(errorHandler_1.onError, res, 'Find all users failed')); |
| 15 | + }; |
| 16 | + UserController.prototype.createUser = function (req, res) { |
| 17 | + this.UserService.create(req.body) |
| 18 | + .then(_.partial(successHandler_1.onSuccess, res)) |
| 19 | + .catch(_.partial(dbErrorHandler_1.dbErrorHandler, res)) |
| 20 | + .catch(_.partial(errorHandler_1.onError, res, "Could not create user")); |
| 21 | + }; |
| 22 | + UserController.prototype.getById = function (req, res) { |
| 23 | + var userId = parseInt(req.params.id); |
| 24 | + this.UserService.getById(userId) |
| 25 | + .then(_.partial(successHandler_1.onSuccess, res)) |
| 26 | + .catch(_.partial(errorHandler_1.onError, res, 'Not found')); |
| 27 | + }; |
| 28 | + UserController.prototype.updateUser = function (req, res) { |
| 29 | + var userId = parseInt(req.params.id); |
| 30 | + var props = req.body; |
| 31 | + this.UserService.update(userId, props) |
| 32 | + .then(_.partial(successHandler_1.onSuccess, res)) |
| 33 | + .catch(_.partial(errorHandler_1.onError, res, 'Update User failed')); |
| 34 | + }; |
| 35 | + UserController.prototype.deleteUser = function (req, res) { |
| 36 | + var userId = req.params.id; |
| 37 | + this.UserService.delete(userId) |
| 38 | + .then(_.partial(successHandler_1.onSuccess, res)) |
| 39 | + .catch(_.partial(errorHandler_1.onError, res, 'An error ocurred to delete an User')); |
| 40 | + }; |
| 41 | + return UserController; |
| 42 | +}()); |
| 43 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 44 | +exports.default = UserController; |
0 commit comments