var express = require('express');
var router = express.Router();
var Models = require('../../models');
var config    = require('../../../config.json');
router.get('/', function(req, res) {
    Models.FolioProject.findAll({order:[['sortIndex', 'DESC']]}).then(projects=> {
        res.render(config.theme+'/work', {
            theme: config.theme,
            title: 'The Twelfth House | Creative Works and Projects',
            projects: projects,
            mode: 'projects'
        });
    }).then(function(value) {
        //console.log(value);
    }).catch(function(err) {
        //next(err);
    })
});

router.get('/:id', function(req, res) {
  Models.FolioProject.findOne({where:{slug: req.params.id}}).then((project) => {
    res.render(config.theme+'/work-project', {
        title: project.title,
        type: project.type,
        desc: project.description,
        images: JSON.parse(project.images),
        mode:'folio',
        url:project.url
    });

  }).catch((err) => {
      console.log(err);
  });
});


module.exports = router;
