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

router.post("/create", authorize(), create);
router.post("/", authorize(), getAll);
router.post("/get-by-approver", authorize(), getByApprover);
router.post("/get-available", authorize(), getAvailable);
router.post("/option", authorize(), option);
router.get("/count", authorize(), count);
router.put("/:id", authorize(), update);
router.delete("/:id", authorize(), _delete);

module.exports = router;

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

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

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

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

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

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

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

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