Skip to content

Commit

Permalink
#33 and #34 - import statment was incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
cambateman committed Apr 14, 2021
1 parent c620aae commit 782a8bc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions models/athlete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mongoose = require('mongoose');
const Review = require('./review')
const Schema = mongoose.Schema;

const AthleteSchema = new Schema({
Expand Down
2 changes: 1 addition & 1 deletion models/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const reviewSchema = new Schema({
rating: Number
});

module.exports = mongoose.model("Review", reviewSchema);
module.exports = mongoose.model("Review", reviewSchema);
7 changes: 4 additions & 3 deletions routes/athletes.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
})
Expand All @@ -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');
}
Expand Down
12 changes: 6 additions & 6 deletions schemas.js
Original file line number Diff line number Diff line change
@@ -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()
});

Expand Down
16 changes: 16 additions & 0 deletions views/athletes/edit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,33 @@
OK!
</div>
</div>
<div class="mb-3">
<label class="form-label" for="image">Image URL:</label>
<input class="form-control" type="text" id="image" name="athlete[image]" value="<%= athlete.image %>" required>
<div class="valid-feedback">
OK!
</div>
</div>
<div class="mb-3">
<label class="form-label" for="sport">Sport:</label>
<input class="form-control" type="text" id="sport" name="athlete[sport]" value="<%= athlete.sport %>" required>
<div class="valid-feedback">
OK!
</div>
</div>
<div class="mb-3">
<label class="form-label" for="highSchool">High School:</label>
<input class="form-control" type="text" id="highSchool" name="athlete[highSchool]" value="<%= athlete.highSchool %>" required>
<div class="valid-feedback">
OK!
</div>
</div>
<div class="mb-3">
<label class="form-label" for="graduationYear">Graduation Year:</label>
<input class="form-control" type="text" id="graduationYear" name="athlete[graduationYear]" value="<%= athlete.graduationYear %>" required>
<div class="valid-feedback">
OK!
</div>
</div>
<div class="mb-3">
<button class="btn btn-info">Update Athlete</button>
Expand Down

0 comments on commit 782a8bc

Please sign in to comment.