I'm working on a project to recreate this: https://issue-tracker.freecodecamp.rocks/
I'm working my way through the test and currently I've just written the Post endpoint to take in user data from the form. the data is to be saved and also displayed back to the user as an object. When I log the attributes to console I can see that the data I input is there however upon clicking the submit button it doesn't display the object.
Link to my code is here: https://replit.com/@Mmuneeb/boilerplate-project-issuetracker?s=app
Here is my api.js code:
"use strict";
const mongoose = require("mongoose");
const IssueModel = require("../models").Issue;
const ProjectModel = require("../models").Project;
const ObjectId = mongoose.Types.ObjectId;
module.exports = function (app) {
app.route('/api/issues/:project')
.get(function (req, res){
let project = req.params.project;
})
.post(function (req, res){
let project = req.params.project;
const issue_title = req.body.issue_title;
const issue_text = req.body.issue_text;
const created_by = req.body.created_by;
const assigned_to = req.body.assigned_to;
const status_text = req.body.status_text;
if (!issue_title || !issue_title || !created_by){
res.json({error: 'required field(s) missing'});
}
else {
const newIssue = new IssueModel({
issue_title: issue_title,
issue_text: issue_text,
created_by: created_by,
asigned_to: assigned_to,
status_text: status_text,
created_on: Date(),
updated_on: Date(),
open: true,
_id:_id,
});
res.json(newIssue);
}
})
.put(function (req, res){
let project = req.params.project;
})
.delete(function (req, res){
let project = req.params.project;
});
};
I've tried Googling and watching videos on YouTube but so far to no avail. Please any help as to what I'm doing wrong or missing would be appreciated.