Skip to content
Permalink
3ff8db9eb5
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
116 lines (99 sloc) 2.45 KB
import Clubs from "../models/Clubs.js";
export const createClub = async (req, res,next) => {
describe("Post Endpoints", () => {
it("should create a new post", async () => {
const saveClub = await club.save();
res.status(200).json(saveClub);
});
expect(res.statusCode).toEqual(201);
expect(res.body).toHaveProperty("post");
});
} catch (err) {
next(err);
}
};
export const updateClub = async (req, res,next) => {
try {
const updatedClub = await Clubs.findByIdAndUpdate(
req.params.id,
{ $set: req.body },
{ new: true }
);
res.status(200).json(updatedClub);
} catch (err) {
next(err);
}
};
export const deleteClubs = async (req, res,next) => {
try {
await Clubs.findByIdAndDelete(req.params.id);
res.status(200).json("Club deleted");
} catch (err) {
next(err);
}
};
export const getClub = async (req, res,next) => {
try {
const getClub = await Clubs.findById(req.params.id);
res.status(200).json(getClub);
} catch (err) {
next(err);
}
};
export const getAllClub = async (req, res,next) => {
try {
const getAllClub = await Clubs.find();
res.status(200).json(getAllClub);
} catch (err) {
next(err);
}
};
export const countByclub = async (req, res,next) => {
try {
const getAllClub = await Clubs.find();
res.status(200).json(getAllClub);
} catch (err) {
next(err);
}
};
export const countByType = async (req, res,next) => {
const type = req.query.types.split(",");
try {
const list = await Promise.all(type.map(data =>
{
return Clubs.countDocuments({type:data})
}))
res.status(200).json(list);
} catch (err) {
next(err);
}
};
// Featured clubs
export const featuredClub = async (req, res, next) => {
try {
const getAllClub = await Clubs.find(res.query).limit(res.query);
res.status(200).json(getAllClub);
} catch (err) {
next(err);
}
};
export const searchQ = async (req, res, next) => {
try {
const getC = await Clubs.find(req.query)
res.status(200).json(getC);
} catch (err) {
next(err);
}
};
export const registerClub = async (req, res, next) => {
try {
const getC = await Clubs.findByIdAndUpdate(
req.params.id,
{ $set: req.body },
{ new: true }
);
res.status(200).json(getC);
} catch (err) {
next(err);
}
};