const express = require('express');
const router = express.Router();

const tools = require('../tools/general');

var server_constants = require('../tools/server_constants');

var { Project } = require('../models/project');

var { authenticate } = require('../middleware/authenticate');

var mongoose = require('mongoose').set('debug', false)
const Subscription = require('../models/subscribers');

var { Todo } = require('../models/todo');
const { Settings } = require('../models/settings');

const _ = require('lodash');

const { ObjectId } = require('mongodb');


router.get('/', async (req, res) => {

  const todo = {
    // category: "personal",
    statustodo: 0,
    completed_at: new Date(),
    created_at: new Date(),
    descr: "Primo Task Esempio",
    enableExpiring: false,
    expiring_at: new Date(),
    modified: false,
    modify_at: new Date(),
    pos: 1,
    priority: 1,
    progress: 0,
    userId: '5e135ede41a7ee26519464f7'
  };

  const myrec = new Todo(todo);
  myrec._id = new ObjectId();

  const TodoOne = myrec.save().then((ris, err) => {
    console.log('Err:', err);
    console.log('Ris:', ris);

  });


  const newrec = new Settings({ key: 'chiave1' });
  newrec._id = new ObjectId();
  newrec.idapp = '8';

  const rec = await newrec.save();
  if (err)
    console.log('ERROR: ', err);
  if (rec) {
    console.log('SAVED? ', rec);
  }

  res.send({});

});


module.exports = router;
