From e99d9c1a7d043a2e888d97ad8873366d15f22590 Mon Sep 17 00:00:00 2001 From: Esteban Date: Tue, 3 Feb 2026 02:43:55 -0600 Subject: [PATCH] Relation meter with project --- water-api/src/services/meter.service.ts | 16 +++++++++++++--- water-api/src/validators/meter.validator.ts | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/water-api/src/services/meter.service.ts b/water-api/src/services/meter.service.ts index 9a0583b..6e66ccc 100644 --- a/water-api/src/services/meter.service.ts +++ b/water-api/src/services/meter.service.ts @@ -2,13 +2,14 @@ import { query } from '../config/database'; /** * Meter interface matching database schema - * Meters are linked to concentrators (not directly to projects) + * Meters are linked to both projects and concentrators */ export interface Meter { id: string; serial_number: string; meter_id: string | null; name: string; + project_id: string; concentrator_id: string; location: string | null; type: string; @@ -123,6 +124,7 @@ export interface CreateMeterInput { serial_number: string; meter_id?: string | null; name: string; + project_id: string; concentrator_id: string; location?: string; type?: string; @@ -173,6 +175,7 @@ export interface UpdateMeterInput { serial_number?: string; meter_id?: string | null; name?: string; + project_id?: string; concentrator_id?: string; location?: string; type?: string; @@ -343,13 +346,14 @@ export async function getById(id: string): Promise { */ export async function create(data: CreateMeterInput): Promise { const result = await query( - `INSERT INTO meters (serial_number, meter_id, name, concentrator_id, location, type, status, installation_date) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8) + `INSERT INTO meters (serial_number, meter_id, name, project_id, concentrator_id, location, type, status, installation_date) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *`, [ data.serial_number, data.meter_id || null, data.name, + data.project_id, data.concentrator_id, data.location || null, data.type || 'LORA', @@ -387,6 +391,12 @@ export async function update(id: string, data: UpdateMeterInput): Promise