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/club.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
116 lines (99 sloc)
2.45 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 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); | |
} | |
}; |