<commit_before>var express = require('express');
var models  = require('../models');
var router = express.Router();

/* GET company page. */
router.get('/', function(req, res){

  var sess = req.session;
  console.log(sess)
  var userId = sess.user_id;
  res.render('company', { title: "My Posted Jobs" });
});

router.get('/new_company', function(req, res, next) {
  res.render('new_company', { title: 'Ready to Hire?' });
});

router.post('/new_company', function(req, res){
  var Company = require('../models/company');
  models.Employer.findOrCreate({
    where: {
      id: req.session.user_id
    }
  });

  models.CompanyContact.create({
    employerId: req.session.user_id,
    Company:{
      name: req.body.name,
      phone: req.body.contact,
      email: req.body.email
    }
  },{
    include: [models.Company]
  }).then(function(){
    res.redirect('/company');
  });
});

router.get('/new_job', function(req, res){
  var userId = req.session.user_id;
  var companies = {};
  var categories = {};
  models.sequelize.Promise.all([
    models.CompanyContact.findAll({
      where: {
        employerId: userId
      }
    }),
    models.Company.findAll(),
    models.Category.findAll()
  ]).spread(function(all_companyContact, all_company, all_categories){
    if(all_companyContact == null){
      console.log('company does not exist');
    }else{

      for(var contact of all_companyContact){
        for(var company of all_company){
          if(company.id == contact.companyId){
            companies[company.id] = company.name;
          }
        }
      }

      for(var category of all_categories){
        categories[category.id] = category.name;
      }

    }
    res.render('post_job', {companies: companies, categories: categories});
  });


});

router.post('/new_job', function(req, res){
  var Job = models.Job;
  models.JobCategory.create({<commit_msg>sequalize create employer and CompanyContact<commit_after>var express = require('express');
var models  = require('../models');
var router = express.Router();

/* GET company page. */
router.get('/', function(req, res){

  var sess = req.session;
  console.log(sess)
  var userId = sess.user_id;
  res.render('company', { title: "My Posted Jobs" });
});

router.get('/new_company', function(req, res, next) {
  res.render('new_company', { title: 'Ready to Hire?' });
});

router.post('/new_company', function(req, res){
  var Company = require('../models/company');
  models.Employer.findOrCreate({
    where: {
      id: req.session.user_id
    }
  }).then(function() {
    models.CompanyContact.create({
      employerId: req.session.user_id,
      Company:{
        name: req.body.name,
        phone: req.body.contact,
        email: req.body.email
      }
    },{
      include: [models.Company]
    }).then(function(){
      res.redirect('/company');
    });
  });
});

router.get('/new_job', function(req, res){
  var userId = req.session.user_id;
  var companies = {};
  var categories = {};
  models.sequelize.Promise.all([
    models.CompanyContact.findAll({
      where: {
        employerId: userId
      }
    }),
    models.Company.findAll(),
    models.Category.findAll()
  ]).spread(function(all_companyContact, all_company, all_categories){
    if(all_companyContact == null){
      console.log('company does not exist');
    }else{

      for(var contact of all_companyContact){
        for(var company of all_company){
          if(company.id == contact.companyId){
            companies[company.id] = company.name;
          }
        }
      }

      for(var category of all_categories){
        categories[category.id] = category.name;
      }

    }
    res.render('post_job', {companies: companies, categories: categories});
  });


});

// need to add default value for some of the fields
router.post('/new_job', function(req, res){
  var Job = models.Job;
  models.JobCategory.create({
{'fraction_non_alphanumeric': 0.1605445671718469, 'fraction_numerical': 0.0, 'mean_word_length': 2.965376782077393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6391519', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1211, 'n_words': 248}