From 57995fdeb18e1d2a827c63dc3e092a4641b4d67e Mon Sep 17 00:00:00 2001 From: numex-admin Date: Thu, 10 Sep 2026 08:58:57 +0000 Subject: [PATCH] =?UTF-8?q?Numex=20yay=C4=B1n:=20routes/reports.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/reports.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 routes/reports.js diff --git a/routes/reports.js b/routes/reports.js new file mode 100644 index 0000000..b0bfed0 --- /dev/null +++ b/routes/reports.js @@ -0,0 +1,45 @@ +'use strict'; + +/** + * routes/reports.js + * Kategori bazlı raporlama — API ucu + HTML rapor sayfası. + */ + +const express = require('express'); +const router = express.Router(); +const reportService = require('../services/reportService'); +const categoryModel = require('../models/categoryModel'); + +/** GET /category — raporlama sayfası (tüm kategori özetleri + seçim) */ +router.get('/category', (req, res) => { + const categories = categoryModel.readAll(); + const summaries = reportService.allCategorySummary(); + res.render('reports/category', { + title: 'Kategori Raporu', + categories, + summaries, + bodyClass: 'reports-page' + }); +}); + +/** GET /api/category/:id — JSON rapor ucu */ +router.get('/api/category/:id', (req, res) => { + const { from, to } = req.query; + const idParam = req.params.id; + const catId = idParam === 'all' ? 0 : Number(idParam); + if (isNaN(catId) && idParam !== 'all') { + return res.status(400).json({ error: 'Geçersiz kategori ID' }); + } + const report = reportService.categoryReport(catId, { + fromDate: from || '', + toDate: to || '' + }); + res.json(report); +}); + +/** GET /api/all — tüm kategorilerin özet raporu (JSON) */ +router.get('/api/all', (req, res) => { + res.json(reportService.allCategorySummary()); +}); + +module.exports = router;