const express = require("express");
const router = express.Router();
const authorize = require("../../../../middlewares/authorize-sapps");
const employeeCheckinService = require("./employeeCheckin.service");
const redisClient = require("../../../../redisClient");

router.post("/create", authorize(), create);
router.post("/", authorize(), getAll);
router.get("/filter", authorize(), filter);
router.get("/count", authorize(), count);
router.put("/:id", authorize(), update);
router.delete("/:id", authorize(), _delete);

module.exports = router;

function create(req, res, next) {
	employeeCheckinService
		.create(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function getAll(req, res, next) {
	employeeCheckinService
		.getAll(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function filter(req, res, next) {
	employeeCheckinService
		.filter(req.query)
		.then((result) => res.json(result))
		.catch(next);
}

function count(req, res, next) {
	employeeCheckinService
		.count()
		.then((result) => res.json(result))
		.catch(next);
}

function update(req, res, next) {
	employeeCheckinService
		.update(req.params.id, req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function _delete(req, res, next) {
	employeeCheckinService
		.delete(req.params.id)
		.then((result) => res.json(result))
		.catch(next);
}
