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:
@@ -1388,6 +1388,7 @@ export async function getSyncStatus(tenantId: string, contribuyenteId?: string):
|
||||
hasActiveSync: boolean;
|
||||
currentJob?: SatSyncJob;
|
||||
lastCompletedJob?: SatSyncJob;
|
||||
lastCompletedInitialJob?: SatSyncJob;
|
||||
totalCfdisSynced: number;
|
||||
}> {
|
||||
const contribuyenteFilter = contribuyenteId ? { contribuyenteId } : {};
|
||||
@@ -1410,6 +1411,16 @@ export async function getSyncStatus(tenantId: string, contribuyenteId?: string):
|
||||
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({
|
||||
where: {
|
||||
tenantId,
|
||||
@@ -1447,6 +1458,7 @@ export async function getSyncStatus(tenantId: string, contribuyenteId?: string):
|
||||
hasActiveSync: !!activeJob,
|
||||
currentJob: activeJob ? mapJob(activeJob) : undefined,
|
||||
lastCompletedJob: lastCompleted ? mapJob(lastCompleted) : undefined,
|
||||
lastCompletedInitialJob: lastCompletedInitial ? mapJob(lastCompletedInitial) : undefined,
|
||||
totalCfdisSynced: totals._sum.cfdisInserted || 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ export function SyncStatus({ fielConfigured, onSyncStarted, contribuyenteId }: S
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{!status?.lastCompletedJob && (
|
||||
{!status?.lastCompletedInitialJob && (
|
||||
<Button
|
||||
disabled={startingSync || status?.hasActiveSync}
|
||||
onClick={() => handleStartSync('initial')}
|
||||
|
||||
@@ -52,6 +52,7 @@ export interface SatSyncStatusResponse {
|
||||
hasActiveSync: boolean;
|
||||
currentJob?: SatSyncJob;
|
||||
lastCompletedJob?: SatSyncJob;
|
||||
lastCompletedInitialJob?: SatSyncJob;
|
||||
totalCfdisSynced: number;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user