fix(sat): muestra extraccion inicial si no hay job initial completado

Problema: el boton 'Sincronizacion inicial (6 años)' desaparecia cuando
existia CUALQUIER job completado (daily, incremental, etc.). Esto era
inconsistente con el cron incremental del backend, que requiere
especificamente un job de tipo 'initial' completado.

Resultado: usuarios que solo habian hecho sync diaria perdian la opcion
de hacer la extraccion inicial completa, y el cron incremental tampoco
corria porque no habia initial.

Fix:
- Backend getSyncStatus: agrega lastCompletedInitialJob (busca solo
  jobs type='initial' status='completed')
- Frontend SyncStatus: muestra el boton de inicial si
  !lastCompletedInitialJob (ignora jobs diarios/incrementales)
- SatSyncStatusResponse: agrega campo lastCompletedInitialJob
This commit is contained in:
Horux Dev
2026-05-16 19:16:07 +00:00
parent bd1edca15e
commit 1c92b8eaf1
3 changed files with 14 additions and 1 deletions

View File

@@ -1388,6 +1388,7 @@ export async function getSyncStatus(tenantId: string, contribuyenteId?: string):
hasActiveSync: boolean; hasActiveSync: boolean;
currentJob?: SatSyncJob; currentJob?: SatSyncJob;
lastCompletedJob?: SatSyncJob; lastCompletedJob?: SatSyncJob;
lastCompletedInitialJob?: SatSyncJob;
totalCfdisSynced: number; totalCfdisSynced: number;
}> { }> {
const contribuyenteFilter = contribuyenteId ? { contribuyenteId } : {}; const contribuyenteFilter = contribuyenteId ? { contribuyenteId } : {};
@@ -1410,6 +1411,16 @@ export async function getSyncStatus(tenantId: string, contribuyenteId?: string):
orderBy: { completedAt: 'desc' }, orderBy: { completedAt: 'desc' },
}); });
const lastCompletedInitial = await prisma.satSyncJob.findFirst({
where: {
tenantId,
...contribuyenteFilter,
type: 'initial',
status: 'completed',
},
orderBy: { completedAt: 'desc' },
});
const totals = await prisma.satSyncJob.aggregate({ const totals = await prisma.satSyncJob.aggregate({
where: { where: {
tenantId, tenantId,
@@ -1447,6 +1458,7 @@ export async function getSyncStatus(tenantId: string, contribuyenteId?: string):
hasActiveSync: !!activeJob, hasActiveSync: !!activeJob,
currentJob: activeJob ? mapJob(activeJob) : undefined, currentJob: activeJob ? mapJob(activeJob) : undefined,
lastCompletedJob: lastCompleted ? mapJob(lastCompleted) : undefined, lastCompletedJob: lastCompleted ? mapJob(lastCompleted) : undefined,
lastCompletedInitialJob: lastCompletedInitial ? mapJob(lastCompletedInitial) : undefined,
totalCfdisSynced: totals._sum.cfdisInserted || 0, totalCfdisSynced: totals._sum.cfdisInserted || 0,
}; };
} }

View File

@@ -236,7 +236,7 @@ export function SyncStatus({ fielConfigured, onSyncStarted, contribuyenteId }: S
</Button> </Button>
</div> </div>
{!status?.lastCompletedJob && ( {!status?.lastCompletedInitialJob && (
<Button <Button
disabled={startingSync || status?.hasActiveSync} disabled={startingSync || status?.hasActiveSync}
onClick={() => handleStartSync('initial')} onClick={() => handleStartSync('initial')}

View File

@@ -52,6 +52,7 @@ export interface SatSyncStatusResponse {
hasActiveSync: boolean; hasActiveSync: boolean;
currentJob?: SatSyncJob; currentJob?: SatSyncJob;
lastCompletedJob?: SatSyncJob; lastCompletedJob?: SatSyncJob;
lastCompletedInitialJob?: SatSyncJob;
totalCfdisSynced: number; totalCfdisSynced: number;
} }