Forked from stephepush/adminController.postAddVehicle.js
Last active
September 13, 2021 02:39
-
-
Save nickserv/20448820cd3a6f58666d4ad7ca60f879 to your computer and use it in GitHub Desktop.
Excluding model/class properties in express
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
exports.postAddVehicle = ({ body }, res, next) => { | |
const car = new Car(body) | |
console.log(car) | |
return car | |
.save() | |
.then(() => { | |
res.redirect('/'); | |
}) | |
.catch(err => console.log(err)) | |
} |
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
module.exports = class Car { | |
constructor(data) { | |
this.data = data; | |
} | |
save() { | |
const { car_photo_url, car_price, ...body } = this.data; | |
return fetch(endpoint, { method: "post", body: JSON.stringify(body) }); | |
} | |
} |
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
Car { | |
id: null, | |
model_year: '2016', | |
make: 'Chevrolet', | |
model: 'Corvette', | |
miles: 'violet', | |
color: '56000', | |
transmission: 'automatic', | |
layout: 'MR', | |
engine_config: 'V8', | |
car_photo_url: undefined, | |
car_price: undefined | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment