Skip to content

Commit

Permalink
Tried to do a relationship and ended in failure
Browse files Browse the repository at this point in the history
  • Loading branch information
SSBinks committed Jan 18, 2017
1 parent 1223ec2 commit 70be74f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added models/.DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion models/assignment.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
var mongoose = require('mongoose');
var moment = require('moment');
var Schema = mongoose.Schema;

var AssignmentType = require('./assignmenttype');
var AssignmentSchema = new Schema ({
_assign: {type: Number, ref: 'AssignmentType'},
title: String,
course: Array,
dueDate: {type: Date, min: moment().subtract(1, 'day'), max: moment().add(2, 'years').calendar()},
progress: {type: Number, min: 0, max: 100},
complete: Boolean,
category: String
});

module.exports = mongoose.model('Assignment', AssignmentSchema);
25 changes: 25 additions & 0 deletions models/assignmenttype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Assignment = require('./assignment');



var AssignmentTypeSchema = new Schema({
_id: Number,
category: String,
fieldOne: {
name: {type: String},
length: {type: Number}
},
fieldTwo: {
name: {type: String},
length: {type: Number}
},
fieldThree: {
name: {type: String},
length: {type: Number}
},
assignment: [{type: Schema.Types.ObjectId, ref: 'Assignment'}]
});

module.exports = mongoose.model('AssignmentType', AssignmentTypeSchema);
44 changes: 42 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var moment = require('moment');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var Assignment = require('./models/assignment');
var AssignmentType = require('./models/assignmenttype');
var dotenv = require('dotenv').config();
var port = process.env.PORT || 8000;
mongoose.connect(process.env.MONGODB_LINK);
Expand All @@ -21,19 +22,31 @@ router.use(function(req, res, next) {

router.route('/assign')
.post( function(req, res){
var type = AssignmentType.find({category: 'reading'}, function(err, type){
if(err)return handleError(err);
console.log(type.category);
});
// res.send(err);
var assign = new Assignment();
// console.log('>>>>This is type object' + JSON.stringify(type))
assign.title = req.body.title;
assign.dueDate = moment(req.body.dueDate).format('L');
assign.progress = req.body.progress;
assign.complete = req.body.complete;
console.log('>>>>This is TYPE ' + req.body.category)
assign._assign = type.id;

assign.save(function(err){
if(err)
res.send(err);
res.json({ message: "Come on ladies let us get into formation"});
res.send('derp this broke' + err);
// console.log('>>>>This is type object ' + JSON.stringify(type))
});
type.assignment.push(assign.id);
type.save();
res.json({ message: "Come on ladies let us get into formation"});
});


router.route('/assign/:due_date')
.get(function(req, res) {
Assignment.find({dueDate: moment(req.params.due_date).format('L')}, function (err, assignment){
Expand All @@ -42,6 +55,33 @@ router.route('/assign/:due_date')
res.json(assignment);
});
});

router.route('/assign/category/:category')
.get(function(req, res) {
AssignmentType.find({category: req.params.category}, function(err, type){
if(err)
res.send(err);
res.json(type);
});
})
router.route('/assign/category')
.post( function(req, res){
var type = new AssignmentType();
console.log('>>>>This is type object ' + JSON.stringify(type))
type.category = req.body.category;
type.fieldOne.name = req.body.fname;
type.fieldOne.length = req.body.fnum;
type.fieldTwo.name = req.body.sname;
type.fieldTwo.length = req.body.snum;
type.fieldThree.name = req.body.tname;
type.fieldThree.length = req.body.tnum;
console.log('This is the body ' + JSON.stringify(req.body));
type.save(function(err){
if(err)
res.send('Yall dont want zero problems' + err);
// res.json({ message: "It worked?"});
});
});
app.use('/', router)
app.listen(port);
console.log('Got it up going high when they go low');

0 comments on commit 70be74f

Please sign in to comment.