From 782a8bcb7c5c4fa3856ff971a820112e3bf4d323 Mon Sep 17 00:00:00 2001 From: cambateman Date: Wed, 14 Apr 2021 16:32:04 -0700 Subject: [PATCH] #33 and #34 - import statment was incorrect --- models/athlete.js | 1 + models/review.js | 2 +- routes/athletes.js | 7 ++++--- schemas.js | 12 ++++++------ views/athletes/edit.ejs | 16 ++++++++++++++++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/models/athlete.js b/models/athlete.js index d0e8f7d..8a02096 100644 --- a/models/athlete.js +++ b/models/athlete.js @@ -1,4 +1,5 @@ const mongoose = require('mongoose'); +const Review = require('./review') const Schema = mongoose.Schema; const AthleteSchema = new Schema({ diff --git a/models/review.js b/models/review.js index 8387b91..9041e76 100644 --- a/models/review.js +++ b/models/review.js @@ -6,4 +6,4 @@ const reviewSchema = new Schema({ rating: Number }); -module.exports = mongoose.model("Review", reviewSchema); +module.exports = mongoose.model("Review", reviewSchema); \ No newline at end of file diff --git a/routes/athletes.js b/routes/athletes.js index 7c5455b..11d478b 100644 --- a/routes/athletes.js +++ b/routes/athletes.js @@ -1,7 +1,7 @@ const express = require('express'); const router = express.Router(); const catchAsync = require('../utils/catchAsync'); -const athleteSchema = require('../schemas.js'); +const { athleteSchema } = require('../schemas.js'); const { isLoggedIn } = require('../middleware'); const ExpressError = require('../utils/ExpressError'); @@ -16,12 +16,13 @@ const validateAthlete = (req, res, next) => { next(); } } - +//get all atheletes - for index page WORKS router.get('/', catchAsync(async (req, res) => { const athletes = await Athlete.find({}); res.render('athletes/index', { athletes }) })); +//get 'new' page to create - WORKS router.get('/new', isLoggedIn, (req, res) => { res.render('athletes/new'); }) @@ -41,7 +42,7 @@ router.get('/:id', catchAsync(async (req, res,) => { router.get('/:id/edit', isLoggedIn, catchAsync(async (req, res) => { const athlete = await Athlete.findById(req.params.id) - if (!athletes) { + if (!athlete) { req.flash('error', 'Cannot find that athlete!'); return res.redirect('/athletes'); } diff --git a/schemas.js b/schemas.js index c55ea28..24199f2 100644 --- a/schemas.js +++ b/schemas.js @@ -1,13 +1,13 @@ const Joi = require('joi'); const { number } = require('joi'); -module.exports.campgroundSchema = Joi.object({ - campground: Joi.object({ - title: Joi.string().required(), - price: Joi.number().required().min(0), +module.exports.athleteSchema = Joi.object({ + athlete: Joi.object({ + name: Joi.string().required(), image: Joi.string().required(), - location: Joi.string().required(), - description: Joi.string().required() + sport: Joi.string().required(), + graduationYear: Joi.number().required().min(0), + highSchool: Joi.string().required() }).required() }); diff --git a/views/athletes/edit.ejs b/views/athletes/edit.ejs index 7971941..6bbaf0b 100644 --- a/views/athletes/edit.ejs +++ b/views/athletes/edit.ejs @@ -10,17 +10,33 @@ OK! +
+ + +
+ OK! +
+
+
+ OK! +
+
+ OK! +
+
+ OK! +