From 75a9819c1ebed3261c22dbac5dd5007b9f773586 Mon Sep 17 00:00:00 2001 From: Consultoria AS Date: Sun, 25 Jan 2026 01:45:42 +0000 Subject: [PATCH] fix: use JWT tenantId instead of header in FIEL and SAT controllers The controllers were looking for x-tenant-id header which the frontend doesn't send. Now using req.user!.tenantId from the JWT token instead. Co-Authored-By: Claude Opus 4.5 --- apps/api/src/controllers/fiel.controller.ts | 20 ++---------- apps/api/src/controllers/sat.controller.ts | 34 +++------------------ 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/apps/api/src/controllers/fiel.controller.ts b/apps/api/src/controllers/fiel.controller.ts index 5efa5ba..ba21971 100644 --- a/apps/api/src/controllers/fiel.controller.ts +++ b/apps/api/src/controllers/fiel.controller.ts @@ -7,11 +7,7 @@ import type { FielUploadRequest } from '@horux/shared'; */ export async function upload(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } + const tenantId = req.user!.tenantId; const { cerFile, keyFile, password } = req.body as FielUploadRequest; @@ -42,12 +38,7 @@ export async function upload(req: Request, res: Response): Promise { */ export async function status(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } - + const tenantId = req.user!.tenantId; const fielStatus = await getFielStatus(tenantId); res.json(fielStatus); } catch (error: any) { @@ -61,12 +52,7 @@ export async function status(req: Request, res: Response): Promise { */ export async function remove(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } - + const tenantId = req.user!.tenantId; const deleted = await deleteFiel(tenantId); if (!deleted) { diff --git a/apps/api/src/controllers/sat.controller.ts b/apps/api/src/controllers/sat.controller.ts index 2047460..3d12a33 100644 --- a/apps/api/src/controllers/sat.controller.ts +++ b/apps/api/src/controllers/sat.controller.ts @@ -13,12 +13,7 @@ import type { StartSyncRequest } from '@horux/shared'; */ export async function start(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } - + const tenantId = req.user!.tenantId; const { type, dateFrom, dateTo } = req.body as StartSyncRequest; const jobId = await startSync( @@ -49,12 +44,7 @@ export async function start(req: Request, res: Response): Promise { */ export async function status(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } - + const tenantId = req.user!.tenantId; const syncStatus = await getSyncStatus(tenantId); res.json(syncStatus); } catch (error: any) { @@ -68,12 +58,7 @@ export async function status(req: Request, res: Response): Promise { */ export async function history(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } - + const tenantId = req.user!.tenantId; const page = parseInt(req.query.page as string) || 1; const limit = parseInt(req.query.limit as string) || 10; @@ -94,12 +79,7 @@ export async function history(req: Request, res: Response): Promise { */ export async function jobDetail(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } - + const tenantId = req.user!.tenantId; const { id } = req.params; const { jobs } = await getSyncHistory(tenantId, 1, 100); const job = jobs.find(j => j.id === id); @@ -121,12 +101,6 @@ export async function jobDetail(req: Request, res: Response): Promise { */ export async function retry(req: Request, res: Response): Promise { try { - const tenantId = req.headers['x-tenant-id'] as string; - if (!tenantId) { - res.status(400).json({ error: 'Tenant ID requerido' }); - return; - } - const id = req.params.id as string; const newJobId = await retryJob(id);