"use strict"; /** * Fraccionamiento Service * Servicio para gestión de fraccionamientos/obras * * @module Construction */ Object.defineProperty(exports, "__esModule", { value: true }); exports.FraccionamientoService = void 0; const typeorm_config_1 = require("../../../shared/database/typeorm.config"); const fraccionamiento_entity_1 = require("../entities/fraccionamiento.entity"); class FraccionamientoService { repository; constructor() { this.repository = typeorm_config_1.AppDataSource.getRepository(fraccionamiento_entity_1.Fraccionamiento); } async findAll(filters) { const where = { tenantId: filters.tenantId, }; if (filters.proyectoId) { where.proyectoId = filters.proyectoId; } if (filters.estado) { where.estado = filters.estado; } return this.repository.find({ where, relations: ['proyecto'], order: { createdAt: 'DESC' }, }); } async findById(id, tenantId) { return this.repository.findOne({ where: { id, tenantId }, relations: ['proyecto', 'createdBy'], }); } async findByCodigo(codigo, tenantId) { return this.repository.findOne({ where: { codigo, tenantId }, }); } async findByProyecto(proyectoId, tenantId) { return this.repository.find({ where: { proyectoId, tenantId }, order: { codigo: 'ASC' }, }); } async create(data) { const fraccionamiento = this.repository.create(data); return this.repository.save(fraccionamiento); } async update(id, tenantId, data) { const fraccionamiento = await this.findById(id, tenantId); if (!fraccionamiento) { return null; } Object.assign(fraccionamiento, data); return this.repository.save(fraccionamiento); } async delete(id, tenantId) { const result = await this.repository.delete({ id, tenantId }); return result.affected ? result.affected > 0 : false; } async countByProyecto(proyectoId, tenantId) { return this.repository.count({ where: { proyectoId, tenantId }, }); } } exports.FraccionamientoService = FraccionamientoService; //# sourceMappingURL=fraccionamiento.service.js.map