Permalink
Browse files

add: write new employee to database

  • Loading branch information...
mpowroznik committed Apr 21, 2017
1 parent 4c3456e commit a871f7b1e5e9fffb696a95213b2bce9869a63cb1
Showing with 42 additions and 3 deletions.
  1. +3 −1 models/employee.js
  2. +34 −1 routes/employee.js
  3. +5 −1 views/employee/index.jade
@@ -3,6 +3,8 @@ var mongoose = require('mongoose')
mongoose.Promise = require('bluebird');
var Employee = require('../models/employee');
var employeeSchema = new Schema({
"pesel": Number,
"imie": String,
@@ -20,6 +22,6 @@ var employeeSchema = new Schema({
"lekarskie": [{
"wazneDo":Date
}]
},{collection: 'azurjan'});
},{collection: 'employee'});
module.exports = mongoose.model('Employee',employeeSchema);
@@ -4,11 +4,44 @@ var express = require('express')
var Employee = require('../models/employee');
router.get('/',function(req,res){
res.render('employee/index');
Employee.find(function(err,azurjans){
res.render('employee/index',{list: azurjans});
}).select('imie nazwisko firma -_id');
});
router.get('/add',function(req,res){
res.render('employee/add');
});
router.post('/add',function(req,res,cb){
var firma = req.body.firma
, imie = req.body.imie
, nazwisko = req.body.nazwisko
, dataUr = req.body.dataUr
, pesel = req.body.PESEL
, umowa = req.body.umowa
, wstepne = req.body.wstepne
, ryzyko = req.body.ryzyko
, dataWystawienia = req.body.dataWystawienia
, ileWazne = req.body.ileWazne
, kierownicze = req.body.kierownicze
, dataWystawieniaLekarskie = req.body.dataWystawieniaLekarskie
var newEmployee = new Employee({
pesel: pesel,
imie: imie,
nazwisko: nazwisko,
dataUr: dataUr,
firma: firma,
umowa: umowa,
wstepne: wstepne,
ryzyko: ryzyko
});
newEmployee.save(cb);
res.redirect('/employee');
});
module.exports = router;
@@ -17,5 +17,9 @@ html
.row
.col-md-12
a(href="/employee/add") Add new employee
.row
.col-md-12
each item in list
li= item
include ../inc/ga.html

0 comments on commit a871f7b

Please sign in to comment.