-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
725310e
commit 6ffe4b1
Showing
35 changed files
with
597 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
const express = require('express') | ||
var router = express.Router() | ||
var ObjectID = require('mongoose').Types.ObjectId | ||
var Planning = require('../model/Planning.js') | ||
|
||
|
||
|
||
|
||
const controller = {} | ||
|
||
controller.add = async (req, res) => { | ||
|
||
var str = req.body.date; | ||
var split= str.split("-"); | ||
var entryDate= new Date(split[0],split[1]-1,split[2]); | ||
|
||
console.log(req.body.tratament) | ||
if(req.body.tratament=="irrigation"){ | ||
entryDate.setDate(entryDate.getDate()+5); | ||
var mDate = entryDate.getMonth(); | ||
var yDate = entryDate.getUTCFullYear(); | ||
var dDate = entryDate.getDate(); | ||
|
||
var mMonth = parseInt(mDate) + 1; | ||
|
||
} | ||
|
||
|
||
if(req.body.tratament=="pruning"){ | ||
entryDate.setDate(entryDate.getDate()+3); | ||
var mDate = entryDate.getMonth(); | ||
var yDate = entryDate.getUTCFullYear(); | ||
var dDate = entryDate.getDate(); | ||
|
||
var mMonth = parseInt(mDate) + 1; | ||
|
||
} | ||
|
||
if(req.body.tratament=="cloning"){ | ||
entryDate.setDate(entryDate.getDate()+4); | ||
var mDate = entryDate.getMonth(); | ||
var yDate = entryDate.getUTCFullYear(); | ||
var dDate = entryDate.getDate(); | ||
|
||
var mMonth = parseInt(mDate) + 1; | ||
|
||
} | ||
|
||
if(req.body.tratament=="fumigation"){ | ||
entryDate.setDate(entryDate.getDate()+6); | ||
var mDate = entryDate.getMonth(); | ||
var yDate = entryDate.getUTCFullYear(); | ||
var dDate = entryDate.getDate(); | ||
|
||
var mMonth = parseInt(mDate) + 1; | ||
|
||
} | ||
|
||
|
||
|
||
var date= yDate + "-" + mMonth + "-" + dDate; | ||
|
||
|
||
|
||
var newRecord = new Planning({ | ||
date: date, | ||
tratament: req.body.tratament, | ||
plant: req.body.plant | ||
}) | ||
|
||
newRecord.save((err, docs) => { | ||
if (!err) res.send(docs) | ||
else console.log('Error while creating new record : ' + JSON.stringify(err, undefined, 2)) | ||
}) | ||
} | ||
|
||
controller.list = async ( req, res) => { | ||
const planning = await Planning.find({"plant": req.params.id}) | ||
.then(planning =>{ | ||
res.send(planning) | ||
}) | ||
.catch(err => { | ||
res.status(500).send({ | ||
message: | ||
err.message || "Some error occurred while retrieving tutorials." | ||
}); | ||
}); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
controller.findOne = async (req , res) =>{ | ||
Planning.findById(req.params.id) | ||
.then((planning) => { | ||
if (!planning) { | ||
return res.status(404).send({ | ||
message: "User not found with id " + req.params.id, | ||
}) | ||
|
||
|
||
} | ||
res.status(200).send(planning); | ||
console.log(planning); | ||
}) | ||
.catch((err) => { | ||
return res.status(500).send({ | ||
message: "Error retrieving user with id " + req.params.id, | ||
}); | ||
}); | ||
} | ||
controller.delete = async (req , res) =>{ | ||
Planning.findByIdAndRemove(req.params.id, (error, data) => { | ||
if (error) { | ||
return next(error); | ||
} else { | ||
res.status(200).json({ | ||
msg: data | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
|
||
controller.edit = async (req, res) => { | ||
|
||
const id = req.params.id; | ||
|
||
Planning.findByIdAndUpdate(id, req.body, { useFindAndModify: false }) | ||
.then(data => { | ||
if (!data) { | ||
res.status(404).send({ | ||
message: `Cannot update Tutorial with id=${id}. Maybe Tutorial was not found!` | ||
}); | ||
} else res.send({ message: "Tutorial was updated successfully." }); | ||
}) | ||
.catch(err => { | ||
res.status(500).send({ | ||
message: "Error updating Tutorial with id=" + id | ||
}); | ||
}); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
module.exports = controller; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var mongoose = require('mongoose'); | ||
var Schema =mongoose.Schema; | ||
|
||
|
||
let planning= new Schema({ | ||
date:{ | ||
type:String | ||
}, | ||
tratament:{ | ||
type: String | ||
}, | ||
plant:{ | ||
type:String | ||
}, | ||
}) | ||
|
||
|
||
module.exports = mongoose.model('planning', planning); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var PlanningController = require("../controllers/PlanningController"); | ||
|
||
|
||
router.get('/list/:id',PlanningController.list); | ||
router.delete('/delete/:id' ,PlanningController.delete); | ||
router.post('/add',PlanningController.add); | ||
router.put('/edit/:id',PlanningController.edit); | ||
router.get('/findOne/:id', PlanningController.findOne); | ||
|
||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ | |
position:fixed; | ||
left:0px; | ||
bottom:0px; | ||
height:30px; | ||
height:50px; | ||
width:100%; | ||
background:lawngreen; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.