fixed cars_make

This commit is contained in:
Jonathan Jara 2025-05-03 18:49:04 -07:00
parent 9d3f2c7352
commit db9af4a33c

View File

@ -2,15 +2,23 @@ const CarMake = require('../models/car_makes.js');
// Get all makes // Get all makes
// This function retrieves all car makes from the database and sends them as a response. // This function retrieves all car makes from the database and sends them as a response.
exports.getMakes = async (req, res) =>{ exports.getMakes = async (req, res) => {
try { try {
const makes = await CarMake.find(); const docs = await CarMake.find()
res.status(200).json(makes); .select("make_name")
.lean();
const makes = docs.map((d) => ({
value: d._id.toString(),
label: d.make_name,
}));
return res.status(200).json(makes);
} catch (error) { } catch (error) {
res.status(500).json({ console.error("Server error retrieving makes:", error);
message: 'Server error retrieving makes', return res.status(500).json({
error: error.message message: "Server error retrieving makes",
error: error.message,
}); });
} }
}; };