"use strict"; /** * Proyecto Service * Servicio para gestión de proyectos de construcción * * @module Construction */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ProyectoService = void 0; const typeorm_config_1 = require("../../../shared/database/typeorm.config"); const proyecto_entity_1 = require("../entities/proyecto.entity"); class ProyectoService { repository; constructor() { this.repository = typeorm_config_1.AppDataSource.getRepository(proyecto_entity_1.Proyecto); } async findAll(filters) { const where = { tenantId: filters.tenantId, }; if (filters.estadoProyecto) { where.estadoProyecto = filters.estadoProyecto; } if (filters.ciudad) { where.ciudad = filters.ciudad; } return this.repository.find({ where, relations: ['fraccionamientos'], order: { createdAt: 'DESC' }, }); } async findById(id, tenantId) { return this.repository.findOne({ where: { id, tenantId }, relations: ['fraccionamientos', 'createdBy'], }); } async findByCodigo(codigo, tenantId) { return this.repository.findOne({ where: { codigo, tenantId }, }); } async create(data) { const proyecto = this.repository.create(data); return this.repository.save(proyecto); } async update(id, tenantId, data) { const proyecto = await this.findById(id, tenantId); if (!proyecto) { return null; } Object.assign(proyecto, data); return this.repository.save(proyecto); } async delete(id, tenantId) { const result = await this.repository.delete({ id, tenantId }); return result.affected ? result.affected > 0 : false; } async getStatistics(tenantId) { const proyectos = await this.repository.find({ where: { tenantId } }); return { total: proyectos.length, activos: proyectos.filter(p => p.estadoProyecto === 'activo').length, completados: proyectos.filter(p => p.estadoProyecto === 'completado').length, pausados: proyectos.filter(p => p.estadoProyecto === 'pausado').length, }; } } exports.ProyectoService = ProyectoService; //# sourceMappingURL=proyecto.service.js.map