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:
@@ -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 }] };
|
||||
}
|
||||
|
||||
/** فهرست شخص/شرکت: در کار جاری، جستجو و فیلتر صریح منبع، قبلیها را هم پیدا میکند. */
|
||||
|
||||
@@ -22,6 +22,8 @@ export type Actor = {
|
||||
scopes?: Partial<Record<DataScope, ScopeVisibility>>;
|
||||
/** off = فیلتر خاموش؛ current = کار جاری؛ archive = بایگانی اطلاعات قبل */
|
||||
priorLens?: 'off' | 'current' | 'archive';
|
||||
/** لحظهٔ روشن شدن ماژول برای این محیط؛ فعالیتهای ساختهشده قبل از آن میتوانند قبلی باشند */
|
||||
priorCutoff?: Date | null;
|
||||
};
|
||||
|
||||
export type ScopedActor = Pick<Actor, 'userId' | 'role' | 'dataVisibility' | 'visibleUserIds' | 'scopes'>;
|
||||
|
||||
Reference in New Issue
Block a user