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:
@@ -13,12 +13,7 @@ import type { StartSyncRequest } from '@horux/shared';
|
||||
*/
|
||||
export async function start(req: Request, res: Response): Promise<void> {
|
||||
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<void> {
|
||||
*/
|
||||
export async function status(req: Request, res: Response): Promise<void> {
|
||||
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<void> {
|
||||
*/
|
||||
export async function history(req: Request, res: Response): Promise<void> {
|
||||
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<void> {
|
||||
*/
|
||||
export async function jobDetail(req: Request, res: Response): Promise<void> {
|
||||
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<void> {
|
||||
*/
|
||||
export async function retry(req: Request, res: Response): Promise<void> {
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user