Unified search algorithm across all lists; per-section record visibility (contacts, deals, activities, leads, finance, tickets, notes, projects)

This commit is contained in:
2026-10-06 15:04:46 +03:30
parent 43717392b2
commit e08f1452ef
38 changed files with 699 additions and 420 deletions
+11 -19
View File
@@ -20,6 +20,7 @@ import { OrgRolesService } from '../org-roles/org-roles.service';
import { PipelinesService } from '../pipelines/pipelines.service';
import { BillingService } from '../billing/billing.service';
import { PrismaService } from '../prisma/prisma.service';
import { buildSearchWhere, ci } from '../common/search';
import type {
ApplyBillingPlanDto,
CreatePlatformAdminDto,
@@ -81,16 +82,11 @@ export class PlatformService {
}
async listOrganizations(query?: string): Promise<PlatformOrganizationDto[]> {
const q = query?.trim();
const rows = await this.prisma.organization.findMany({
where: q
? {
OR: [
{ name: { contains: q, mode: 'insensitive' } },
{ slug: { contains: q, mode: 'insensitive' } },
],
}
: undefined,
where: buildSearchWhere<Prisma.OrganizationWhereInput>(query, (t) => [
{ name: ci(t) },
{ slug: ci(t) },
]),
orderBy: { createdAt: 'desc' },
select: {
id: true,
@@ -340,18 +336,14 @@ export class PlatformService {
}
async listUsers(query?: string, ownersOnly = false): Promise<PlatformUserDto[]> {
const q = query?.trim();
const search = buildSearchWhere<Prisma.UserWhereInput>(query, (t) => [
{ fullName: ci(t) },
{ email: ci(t) },
{ mobile: { contains: t } },
]);
const rows = await this.prisma.user.findMany({
where: {
...(q
? {
OR: [
{ fullName: { contains: q, mode: 'insensitive' } },
{ email: { contains: q, mode: 'insensitive' } },
{ mobile: { contains: q } },
],
}
: {}),
...(search ? { AND: [search] } : {}),
...(ownersOnly
? { memberships: { some: { role: 'owner', isActive: true } } }
: {}),