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 <noreply@anthropic.com>
This commit is contained in:
Consultoria AS
2026-01-25 01:45:42 +00:00
parent 2dd22ec152
commit 75a9819c1e
2 changed files with 7 additions and 47 deletions

View File

@@ -7,11 +7,7 @@ import type { FielUploadRequest } from '@horux/shared';
*/ */
export async function upload(req: Request, res: Response): Promise<void> { export async function upload(req: Request, res: Response): Promise<void> {
try { try {
const tenantId = req.headers['x-tenant-id'] as string; const tenantId = req.user!.tenantId;
if (!tenantId) {
res.status(400).json({ error: 'Tenant ID requerido' });
return;
}
const { cerFile, keyFile, password } = req.body as FielUploadRequest; const { cerFile, keyFile, password } = req.body as FielUploadRequest;
@@ -42,12 +38,7 @@ export async function upload(req: Request, res: Response): Promise<void> {
*/ */
export async function status(req: Request, res: Response): Promise<void> { export async function status(req: Request, res: Response): Promise<void> {
try { try {
const tenantId = req.headers['x-tenant-id'] as string; const tenantId = req.user!.tenantId;
if (!tenantId) {
res.status(400).json({ error: 'Tenant ID requerido' });
return;
}
const fielStatus = await getFielStatus(tenantId); const fielStatus = await getFielStatus(tenantId);
res.json(fielStatus); res.json(fielStatus);
} catch (error: any) { } catch (error: any) {
@@ -61,12 +52,7 @@ export async function status(req: Request, res: Response): Promise<void> {
*/ */
export async function remove(req: Request, res: Response): Promise<void> { export async function remove(req: Request, res: Response): Promise<void> {
try { try {
const tenantId = req.headers['x-tenant-id'] as string; const tenantId = req.user!.tenantId;
if (!tenantId) {
res.status(400).json({ error: 'Tenant ID requerido' });
return;
}
const deleted = await deleteFiel(tenantId); const deleted = await deleteFiel(tenantId);
if (!deleted) { if (!deleted) {

View File

@@ -13,12 +13,7 @@ import type { StartSyncRequest } from '@horux/shared';
*/ */
export async function start(req: Request, res: Response): Promise<void> { export async function start(req: Request, res: Response): Promise<void> {
try { try {
const tenantId = req.headers['x-tenant-id'] as string; const tenantId = req.user!.tenantId;
if (!tenantId) {
res.status(400).json({ error: 'Tenant ID requerido' });
return;
}
const { type, dateFrom, dateTo } = req.body as StartSyncRequest; const { type, dateFrom, dateTo } = req.body as StartSyncRequest;
const jobId = await startSync( const jobId = await startSync(
@@ -49,12 +44,7 @@ export async function start(req: Request, res: Response): Promise<void> {
*/ */
export async function status(req: Request, res: Response): Promise<void> { export async function status(req: Request, res: Response): Promise<void> {
try { try {
const tenantId = req.headers['x-tenant-id'] as string; const tenantId = req.user!.tenantId;
if (!tenantId) {
res.status(400).json({ error: 'Tenant ID requerido' });
return;
}
const syncStatus = await getSyncStatus(tenantId); const syncStatus = await getSyncStatus(tenantId);
res.json(syncStatus); res.json(syncStatus);
} catch (error: any) { } catch (error: any) {
@@ -68,12 +58,7 @@ export async function status(req: Request, res: Response): Promise<void> {
*/ */
export async function history(req: Request, res: Response): Promise<void> { export async function history(req: Request, res: Response): Promise<void> {
try { try {
const tenantId = req.headers['x-tenant-id'] as string; const tenantId = req.user!.tenantId;
if (!tenantId) {
res.status(400).json({ error: 'Tenant ID requerido' });
return;
}
const page = parseInt(req.query.page as string) || 1; const page = parseInt(req.query.page as string) || 1;
const limit = parseInt(req.query.limit as string) || 10; const limit = parseInt(req.query.limit as string) || 10;
@@ -94,12 +79,7 @@ export async function history(req: Request, res: Response): Promise<void> {
*/ */
export async function jobDetail(req: Request, res: Response): Promise<void> { export async function jobDetail(req: Request, res: Response): Promise<void> {
try { try {
const tenantId = req.headers['x-tenant-id'] as string; const tenantId = req.user!.tenantId;
if (!tenantId) {
res.status(400).json({ error: 'Tenant ID requerido' });
return;
}
const { id } = req.params; const { id } = req.params;
const { jobs } = await getSyncHistory(tenantId, 1, 100); const { jobs } = await getSyncHistory(tenantId, 1, 100);
const job = jobs.find(j => j.id === id); const job = jobs.find(j => j.id === id);
@@ -121,12 +101,6 @@ export async function jobDetail(req: Request, res: Response): Promise<void> {
*/ */
export async function retry(req: Request, res: Response): Promise<void> { export async function retry(req: Request, res: Response): Promise<void> {
try { 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 id = req.params.id as string;
const newJobId = await retryJob(id); const newJobId = await retryJob(id);