mirror of
https://github.com/Alvin-Zilverstand/challenge-11.git
synced 2026-03-07 05:47:23 +01:00
Add new car modification options to CarModifications component, including performance upgrades for engine, exhaust, suspension, and brakes. Update Customer model to include address and car year fields, and implement pre-save hook for updatedAt timestamp. Enhance customer routes with authentication middleware and improved error handling.
This commit is contained in:
@@ -3,21 +3,34 @@ const mongoose = require('mongoose');
|
||||
const customerSchema = new mongoose.Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true
|
||||
unique: true,
|
||||
trim: true,
|
||||
lowercase: true
|
||||
},
|
||||
phone: {
|
||||
type: String
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
carDetails: {
|
||||
make: String,
|
||||
model: String,
|
||||
year: Number,
|
||||
modifications: [String]
|
||||
address: {
|
||||
type: String,
|
||||
trim: true
|
||||
},
|
||||
carModel: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
carYear: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
@@ -29,4 +42,10 @@ const customerSchema = new mongoose.Schema({
|
||||
}
|
||||
});
|
||||
|
||||
// Update the updatedAt timestamp before saving
|
||||
customerSchema.pre('save', function(next) {
|
||||
this.updatedAt = Date.now();
|
||||
next();
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Customer', customerSchema);
|
||||
Reference in New Issue
Block a user