diff --git a/apps/api/package.json b/apps/api/package.json index f851c23..f50a5af 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -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": "*", diff --git a/apps/api/src/ai/ai-ask.service.ts b/apps/api/src/ai/ai-ask.service.ts index 1c8c834..8cae72a 100644 --- a/apps/api/src/ai/ai-ask.service.ts +++ b/apps/api/src/ai/ai-ask.service.ts @@ -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: () => diff --git a/apps/api/src/auth/auth.service.ts b/apps/api/src/auth/auth.service.ts index c8ab25c..8fb112e 100644 --- a/apps/api/src/auth/auth.service.ts +++ b/apps/api/src/auth/auth.service.ts @@ -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, diff --git a/apps/api/src/pipelines/deals-excel.service.ts b/apps/api/src/pipelines/deals-excel.service.ts index 820f6cc..7fd68b4 100644 --- a/apps/api/src/pipelines/deals-excel.service.ts +++ b/apps/api/src/pipelines/deals-excel.service.ts @@ -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: { diff --git a/apps/api/src/pipelines/pipelines.service.ts b/apps/api/src/pipelines/pipelines.service.ts index 70cfa0f..f5db4d1 100644 --- a/apps/api/src/pipelines/pipelines.service.ts +++ b/apps/api/src/pipelines/pipelines.service.ts @@ -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 } }, diff --git a/apps/api/src/reports/reports.service.ts b/apps/api/src/reports/reports.service.ts index 95dd638..7eed9b4 100644 --- a/apps/api/src/reports/reports.service.ts +++ b/apps/api/src/reports/reports.service.ts @@ -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, + ], }, }), ]);