<commit_before>const express = require('express');
const router = express.Router();
const bcrypt = require('bcrypt');
const knex = require('../knex');
const jwt = require('jsonwebtoken');

router.get('/', (req, res) => {
   res.render('create')
})

router.post('/', (req, res) => {
   console.log('body', req.body);
   let title = req.body.title
   let userID = req.cookies.userID
   console.log('userid', userID);
   //knex to add deck
   knex('decks')
      .returning(['id', 'name', 'user_id'])
      .insert({
        'name': title,
        'user_id': userID
      })
      .then((data) => {
         console.log('daaata', data);
         res.render('create')
      })

   //knex to add card
   for (let card in req.body.front){
      console.log(req.body.front[card]);
      console.log(req.body.back[card]);
   }
   // let card  = {req.body.front[1]: req.body.back[1]}
   // console.log('card obj', card);
   // knex('cards')


})

module.exports = router;<commit_msg>user can create decks and populate with cards<commit_after>const express = require('express');
const router = express.Router();
const bcrypt = require('bcrypt');
const knex = require('../knex');
const jwt = require('jsonwebtoken');

router.get('/', (req, res) => {
   res.render('create')
})

router.post('/', (req, res) => {
   console.log('body', req.body);
   let title = req.body.title
   let userID = req.cookies.userID
   console.log('userid', userID);
   //knex to add deck

   function createDeck() {
      return knex('decks')
               .returning(['id', 'name', 'user_id'])
               .insert({
                  'name': title,
                  'user_id': userID
               })
               .then((deck) => {
                  console.log('daaata', deck[0]);
                  return deck[0]
               })
   }
   // knex to add card
   function createCard(deck) {
      for (let card in req.body.front){
        knex('cards')
            .returning(['id', 'front', 'back', 'deck_id', 'got_it'])
            .insert({
               'front': req.body.front[card],
               'back': req.body.back[card],
               'deck_id':deck.id,
               'got_it': false
            })
            .then((card) => {
               console.log('card', card);
               return card
            })
         }
   }

   function createDeckandCards() {
     return createDeck()
       .then(createCard)
   }

   createDeckandCards()
   .then(() => {
      res.redirect('decks')
   })

})

module.exports = router;
{'fraction_non_alphanumeric': 0.17838696861342868, 'fraction_numerical': 0.0015891934843067143, 'mean_word_length': 2.0337349397590363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6153127', 'n_tokens_mistral': 811, 'n_tokens_neox': 799, 'n_words': 169}