Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions backend/src/controllers/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ export const addProduct = [
upload,
async (req: AuthenticatedRequest, res: Response) => {
try {
const { name, price, description } = req.body;
const { name, price, description, year, category, condition} = req.body;
if (!req.user) return res.status(404).json({ message: "User not found" });
const userId = req.user._id;
const userEmail = req.user.userEmail;
if (!name || !price || !userEmail) {
return res.status(400).json({ message: "Name, price, and userEmail are required." });
if (!name || !price || !userEmail || !year || !category || !condition) {
return res.status(400).json({ message: "Name, price, userEmail, year, category, condition, are required." });
}

const images: string[] = [];
Expand All @@ -101,6 +101,9 @@ export const addProduct = [
description,
userEmail,
images,
year,
category,
condition,
timeCreated: new Date(),
timeUpdated: new Date(),
});
Expand Down Expand Up @@ -189,6 +192,9 @@ export const updateProductById = [
name: req.body.name,
price: req.body.price,
description: req.body.description,
year: req.body.year,
category: req.body.category,
condition: req.body.condition,
images: finalImages,
timeUpdated: new Date(),
},
Expand Down
12 changes: 12 additions & 0 deletions backend/src/models/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ const productSchema = new Schema({
description: {
type: String,
},
year: {
type: Number,
required: true,
},
category: {
type: String,
required: true,
},
condition: {
type: String,
required: true,
},
timeCreated: {
type: Date,
required: true,
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/Product.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ interface Props {
productImages: string[];
productName: string;
productPrice: number;
productYear: number;
productCategory: string;
productCondition: string;
productLocation: string;
isSaved?: boolean;
onSaveToggle?: (productId: string, newSavedStatus: boolean) => void;
}
Expand Down
Loading