This commit is contained in:
22
server/src/routes/statsRoutes.ts
Normal file
22
server/src/routes/statsRoutes.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user