Fix prior archive filter collisions

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-17 17:49:51 +03:30
co-authored by Cursor
parent e86841fc60
commit bc68582fe2
6 changed files with 76 additions and 39 deletions
+1 -1
View File
@@ -12,7 +12,7 @@
"prisma:seed": "tsx prisma/seed.ts",
"lint": "echo \"api lint placeholder\"",
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p test/tsconfig.json",
"test": "tsx --test test/tahesab-methods.test.ts test/dates.test.ts test/birthdays.test.ts test/message-automation.test.ts test/record-scope.test.ts test/gamification-engine.test.ts test/automation-branches.test.ts test/pipeline-merge.test.ts test/ask-count.test.ts test/prior-archive.test.ts test/organizations.test.ts"
"test": "tsx --test test/tahesab-methods.test.ts test/dates.test.ts test/birthdays.test.ts test/message-automation.test.ts test/record-scope.test.ts test/gamification-engine.test.ts test/automation-branches.test.ts test/pipeline-merge.test.ts test/ask-count.test.ts test/prior-archive.test.ts test/organizations.test.ts test/promote-from-prior.test.ts"
},
"dependencies": {
"@mento/shared": "*",
+8 -4
View File
@@ -399,10 +399,14 @@ Rules:
activity: () =>
this.prisma.activity.count({
where: {
organizationId: orgId,
...assigneeWhere(actor),
...created,
...activityPriorWhere(actor.priorLens, actor.priorCutoff),
AND: [
{
organizationId: orgId,
...created,
},
assigneeWhere(actor),
activityPriorWhere(actor.priorLens, actor.priorCutoff),
],
},
}),
ticket: () =>
-1
View File
@@ -10,7 +10,6 @@ import {
import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcryptjs';
import type {} from 'multer';
import * as path from 'path';
import type {
AuthUserDto,
@@ -113,8 +113,10 @@ export class DealsExcelService {
this.prisma.deal.findMany({
where: {
organizationId: actor.organizationId,
...dealAccessWhere(actor),
...dealPriorWhere(actor.priorLens, actor.priorCutoff),
AND: [
dealAccessWhere(actor),
dealPriorWhere(actor.priorLens, actor.priorCutoff),
],
},
include: {
person: {
+4 -2
View File
@@ -328,8 +328,10 @@ export class PipelinesService {
where: {
organizationId,
pipelineId: resolved.id,
...(actor ? dealAccessWhere(actor) : {}),
...(includePrior ? {} : dealPriorWhere(actor?.priorLens, actor?.priorCutoff)),
AND: [
...(actor ? [dealAccessWhere(actor)] : []),
...(includePrior ? [] : [dealPriorWhere(actor?.priorLens, actor?.priorCutoff)]),
],
},
include: {
person: { select: { id: true, firstName: true, lastName: true } },
+59 -29
View File
@@ -127,10 +127,14 @@ export class ReportsService {
}),
this.prisma.activity.findMany({
where: {
organizationId: orgId,
...activityScope,
...activitiesPrior,
createdAt: { gte: prevStart, lte: end },
AND: [
{
organizationId: orgId,
createdAt: { gte: prevStart, lte: end },
},
activityScope,
activitiesPrior,
],
},
select: {
id: true,
@@ -1565,11 +1569,15 @@ export class ReportsService {
] = await Promise.all([
this.prisma.deal.findMany({
where: {
organizationId: orgId,
status: 'won',
...dealScope,
...dealsPrior,
updatedAt: { gte: addMonthsStart(now, -5) },
AND: [
{
organizationId: orgId,
status: 'won',
updatedAt: { gte: addMonthsStart(now, -5) },
},
dealScope,
dealsPrior,
],
},
select: {
amount: true,
@@ -1583,7 +1591,13 @@ export class ReportsService {
},
}),
this.prisma.deal.count({
where: { organizationId: orgId, status: 'open', ...dealScope, ...dealsPrior },
where: {
AND: [
{ organizationId: orgId, status: 'open' },
dealScope,
dealsPrior,
],
},
}),
this.prisma.deal.findMany({
where: {
@@ -1626,28 +1640,40 @@ export class ReportsService {
}),
this.prisma.activity.count({
where: {
organizationId: orgId,
...activityScope,
...activitiesPrior,
status: 'open',
dueAt: { gte: todayStart, lte: todayEnd },
AND: [
{
organizationId: orgId,
status: 'open',
dueAt: { gte: todayStart, lte: todayEnd },
},
activityScope,
activitiesPrior,
],
},
}),
this.prisma.activity.count({
where: {
organizationId: orgId,
...activityScope,
...activitiesPrior,
dueAt: { gte: yesterdayStart, lte: yesterdayEnd },
AND: [
{
organizationId: orgId,
dueAt: { gte: yesterdayStart, lte: yesterdayEnd },
},
activityScope,
activitiesPrior,
],
},
}),
this.prisma.deal.count({
where: {
organizationId: orgId,
status: 'open',
...dealScope,
...dealsPrior,
updatedAt: { lte: weekAgo },
AND: [
{
organizationId: orgId,
status: 'open',
updatedAt: { lte: weekAgo },
},
dealScope,
dealsPrior,
],
},
}),
this.prisma.salesGoal.findMany({
@@ -1660,11 +1686,15 @@ export class ReportsService {
}),
this.prisma.activity.count({
where: {
organizationId: orgId,
...activityScope,
...activitiesPrior,
status: 'open',
dueAt: { lt: now },
AND: [
{
organizationId: orgId,
status: 'open',
dueAt: { lt: now },
},
activityScope,
activitiesPrior,
],
},
}),
]);