15vo Commit
This commit is contained in:
parent
dc21b528b3
commit
7a2cd0cd41
3 changed files with 30 additions and 4 deletions
|
|
@ -1,12 +1,13 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Configuracion } from '../configuracion/entities/configuracion.entity.js';
|
||||||
import { Persona } from '../persona/entities/persona.entity.js';
|
import { Persona } from '../persona/entities/persona.entity.js';
|
||||||
import { Reporte } from './entities/reporte.entity.js';
|
import { Reporte } from './entities/reporte.entity.js';
|
||||||
import { ReportesController } from './reportes.controller.js';
|
import { ReportesController } from './reportes.controller.js';
|
||||||
import { ReportesService } from './reportes.service.js';
|
import { ReportesService } from './reportes.service.js';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Persona, Reporte])],
|
imports: [TypeOrmModule.forFeature([Persona, Reporte, Configuracion])],
|
||||||
controllers: [ReportesController],
|
controllers: [ReportesController],
|
||||||
providers: [ReportesService],
|
providers: [ReportesService],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ import {
|
||||||
defaultServiceResult,
|
defaultServiceResult,
|
||||||
ServiceResult,
|
ServiceResult,
|
||||||
} from '../../common/interfaces/service.result.js';
|
} from '../../common/interfaces/service.result.js';
|
||||||
|
import {
|
||||||
|
ZONA_HORA_DEFAULT,
|
||||||
|
ZONA_HORA_RE,
|
||||||
|
} from '../../common/utils/zona-horaria.js';
|
||||||
|
import { Configuracion } from '../configuracion/entities/configuracion.entity.js';
|
||||||
import { Persona } from '../persona/entities/persona.entity.js';
|
import { Persona } from '../persona/entities/persona.entity.js';
|
||||||
import { Reporte } from './entities/reporte.entity.js';
|
import { Reporte } from './entities/reporte.entity.js';
|
||||||
import { TipoReporte } from './dto/reporte.dto.js';
|
import { TipoReporte } from './dto/reporte.dto.js';
|
||||||
|
|
@ -120,8 +125,20 @@ export class ReportesService {
|
||||||
private readonly personaRepository: Repository<Persona>,
|
private readonly personaRepository: Repository<Persona>,
|
||||||
@InjectRepository(Reporte)
|
@InjectRepository(Reporte)
|
||||||
private readonly reporteRepository: Repository<Reporte>,
|
private readonly reporteRepository: Repository<Reporte>,
|
||||||
|
@InjectRepository(Configuracion)
|
||||||
|
private readonly configuracionRepository: Repository<Configuracion>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offset de `configuracion.zonaHoraria` para convertir los `timestamptz`
|
||||||
|
* antes de formatear (`to_char … AT TIME ZONE`); inválido/vacío → default.
|
||||||
|
*/
|
||||||
|
private async zonaHoraria(): Promise<string> {
|
||||||
|
const config = await this.configuracionRepository.findOneBy({});
|
||||||
|
const zona = config?.zonaHoraria ?? '';
|
||||||
|
return ZONA_HORA_RE.test(zona) ? zona : ZONA_HORA_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- acceso
|
// ---------------------------------------------------------------- acceso
|
||||||
|
|
||||||
/** Developer (bypass) y SuperAdmin ven todo; solo el Líder ve reportes. */
|
/** Developer (bypass) y SuperAdmin ven todo; solo el Líder ve reportes. */
|
||||||
|
|
@ -281,6 +298,12 @@ export class ReportesService {
|
||||||
paramsFilas.push(`{${equipos.join(',')}}`);
|
paramsFilas.push(`{${equipos.join(',')}}`);
|
||||||
whereFilas += ' AND a."idEquipo" = ANY($2::uuid[])';
|
whereFilas += ' AND a."idEquipo" = ANY($2::uuid[])';
|
||||||
}
|
}
|
||||||
|
// Hora de la organización (config.zonaHoraria): los timestamptz se
|
||||||
|
// convierten ANTES de to_char — sin esto PG formatea en la TimeZone
|
||||||
|
// de su sesión (típicamente UTC) y las horas salen desfasadas
|
||||||
|
// (tanda 2026-10-30, pedido del usuario).
|
||||||
|
const idxZona = paramsFilas.length + 1;
|
||||||
|
paramsFilas.push(await this.zonaHoraria());
|
||||||
|
|
||||||
const filas: Fila[] = await manager.query(
|
const filas: Fila[] = await manager.query(
|
||||||
`SELECT a."idAsistencia",
|
`SELECT a."idAsistencia",
|
||||||
|
|
@ -293,8 +316,10 @@ export class ReportesService {
|
||||||
e."nombreEquipo" AS equipo,
|
e."nombreEquipo" AS equipo,
|
||||||
a.estado,
|
a.estado,
|
||||||
a."fecIngreso" IS NOT NULL AS "tieneIngreso",
|
a."fecIngreso" IS NOT NULL AS "tieneIngreso",
|
||||||
to_char(a."fecIngreso", 'HH24:MI DD-MM-YYYY') AS ingreso,
|
to_char(a."fecIngreso" AT TIME ZONE $${idxZona}::text,
|
||||||
to_char(a."fecSalida", 'HH24:MI DD-MM-YYYY') AS salida,
|
'HH24:MI DD-MM-YYYY') AS ingreso,
|
||||||
|
to_char(a."fecSalida" AT TIME ZONE $${idxZona}::text,
|
||||||
|
'HH24:MI DD-MM-YYYY') AS salida,
|
||||||
a.observacion
|
a.observacion
|
||||||
FROM asistencia a
|
FROM asistencia a
|
||||||
JOIN persona p ON p."idPersona" = a."idPersona"
|
JOIN persona p ON p."idPersona" = a."idPersona"
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue