22 lines
742 B
TypeScript
22 lines
742 B
TypeScript
import express, { Request, Response } from "express";
|
|
import { getLogin } from "../auth";
|
|
import { parseToken } from "../utils";
|
|
import { WeeklyStats } from "../../../types";
|
|
import { getStats } from "../stats";
|
|
|
|
const router = express.Router();
|
|
|
|
router.get("/", async (req: Request<{}, any, undefined>, res: Response<WeeklyStats>) => {
|
|
getLogin(parseToken(req));
|
|
if (typeof req.query.startDate === 'string' && typeof req.query.endDate === 'string') {
|
|
try {
|
|
const data = await getStats(req.query.startDate, req.query.endDate);
|
|
return res.status(200).json(data);
|
|
} catch (e) {
|
|
// necháme to zatím spadnout na 400
|
|
}
|
|
}
|
|
res.sendStatus(400);
|
|
});
|
|
|
|
export default router; |