Skip to content

WD_PT_RMT_012025_SANTIAGO_VILLA #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
edits
  • Loading branch information
villa-santiago committed May 31, 2025
commit 6c0a0d209395828de7779e5c67d690f85da0c821
11 changes: 11 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express");
const logger = require("morgan");
const mongoose = require("mongoose");
const Recipe = require("./models/Recipe.model");
const User = require("./models/User.model");

const app = express();

Expand Down Expand Up @@ -77,6 +78,16 @@ app.delete('/recipes/:id', (req, res) => {
}).catch(error => res.status(500).json(error))
});

// Iteration 8 - User
app.post('/users', (req, res) => {
const {email, firstName, lastName, password, image} = req.body;
User.create({email, firstName, lastName, password, image}).then(newUser => {
res.status(201).json(newUser);
}).catch(error => res.status(500).json(error));

});




// Start the server
Expand Down
32 changes: 32 additions & 0 deletions models/User.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const userSchema = new Schema({
email: {
type: String,
required: true,
unique: true
},
firstName: {
type: String,
required: true,
minlength: 2
},
lastName: {
type: String,
required: true,
minlength: 2
},
password: {
type: String,
required: true,
minlength: 8
},
image: {
type: String,
default: "https://xsgames.co/randomusers/assets/avatars/pixel/44.jpg"
}
});

const User = mongoose.model("User", userSchema);
module.exports = User;