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
+19 -18
View File
@@ -18,6 +18,7 @@ import { AutomationsService } from '../automations/automations.service';
import { MessageAutomationsService } from '../message-automations/message-automations.service';
import { type Actor, assigneeWhere, dealAccessWhere, ownerWhere } from '../common/record-scope';
import { normalizeTags } from '../common/tags';
import { buildSearchWhere, ci } from '../common/search';
type ActivityActor = Pick<Actor, 'userId' | 'role'>;
@@ -427,24 +428,24 @@ export class ActivitiesService {
...(entity?.companyId ? [{ companyId: entity.companyId }] : []),
...(entity?.dealId ? [{ dealId: entity.dealId }] : []),
];
if (q?.trim()) {
const needle = q.trim();
andParts.push({
OR: [
{ title: { contains: needle, mode: 'insensitive' } },
{ description: { contains: needle, mode: 'insensitive' } },
{
person: {
OR: [
{ firstName: { contains: needle, mode: 'insensitive' } },
{ lastName: { contains: needle, mode: 'insensitive' } },
],
},
},
{ deal: { title: { contains: needle, mode: 'insensitive' } } },
],
});
}
const search = buildSearchWhere<Prisma.ActivityWhereInput>(q, (t) => [
{ title: ci(t) },
{ description: ci(t) },
{ tags: { has: t } },
{
person: {
OR: [
{ firstName: ci(t) },
{ lastName: ci(t) },
{ mobile: { contains: t } },
{ phone: { contains: t } },
],
},
},
{ company: { name: ci(t) } },
{ deal: { title: ci(t) } },
]);
if (search) andParts.push(search);
const base: Prisma.ActivityWhereInput = {
organizationId,
AND: andParts,