Убран лишний код. Скорректированы docker и package файлы. Переработано взаимодействие с бд - упрощена логика. #1
@@ -2,8 +2,6 @@ export type EdgeItemDto = {
|
||||
id: string;
|
||||
name: string;
|
||||
parentId: string | null;
|
||||
tagIds: string[];
|
||||
tagCount: number;
|
||||
};
|
||||
|
||||
export type EdgeResponseDto = {
|
||||
|
||||
@@ -8,8 +8,6 @@ export function createEdgeResponse(rows: EdgeRow[]): EdgeResponseDto {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
parentId: row.parent_id,
|
||||
tagIds: row.tag_ids ?? [],
|
||||
tagCount: row.tag_count,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,16 +6,14 @@ import { EdgeRow } from './edge.types';
|
||||
export class EdgeRepository {
|
||||
constructor(private readonly db: DbService) {}
|
||||
|
||||
/** Читает каталог edge без расчетов по текущим значениям. */
|
||||
/** Reads the edge catalog. */
|
||||
async findAll(parentId: string | null, search: string | null): Promise<EdgeRow[]> {
|
||||
const result = await this.db.query<EdgeRow>(
|
||||
`
|
||||
SELECT
|
||||
e.id,
|
||||
e.name,
|
||||
e.parent_id,
|
||||
e.tag_ids,
|
||||
cardinality(e.tag_ids)::integer AS tag_count
|
||||
e.parent_id
|
||||
FROM edge AS e
|
||||
WHERE ($1::varchar IS NULL OR e.parent_id = $1::varchar)
|
||||
AND (
|
||||
|
||||
@@ -2,6 +2,4 @@ export type EdgeRow = {
|
||||
id: string;
|
||||
name: string;
|
||||
parent_id: string | null;
|
||||
tag_ids: string[];
|
||||
tag_count: number;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class GetTagsDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
edge?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
search?: string;
|
||||
|
||||
@@ -6,7 +6,6 @@ export type TagItemDto = {
|
||||
max: number | null;
|
||||
comment: string;
|
||||
unitOfMeasurement: string;
|
||||
edgeIds: string[];
|
||||
precision: number | null;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ export function createTagResponse(rows: TagRow[]): TagResponseDto {
|
||||
max: row.max,
|
||||
comment: row.comment,
|
||||
unitOfMeasurement: row.unit_of_measurement,
|
||||
edgeIds: row.edge_ids ?? [],
|
||||
precision: row.precision,
|
||||
})),
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@ import { TagRow } from './tag.types';
|
||||
export class TagRepository {
|
||||
constructor(private readonly db: DbService) {}
|
||||
|
||||
/** Читает метаданные тегов с учетом связей из tag.edge_ids и edge.tag_ids. */
|
||||
async findAll(edge: string | null, search: string | null): Promise<TagRow[]> {
|
||||
/** Reads the tag catalog. */
|
||||
async findAll(search: string | null): Promise<TagRow[]> {
|
||||
const result = await this.db.query<TagRow>(
|
||||
`
|
||||
SELECT
|
||||
@@ -18,31 +18,20 @@ export class TagRepository {
|
||||
t.max,
|
||||
t.comment,
|
||||
t.unit_of_measurement,
|
||||
t.edge_ids,
|
||||
t.precision
|
||||
FROM tag AS t
|
||||
WHERE (
|
||||
$1::varchar IS NULL
|
||||
OR $1::varchar = ANY(t.edge_ids)
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM edge AS e
|
||||
WHERE e.id = $1::varchar
|
||||
AND t.id = ANY(e.tag_ids)
|
||||
)
|
||||
$1::text IS NULL
|
||||
OR t.id ILIKE $1::text
|
||||
OR t.name ILIKE $1::text
|
||||
OR t.comment ILIKE $1::text
|
||||
)
|
||||
AND (
|
||||
$2::text IS NULL
|
||||
OR t.id ILIKE $2::text
|
||||
OR t.name ILIKE $2::text
|
||||
OR t.comment ILIKE $2::text
|
||||
)
|
||||
ORDER BY
|
||||
NULLIF(t.tag_group, '') ASC NULLS LAST,
|
||||
t.name ASC,
|
||||
t.id ASC
|
||||
`,
|
||||
[edge, search],
|
||||
[search],
|
||||
);
|
||||
|
||||
return result.rows;
|
||||
|
||||
@@ -10,9 +10,8 @@ export class TagService {
|
||||
|
||||
/** Нормализует фильтры и возвращает метаданные тегов для UI. */
|
||||
async findAll(query: GetTagsDto): Promise<TagResponseDto> {
|
||||
const edge = query.edge ?? null;
|
||||
const search = query.search ? `%${query.search}%` : null;
|
||||
const rows = await this.repository.findAll(edge, search);
|
||||
const rows = await this.repository.findAll(search);
|
||||
return createTagResponse(rows);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,5 @@ export type TagRow = {
|
||||
max: number | null;
|
||||
comment: string;
|
||||
unit_of_measurement: string;
|
||||
edge_ids: string[];
|
||||
precision: number | null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user