Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+162
-165
@@ -1,4 +1,4 @@
|
||||
import { BULK_REINDEX_SUPPORTED_INDEX_NAMES, crmContactsIndex, kbArticlesIndex, rowsIndex, usersIndex } from "@toolctrl/search";
|
||||
import { BULK_REINDEX_SUPPORTED_INDEX_NAMES, crmContactsIndex, kbArticlesIndex, projectsIndex, usersIndex } from "@hivegrid/search";
|
||||
import type { SearchIndexerBulkPager, SearchIndexerDependencies } from "./search-indexer.js";
|
||||
|
||||
type KnowledgeBaseArticleRow = {
|
||||
@@ -15,37 +15,21 @@ type KnowledgeBaseArticleRow = {
|
||||
knowledgeBase: { tenantId: string | null };
|
||||
};
|
||||
|
||||
const SEARCHABLE_ROW_PROPERTY_TYPES = new Set([1, 8]); // TEXT, SELECT
|
||||
|
||||
type RowSearchProperty = {
|
||||
// CRM-contact search rows now come from the typed `Kontakt` table (R-P6 / R-P6B-β,
|
||||
// AD-2) instead of the removed generic entity-builder `Row` engine.
|
||||
type KontaktSearchRow = {
|
||||
id: string;
|
||||
name: string;
|
||||
type: number;
|
||||
};
|
||||
|
||||
type RowSearchValue = {
|
||||
propertyId: string;
|
||||
textValue: string | null;
|
||||
numberValue: { toString(): string } | number | string | null;
|
||||
dateValue: Date | string | null;
|
||||
booleanValue: boolean | null;
|
||||
property: RowSearchProperty;
|
||||
};
|
||||
|
||||
type SearchRow = {
|
||||
id: string;
|
||||
tenantId: string | null;
|
||||
entityId: string;
|
||||
folio: number;
|
||||
tenantId: string;
|
||||
kontaktTyp: string;
|
||||
vorname: string | null;
|
||||
nachname: string | null;
|
||||
orgName: string | null;
|
||||
primaerEmail: string | null;
|
||||
kontaktStatus: string;
|
||||
zustaendigerUserId: string | null;
|
||||
createdByUserId: string | null;
|
||||
createdAt: Date | string;
|
||||
updatedAt: Date | string;
|
||||
deletedAt: Date | string | null;
|
||||
entity: {
|
||||
name: string;
|
||||
properties: RowSearchProperty[];
|
||||
};
|
||||
values: RowSearchValue[];
|
||||
};
|
||||
|
||||
const TENANT_USER_STATUS_ACTIVE = 2;
|
||||
@@ -68,6 +52,26 @@ type TenantUserSearchRow = {
|
||||
};
|
||||
};
|
||||
|
||||
type ProjektSearchRow = {
|
||||
id: string;
|
||||
tenantId: string;
|
||||
projektNummer: string;
|
||||
projektname: string;
|
||||
beschreibung: string | null;
|
||||
projekttyp: string | null;
|
||||
quelle: string | null;
|
||||
pipelineId: string;
|
||||
stageId: string;
|
||||
zustaendigePersonId: string | null;
|
||||
projektleiterId: string | null;
|
||||
archivedAt: Date | string | null;
|
||||
createdAt: Date | string;
|
||||
updatedAt: Date | string;
|
||||
deadline: Date | string | null;
|
||||
potenziellerAuftragswert: unknown;
|
||||
auftragsvolumen: unknown;
|
||||
};
|
||||
|
||||
export type SearchIndexerBulkPagerPrisma = {
|
||||
knowledgeBaseArticle: {
|
||||
findMany(args: {
|
||||
@@ -92,55 +96,30 @@ export type SearchIndexerBulkPagerPrisma = {
|
||||
};
|
||||
}): Promise<KnowledgeBaseArticleRow[]>;
|
||||
};
|
||||
row: {
|
||||
kontakt: {
|
||||
findMany(args: {
|
||||
where: {
|
||||
id?: { gt: string };
|
||||
tenantId: string;
|
||||
deletedAt: null;
|
||||
entity?: { name: string };
|
||||
archivedAt: null;
|
||||
};
|
||||
orderBy: { id: "asc" };
|
||||
take: number;
|
||||
select: {
|
||||
id: true;
|
||||
tenantId: true;
|
||||
entityId: true;
|
||||
folio: true;
|
||||
kontaktTyp: true;
|
||||
vorname: true;
|
||||
nachname: true;
|
||||
orgName: true;
|
||||
primaerEmail: true;
|
||||
kontaktStatus: true;
|
||||
zustaendigerUserId: true;
|
||||
createdByUserId: true;
|
||||
createdAt: true;
|
||||
updatedAt: true;
|
||||
deletedAt: true;
|
||||
entity: {
|
||||
select: {
|
||||
name: true;
|
||||
properties: {
|
||||
select: {
|
||||
id: true;
|
||||
name: true;
|
||||
type: true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
values: {
|
||||
select: {
|
||||
propertyId: true;
|
||||
textValue: true;
|
||||
numberValue: true;
|
||||
dateValue: true;
|
||||
booleanValue: true;
|
||||
property: {
|
||||
select: {
|
||||
id: true;
|
||||
name: true;
|
||||
type: true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}): Promise<SearchRow[]>;
|
||||
}): Promise<KontaktSearchRow[]>;
|
||||
};
|
||||
tenantUser: {
|
||||
findMany(args: {
|
||||
@@ -176,14 +155,44 @@ export type SearchIndexerBulkPagerPrisma = {
|
||||
};
|
||||
}): Promise<TenantUserSearchRow[]>;
|
||||
};
|
||||
projekt: {
|
||||
findMany(args: {
|
||||
where: {
|
||||
id?: { gt: string };
|
||||
tenantId: string;
|
||||
archivedAt: null;
|
||||
};
|
||||
orderBy: { id: "asc" };
|
||||
take: number;
|
||||
select: {
|
||||
id: true;
|
||||
tenantId: true;
|
||||
projektNummer: true;
|
||||
projektname: true;
|
||||
beschreibung: true;
|
||||
projekttyp: true;
|
||||
quelle: true;
|
||||
pipelineId: true;
|
||||
stageId: true;
|
||||
zustaendigePersonId: true;
|
||||
projektleiterId: true;
|
||||
archivedAt: true;
|
||||
createdAt: true;
|
||||
updatedAt: true;
|
||||
deadline: true;
|
||||
potenziellerAuftragswert: true;
|
||||
auftragsvolumen: true;
|
||||
};
|
||||
}): Promise<ProjektSearchRow[]>;
|
||||
};
|
||||
};
|
||||
|
||||
export function createSearchIndexerBulkPagers(input: { prisma: SearchIndexerBulkPagerPrisma }): NonNullable<SearchIndexerDependencies["bulkPagers"]> {
|
||||
return {
|
||||
[kbArticlesIndex.name]: createKbArticlesPager(input.prisma),
|
||||
[crmContactsIndex.name]: createCrmContactsPager(input.prisma),
|
||||
[rowsIndex.name]: createRowsPager(input.prisma),
|
||||
[usersIndex.name]: createUsersPager(input.prisma),
|
||||
[projectsIndex.name]: createProjectsPager(input.prisma),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -237,24 +246,31 @@ function createKbArticlesPager(prisma: SearchIndexerBulkPagerPrisma): SearchInde
|
||||
|
||||
function createCrmContactsPager(prisma: SearchIndexerBulkPagerPrisma): SearchIndexerBulkPager {
|
||||
return async ({ tenantId, cursor, pageSize }) => {
|
||||
const rows = await findSearchRows(prisma, {
|
||||
tenantId,
|
||||
cursor,
|
||||
pageSize,
|
||||
entityName: "contact",
|
||||
const rows = await prisma.kontakt.findMany({
|
||||
where: {
|
||||
...(cursor ? { id: { gt: cursor } } : {}),
|
||||
tenantId,
|
||||
archivedAt: null,
|
||||
},
|
||||
orderBy: { id: "asc" },
|
||||
take: pageSize,
|
||||
select: {
|
||||
id: true,
|
||||
tenantId: true,
|
||||
kontaktTyp: true,
|
||||
vorname: true,
|
||||
nachname: true,
|
||||
orgName: true,
|
||||
primaerEmail: true,
|
||||
kontaktStatus: true,
|
||||
zustaendigerUserId: true,
|
||||
createdByUserId: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
return {
|
||||
documents: rows.filter((row) => row.tenantId === tenantId && row.entity.name === "contact").map((row) => rowToContactDocument(row, tenantId)),
|
||||
nextCursor: rows.length === pageSize ? (rows[rows.length - 1]?.id ?? null) : null,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function createRowsPager(prisma: SearchIndexerBulkPagerPrisma): SearchIndexerBulkPager {
|
||||
return async ({ tenantId, cursor, pageSize }) => {
|
||||
const rows = await findSearchRows(prisma, { tenantId, cursor, pageSize });
|
||||
return {
|
||||
documents: rows.filter((row) => row.tenantId === tenantId).map((row) => rowToRowsDocument(row, tenantId)),
|
||||
documents: rows.filter((row) => row.tenantId === tenantId).map((row) => kontaktToContactDocument(row, tenantId)),
|
||||
nextCursor: rows.length === pageSize ? (rows[rows.length - 1]?.id ?? null) : null,
|
||||
};
|
||||
};
|
||||
@@ -301,58 +317,41 @@ function createUsersPager(prisma: SearchIndexerBulkPagerPrisma): SearchIndexerBu
|
||||
};
|
||||
}
|
||||
|
||||
function findSearchRows(
|
||||
prisma: SearchIndexerBulkPagerPrisma,
|
||||
input: { tenantId: string; cursor: string | null; pageSize: number; entityName?: string }
|
||||
) {
|
||||
return prisma.row.findMany({
|
||||
where: {
|
||||
...(input.cursor ? { id: { gt: input.cursor } } : {}),
|
||||
tenantId: input.tenantId,
|
||||
deletedAt: null,
|
||||
...(input.entityName ? { entity: { name: input.entityName } } : {}),
|
||||
},
|
||||
orderBy: { id: "asc" },
|
||||
take: input.pageSize,
|
||||
select: {
|
||||
id: true,
|
||||
tenantId: true,
|
||||
entityId: true,
|
||||
folio: true,
|
||||
createdByUserId: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
deletedAt: true,
|
||||
entity: {
|
||||
select: {
|
||||
name: true,
|
||||
properties: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
type: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
function createProjectsPager(prisma: SearchIndexerBulkPagerPrisma): SearchIndexerBulkPager {
|
||||
return async ({ tenantId, cursor, pageSize }) => {
|
||||
const rows = await prisma.projekt.findMany({
|
||||
where: {
|
||||
...(cursor ? { id: { gt: cursor } } : {}),
|
||||
tenantId,
|
||||
archivedAt: null,
|
||||
},
|
||||
values: {
|
||||
select: {
|
||||
propertyId: true,
|
||||
textValue: true,
|
||||
numberValue: true,
|
||||
dateValue: true,
|
||||
booleanValue: true,
|
||||
property: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
type: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { id: "asc" },
|
||||
take: pageSize,
|
||||
select: {
|
||||
id: true,
|
||||
tenantId: true,
|
||||
projektNummer: true,
|
||||
projektname: true,
|
||||
beschreibung: true,
|
||||
projekttyp: true,
|
||||
quelle: true,
|
||||
pipelineId: true,
|
||||
stageId: true,
|
||||
zustaendigePersonId: true,
|
||||
projektleiterId: true,
|
||||
archivedAt: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
deadline: true,
|
||||
potenziellerAuftragswert: true,
|
||||
auftragsvolumen: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
return {
|
||||
documents: rows.filter((row) => row.tenantId === tenantId).map((row) => projektToProjectDocument(row, tenantId)),
|
||||
nextCursor: rows.length === pageSize ? (rows[rows.length - 1]?.id ?? null) : null,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function tenantUserToUserDocument(row: TenantUserSearchRow, tenantId: string): Record<string, unknown> & { id: string; tenantId: string } {
|
||||
@@ -370,57 +369,55 @@ function tenantUserToUserDocument(row: TenantUserSearchRow, tenantId: string): R
|
||||
};
|
||||
}
|
||||
|
||||
function rowToContactDocument(row: SearchRow, tenantId: string): Record<string, unknown> & { id: string; tenantId: string } {
|
||||
function kontaktToContactDocument(row: KontaktSearchRow, tenantId: string): Record<string, unknown> & { id: string; tenantId: string } {
|
||||
// Project the typed Kontakt columns onto the `crm-contacts` Meilisearch document
|
||||
// keys (German column → English document field), mirroring indexedEntities.
|
||||
return {
|
||||
id: row.id,
|
||||
tenantId,
|
||||
firstName: getTextValue(row, "firstName"),
|
||||
lastName: getTextValue(row, "lastName"),
|
||||
email: getTextValue(row, "email"),
|
||||
company: getTextValue(row, "company"),
|
||||
jobTitle: getTextValue(row, "jobTitle"),
|
||||
status: getTextValue(row, "status"),
|
||||
ownerId: row.createdByUserId ?? "",
|
||||
entityType: row.kontaktTyp === "organisation" ? "company" : "contact",
|
||||
firstName: row.vorname ?? "",
|
||||
lastName: row.nachname ?? "",
|
||||
email: row.primaerEmail ?? "",
|
||||
company: row.orgName ?? "",
|
||||
jobTitle: "",
|
||||
status: row.kontaktStatus,
|
||||
ownerId: row.zustaendigerUserId ?? row.createdByUserId ?? "",
|
||||
createdAt: serializeDate(row.createdAt),
|
||||
updatedAt: serializeDate(row.updatedAt),
|
||||
};
|
||||
}
|
||||
|
||||
function rowToRowsDocument(row: SearchRow, tenantId: string): Record<string, unknown> & { id: string; tenantId: string } {
|
||||
function projektToProjectDocument(row: ProjektSearchRow, tenantId: string): Record<string, unknown> & { id: string; tenantId: string } {
|
||||
return {
|
||||
id: row.id,
|
||||
tenantId,
|
||||
entityId: row.entityId,
|
||||
entityName: row.entity.name,
|
||||
folio: typeof row.folio === "number" ? row.folio : 0,
|
||||
searchable: buildSearchableBlob(row),
|
||||
createdById: row.createdByUserId ?? "",
|
||||
projectNumber: row.projektNummer,
|
||||
name: row.projektname,
|
||||
description: row.beschreibung ?? "",
|
||||
type: row.projekttyp ?? "",
|
||||
source: row.quelle ?? "",
|
||||
pipelineId: row.pipelineId,
|
||||
stageId: row.stageId,
|
||||
ownerId: row.zustaendigePersonId ?? "",
|
||||
projectLeadId: row.projektleiterId ?? "",
|
||||
archived: row.archivedAt !== null,
|
||||
createdAt: serializeDate(row.createdAt),
|
||||
updatedAt: serializeDate(row.updatedAt),
|
||||
deadline: serializeDate(row.deadline),
|
||||
potentialValue: serializeDecimal(row.potenziellerAuftragswert),
|
||||
orderVolume: serializeDecimal(row.auftragsvolumen),
|
||||
};
|
||||
}
|
||||
|
||||
function buildSearchableBlob(row: SearchRow): string {
|
||||
return row.entity.properties
|
||||
.filter((property) => SEARCHABLE_ROW_PROPERTY_TYPES.has(property.type))
|
||||
.map((property) => getTextValue(row, property.name))
|
||||
.filter((value) => value.length > 0)
|
||||
.join(" \n ");
|
||||
}
|
||||
|
||||
function getTextValue(row: SearchRow, propertyName: string): string {
|
||||
const property = row.entity.properties.find((item) => item.name === propertyName);
|
||||
const value = property ? row.values.find((item) => item.propertyId === property.id) : undefined;
|
||||
return normalizeRowValue(value).trim();
|
||||
}
|
||||
|
||||
function normalizeRowValue(value: RowSearchValue | undefined): string {
|
||||
if (!value) return "";
|
||||
if (value.textValue !== null) return value.textValue;
|
||||
if (value.numberValue !== null) return value.numberValue.toString();
|
||||
if (value.dateValue !== null) return serializeDate(value.dateValue) ?? "";
|
||||
if (value.booleanValue !== null) return String(value.booleanValue);
|
||||
return "";
|
||||
function serializeDecimal(value: unknown): number | null {
|
||||
if (value === null || value === undefined) return null;
|
||||
if (typeof value === "number") return value;
|
||||
if (typeof value === "string") return Number(value);
|
||||
if (typeof value === "object" && "toString" in value && typeof value.toString === "function") {
|
||||
return Number(value.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function serializeDate(value: Date | string | null): string | null {
|
||||
|
||||
Reference in new issue
Block a user