An object that modifies the standard JSON stack based on a key value

I have a JSON object that represents calendar data. I am stuck on how or if a create method can be added to insert new data based on the key value.

Here is my diagram

year: { 
August: [
  {
    day: String,
    title: String,
    summary: String,
    description: String
  }
      ],
September: [
  {
    day: String,
    title: String,
    summary: String,
    description: String
  }
      ]
}
});

      

I would like to be able to create a new date based on Key value, Key is month.

{
    _id: "53d069cbea21639a67b5c64b"
    __v: 0
    -year: {
      -September: [
        -{
           day: "9 sep"
           title: "sep title"
           summary: "sep summ"
           _id: "53d069cbea21639a67b5c64c"
         }
       ],
    -August: [
        -{
           day: "9"
           title: "Dave Ramsey Financial Peace University"
           summary: "Financial Peace University (FPU) is a biblically-based, life-changing program that teaches people how to make wise decisions with money. You will be empowered with the practical skills and confidence needed..."
           _id: "53d069ccea21639a67b5c651"
         }
       -{
           day: "17"
           title: "Divorce & Beyond Seminar"
           summary: "If you are separated from your spouse, going through a divorce or are divorced, we encourage you to seek support. We understand the feelings of guilt, rejection, fear, confusion, isolation,..."
           _id: "53d069ccea21639a67b5c650"
        }

       ]
    }
    }

      

Here is my current creation method. Maybe everything is ok and my job should only be done on the angular side ...

  module.exports.create = function (req, res) {
  var cal = new Cal(req.body);      
        cal.save(function(err, result) {
            if (err)
                res.send(err);

            res.json(result);
        });
}

      

I am currently returning new objects in postman with new _id and empty values.

{
 __v: 0
 _id: "53ed6aa775e54f91b7362788"
 -year: {
     September: [ ]
     August: [ ]
    }
}

      

+3


source to share





All Articles