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

var {User} = require('../models/user');

router.get('/:idapp/:email', (req, res) => {
  var email = req.params.email;
  const idapp = req.params.idapp;

  User.findByEmail(idapp, email).then((user) => {
    if (!user) {
      return res.status(404).send();
    }
    res.status(200).send();
  }).catch((e) => {
    res.status(400).send();
  });
});

router.post('/ck', (req, res) => {
  const idapp = req.body.idapp;
  var email = req.body.email;

  User.findByEmail(idapp, email, true).then((user) => {
    if (!user) {
      return res.status(404).send();
    }
    res.status(200).send();
  }).catch((e) => {
    res.status(400).send();
  });
});

module.exports = router;
