Skip to content
Permalink
7c6fca306a
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
52 lines (45 sloc) 1.07 KB
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);
}
};