aboutsummaryrefslogtreecommitdiff
path: root/api/src/modules/dashboard/dashboard.routes.ts
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-08-16 23:17:42 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-08-16 23:17:42 +0000
commit375482e654a01615683867e732ac9e458c7cbe74 (patch)
tree12d1b31b8deb6bf8590bcdbc2cfb52dcc553e006 /api/src/modules/dashboard/dashboard.routes.ts
parent2c2dfba45357bbd205a59145ae55a2779c911ae0 (diff)
downloadyaba-master.tar.gz
yaba-master.zip
feat: upload yaba srcHEADmaster
Signed-off-by: Lucas Faria Mendes <lucas.fariamo08@gmail.com>
Diffstat (limited to 'api/src/modules/dashboard/dashboard.routes.ts')
-rw-r--r--api/src/modules/dashboard/dashboard.routes.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/api/src/modules/dashboard/dashboard.routes.ts b/api/src/modules/dashboard/dashboard.routes.ts
new file mode 100644
index 0000000..d579ef2
--- /dev/null
+++ b/api/src/modules/dashboard/dashboard.routes.ts
@@ -0,0 +1,50 @@
+import type { FastifyPluginAsync } from 'fastify';
+import { z } from 'zod';
+import * as dashboardService from './dashboard.service';
+
+const dashboardQuerySchema = z.object({
+ month: z.coerce.number().int().min(1).max(12).optional(),
+ year: z.coerce.number().int().min(2020).optional(),
+});
+
+const dashboardParamsSchema = z.object({
+ userId: z.coerce.number().int().positive(),
+});
+
+const dashboardRoutes: FastifyPluginAsync = async (fastify) => {
+ /**
+ * GET /users/:userId/dashboard
+ * Retorna o resumo financeiro completo do mês.
+ *
+ * Query params (opcionais):
+ * ?month=6&year=2025 → mês/ano específico
+ * Sem params → mês/ano atual
+ *
+ * Resposta:
+ * - Dados do usuário e salário
+ * - Lista de gastos recorrentes ativos
+ * - Lista de gastos avulsos do mês
+ * - Saldo disponível e percentual comprometido
+ */
+ fastify.get<{ Params: { userId: string }; Querystring: Record<string, string> }>(
+ '/users/:userId/dashboard',
+ async (request, reply) => {
+ const { userId } = dashboardParamsSchema.parse(request.params);
+ const query = dashboardQuerySchema.parse(request.query);
+
+ const now = new Date();
+ const month = query.month ?? now.getMonth() + 1;
+ const year = query.year ?? now.getFullYear();
+
+ const data = await dashboardService.getDashboard(userId, month, year);
+
+ if (!data) {
+ return reply.status(404).send({ error: 'Usuário não encontrado.' });
+ }
+
+ return reply.send({ data });
+ },
+ );
+};
+
+export default dashboardRoutes;