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