fix: keep imported follow-ups out of current work

They stayed on the board when a non-prior deal was attached, even though the person was prior.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-15 12:34:40 +03:30
co-authored by Cursor
parent 6bc5e1bec7
commit 6bff9d2888
9 changed files with 102 additions and 16 deletions
+43 -5
View File
@@ -25,6 +25,39 @@ function liveActivity(now: Date): Prisma.ActivityWhereInput {
};
}
/** فعالیت باز با موعد آینده، حتی اگر قبلی باشد، در کار جاری می‌ماند. */
function stillOpenAhead(now: Date): Prisma.ActivityWhereInput {
return { status: 'open', dueAt: { gt: now } };
}
/**
* فعالیت قبلی است اگر منبعش didar باشد،
* یا قبل از روشن شدن ماژول ساخته شده و به شخص/شرکت/معاملهٔ قبلی وصل باشد.
* معاملهٔ غیرقبلی مانع نمی‌شود؛ شخص قبلی (حتی اگر بعداً منبعش عوض شده) کافی است.
*/
function historicalActivity(cutoff: Date): Prisma.ActivityWhereInput {
return {
OR: [
{ importSource: PRIOR_IMPORT_SOURCE },
{
createdAt: { lt: cutoff },
OR: [
{
person: {
OR: [
{ importSource: PRIOR_IMPORT_SOURCE },
{ previousImportSource: PRIOR_IMPORT_SOURCE },
],
},
},
{ company: { importSource: PRIOR_IMPORT_SOURCE } },
{ deal: { importSource: PRIOR_IMPORT_SOURCE } },
],
},
],
};
}
export function personPriorWhere(lens: PriorLens | undefined): Prisma.PersonWhereInput {
if (lens === 'archive') return { importSource: PRIOR_IMPORT_SOURCE };
if (lens === 'current') return { importSource: { not: PRIOR_IMPORT_SOURCE } };
@@ -50,14 +83,19 @@ export function dealPriorWhere(lens: PriorLens | undefined, now = new Date()): P
export function activityPriorWhere(
lens: PriorLens | undefined,
now = new Date(),
cutoff?: Date | null,
): Prisma.ActivityWhereInput {
if (lens === 'current') {
return { OR: [{ importSource: { not: PRIOR_IMPORT_SOURCE } }, liveActivity(now)] };
}
if (lens === 'archive') {
if (lens !== 'current' && lens !== 'archive') return {};
if (!cutoff) {
if (lens === 'current') {
return { OR: [{ importSource: { not: PRIOR_IMPORT_SOURCE } }, liveActivity(now)] };
}
return { importSource: PRIOR_IMPORT_SOURCE, NOT: liveActivity(now) };
}
return {};
const prior = historicalActivity(cutoff);
const live = stillOpenAhead(now);
if (lens === 'current') return { OR: [{ NOT: prior }, live] };
return { AND: [prior, { NOT: live }] };
}
/** فهرست شخص/شرکت: در کار جاری، جستجو و فیلتر صریح منبع، قبلی‌ها را هم پیدا می‌کند. */