Exercise tracker schema

Hello gyus
i am working on the Exercice tracker project and i am facing problems concerning the description and the duration fields, the problem is that when adding an exercise for a specific user, empty fields are allowed

i am affraid the problem is caused from my schema, here is mine, i used a nested schema ( a subdocument )
is it a good practice to split it, i mean by that creating a 2 seperates schema one for the user log and one for the exercise , this would not cause data redundancy ?

const mongoose = require("mongoose")
let ExerciseTracker;

// creating user log nested schema
const userLogSchema = new mongoose.Schema({
description:{type:String,required:true},
duration: {type:String,required:true},
date: {type:String}
});

// creating a user schema
const exerciseTrackerSchema = new mongoose.Schema({
  username: {type:String,required:true},
  count: {
     type: Number,
     default: 0
  },
   log: {
     type: [userLogSchema],
  }
});


// ceating a model
ExerciseTracker = mongoose.model("ExerciseTracker", exerciseTrackerSchema);

exports.ExerciseTrackerModel = ExerciseTracker;

Hey there,

I did the exact same thing as far as the embedded schema portion and therefore wound up with the same issue you are mentioning.

You can always add the required attribute in the input fields to prevent the form submission unless the fields are filled by changing

     <input id="desc" type="text" name="description" placeholder="description*">
     <input id="dur" type="text" name="duration" placeholder="duration* (mins.)">

To

     <input id="desc" type="text" name="description" placeholder="description*" required>
     <input id="dur" type="text" name="duration" placeholder="duration* (mins.)" required>

In the Index.html file.

That way you won’t be allowed to submit the information without filling the fields.

Hope that helps!

1 Like

Hi @laurentlabine
thanks for your reply
yeah you are right this should resolve the problem, but i tried to come up with a solution similar to the freecodecamp solution, you see, when you submit the form without filling for instance the description field you get a “Path description is required.” response.
so i split my schema into 2 schemas one for the user and one for the exercise and i ended up with a solution closer to the fcc solution.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.