Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sports_Club/controllers/user.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (45 sloc)
1.07 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Users from "../models/User.js"; | |
export const updateUser = async (req, res) => { | |
try { | |
const updatedUser = await Users.findByIdAndUpdate( | |
req.params.id, | |
{ $set: req.body }, | |
{ new: true } | |
); | |
res.status(200).json(updatedUser); | |
} catch (err) { | |
next(err); | |
} | |
}; | |
export const deleteUser = async (req, res) => { | |
try { | |
await Users.findByIdAndDelete(req.params.id); | |
res.status(200).json("User deleted"); | |
} catch (err) { | |
next(err); | |
} | |
}; | |
export const getUser = async (req, res) => { | |
try { | |
const getUser = await Users.findById(req.params.id); | |
res.status(200).json(getUser); | |
} catch (err) { | |
next(err); | |
} | |
}; | |
export const getAllUser = async (req, res) => { | |
try { | |
const getAllUser = await Users.find(); | |
res.status(200).json(getAllUser); | |
} catch (err) { | |
next(err); | |
} | |
}; | |
export const countAllUser = async (req, res,next) => { | |
try { | |
const count = await Users.countDocuments() | |
res.status(200).json(count); | |
} catch (err) { | |
next(err); | |
} | |
}; |