Files
cloud-v3/src/current/current.repository.ts
Первов Артем 05a9e0e535 first commit
2026-06-19 08:18:52 +03:00

39 lines
1.0 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { DbService } from '../db/db.service';
import { CurrentRow } from './current.types';
@Injectable()
export class CurrentRepository {
constructor(private readonly db: DbService) {}
/** Читает текущие значения и добавляет метаданные тегов для UI-дашбордов. */
async findByEdge(edge: string, tags: string[] | null): Promise<CurrentRow[]> {
const result = await this.db.query<CurrentRow>(
`
SELECT
c.edge,
c.tag,
c.value,
c."createdAt",
c."updatedAt",
t.name,
t.tag_group,
t.min,
t.max,
t.comment,
t.unit_of_measurement,
t.precision
FROM current AS c
LEFT JOIN tag AS t
ON t.id = c.tag
WHERE c.edge = $1
AND ($2::varchar[] IS NULL OR c.tag = ANY($2::varchar[]))
ORDER BY c.tag ASC
`,
[edge, tags],
);
return result.rows;
}
}