All files / src/controller userController.js

100% Statements 23/23
100% Branches 0/0
100% Functions 4/4
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 413x   3x   3x 1x 1x     3x 3x 3x 3x 1x   2x       3x 2x 2x       2x 1x   1x       3x 2x 2x 2x 1x   1x    
const userRepository = new (require("../repository/userRepository"))([]);
 
const UserService = require('../services/userService');
 
exports.getUser = async(req,res) => {
  const users = await userRepository.findMany()
  res.json(users)
}
 
exports.createUser = async(req,res) => {
  try {
    const user = new UserService(userRepository, req.body)
    const newUser = await user.save()
    res.json(newUser)
  } catch (error) {
    res.status(400).json({ message: error.message })
  }
}
 
exports.updateUser = async(req,res) => {
  try {
    const user = new UserService(userRepository, {
      id: req.params.id,
      ...req.body
    })
    const updatedUser = await user.update()
    return res.json(updatedUser)
  } catch (error) {
    return res.status(400).json({ message: error.message })
  }
}
 
exports.deleteUser = async(req,res) => {
  try {
    const user = new UserService(userRepository, { id: req.params.id })  
    await user.delete()
    res.json({ message: `User with id ${req.params.id} deleted!!`})
  } catch (error) {
    res.status(400).json({ message: error.message })
  }
}