Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion server/src/controllers/perkController.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ export async function createPerk(req, res, next) {
// TODO
// Update an existing perk by ID and validate only the fields that are being updated
export async function updatePerk(req, res, next) {

try {
const { value, error } = perkSchema.validate(req.body);
if (error) return res.status(400).json({ message: error.message });
const doc = await Perk.findByIdAndUpdate(req.params.id, { ...value });
if (!doc) return res.status(404).json({ message: 'Perk not found' });
res.json({ perk: doc });
} catch (err) { next(err); }
}


Expand Down