@open-mercato/core 0.10.1-develop.7888.1.96c8c2bd5f → 0.10.1-develop.7900.1.69c0120c72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/modules/audit_logs/api/audit-logs/actions/route.js +12 -26
- package/dist/modules/audit_logs/api/audit-logs/actions/route.js.map +2 -2
- package/dist/modules/audit_logs/services/actionLogService.js +10 -4
- package/dist/modules/audit_logs/services/actionLogService.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/page.js +5 -2
- package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js +9 -6
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js.map +2 -2
- package/dist/modules/customers/components/detail/CompanyKpiBar.js +3 -2
- package/dist/modules/customers/components/detail/CompanyKpiBar.js.map +2 -2
- package/dist/modules/customers/lib/duplicateDeal.js +10 -1
- package/dist/modules/customers/lib/duplicateDeal.js.map +2 -2
- package/dist/modules/query_index/lib/coverage.js +36 -19
- package/dist/modules/query_index/lib/coverage.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/audit_logs/api/audit-logs/actions/route.ts +18 -28
- package/src/modules/audit_logs/services/actionLogService.ts +20 -18
- package/src/modules/business_rules/i18n/es.json +1 -1
- package/src/modules/customers/backend/customers/deals/page.tsx +4 -2
- package/src/modules/customers/backend/customers/deals/pipeline/page.tsx +8 -6
- package/src/modules/customers/components/detail/CompanyKpiBar.tsx +2 -1
- package/src/modules/customers/i18n/de.json +6 -0
- package/src/modules/customers/i18n/en.json +6 -0
- package/src/modules/customers/i18n/es.json +6 -0
- package/src/modules/customers/i18n/ko.json +6 -0
- package/src/modules/customers/i18n/pl.json +6 -0
- package/src/modules/customers/lib/duplicateDeal.ts +9 -0
- package/src/modules/query_index/lib/coverage.ts +54 -31
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { raw, type FilterQuery } from '@mikro-orm/core'
|
|
2
2
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
3
3
|
import { sql } from 'kysely'
|
|
4
|
+
import { z } from 'zod'
|
|
4
5
|
import { ActionLog } from '@open-mercato/core/modules/audit_logs/data/entities'
|
|
5
6
|
import {
|
|
6
7
|
actionLogCreateSchema,
|
|
@@ -30,6 +31,15 @@ import {
|
|
|
30
31
|
|
|
31
32
|
const logger = createLogger('audit_logs').child({ component: 'action-log-service' })
|
|
32
33
|
|
|
34
|
+
const DEFAULT_LIST_PAGE_SIZE = 50
|
|
35
|
+
|
|
36
|
+
const actionLogListQuerySchema = actionLogListSchema.extend({
|
|
37
|
+
page: z.number().int().positive().optional(),
|
|
38
|
+
pageSize: z.number().int().positive().max(200).optional(),
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
type ParsedActionLogListQuery = z.infer<typeof actionLogListQuerySchema>
|
|
42
|
+
|
|
33
43
|
let validationWarningLogged = false
|
|
34
44
|
let runtimeValidationAvailable: boolean | null = null
|
|
35
45
|
let decryptionWarningLogged = false
|
|
@@ -409,26 +419,26 @@ export class ActionLogService {
|
|
|
409
419
|
}
|
|
410
420
|
|
|
411
421
|
private parseListQuery(query: Partial<ActionLogListQuery>) {
|
|
412
|
-
return
|
|
422
|
+
return actionLogListQuerySchema.parse({
|
|
413
423
|
...query,
|
|
414
424
|
})
|
|
415
425
|
}
|
|
416
426
|
|
|
417
|
-
private resolveActorUserIds(parsed:
|
|
427
|
+
private resolveActorUserIds(parsed: ParsedActionLogListQuery): string[] {
|
|
418
428
|
const values = [...(parsed.actorUserIds ?? [])]
|
|
419
429
|
if (parsed.actorUserId) values.push(parsed.actorUserId)
|
|
420
430
|
|
|
421
431
|
return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean)))
|
|
422
432
|
}
|
|
423
433
|
|
|
424
|
-
private resolveFieldNames(parsed:
|
|
434
|
+
private resolveFieldNames(parsed: ParsedActionLogListQuery): string[] {
|
|
425
435
|
const values = [...(parsed.fieldNames ?? [])]
|
|
426
436
|
if (parsed.fieldName) values.push(parsed.fieldName)
|
|
427
437
|
|
|
428
438
|
return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean)))
|
|
429
439
|
}
|
|
430
440
|
|
|
431
|
-
private resolveActionTypes(parsed:
|
|
441
|
+
private resolveActionTypes(parsed: ParsedActionLogListQuery): ActionLogFilterType[] {
|
|
432
442
|
const values = [...(parsed.actionTypes ?? [])]
|
|
433
443
|
if (parsed.actionType) values.push(parsed.actionType)
|
|
434
444
|
|
|
@@ -436,22 +446,14 @@ export class ActionLogService {
|
|
|
436
446
|
.filter((value): value is ActionLogFilterType => ACTION_LOG_FILTER_TYPES.includes(value as ActionLogFilterType))
|
|
437
447
|
}
|
|
438
448
|
|
|
439
|
-
private resolvePagination(parsed:
|
|
440
|
-
const pageSize =
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
: typeof parsed.limit === 'number' && parsed.limit > 0
|
|
444
|
-
? parsed.limit
|
|
445
|
-
: 50
|
|
446
|
-
const page = typeof parsed.page === 'number' && parsed.page > 0 ? parsed.page : 1
|
|
447
|
-
const offset =
|
|
448
|
-
typeof parsed.offset === 'number' && parsed.offset >= 0
|
|
449
|
-
? parsed.offset
|
|
450
|
-
: (page - 1) * pageSize
|
|
449
|
+
private resolvePagination(parsed: ParsedActionLogListQuery): { page: number; pageSize: number; offset: number; limit: number } {
|
|
450
|
+
const pageSize = parsed.pageSize ?? parsed.limit ?? DEFAULT_LIST_PAGE_SIZE
|
|
451
|
+
const page = parsed.page ?? 1
|
|
452
|
+
const offset = parsed.offset ?? (page - 1) * pageSize
|
|
451
453
|
return { page, pageSize, offset, limit: pageSize }
|
|
452
454
|
}
|
|
453
455
|
|
|
454
|
-
private async loadEntries(parsed:
|
|
456
|
+
private async loadEntries(parsed: ParsedActionLogListQuery, options?: { paginate?: boolean }) {
|
|
455
457
|
let query = (this.buildListQuery(parsed) as any).select('action_logs.id as id')
|
|
456
458
|
|
|
457
459
|
if (options?.paginate !== false) {
|
|
@@ -480,7 +482,7 @@ export class ActionLogService {
|
|
|
480
482
|
))
|
|
481
483
|
}
|
|
482
484
|
|
|
483
|
-
private buildListQuery(parsed:
|
|
485
|
+
private buildListQuery(parsed: ParsedActionLogListQuery): any {
|
|
484
486
|
let query = (this.em.getKysely<any>() as any)
|
|
485
487
|
.selectFrom('action_logs')
|
|
486
488
|
.selectAll()
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"business_rules.components.actionRow.config.endpoint.placeholder": "Seleccione endpoint",
|
|
38
38
|
"business_rules.components.actionRow.config.field.placeholder": "Ingrese {{field}}",
|
|
39
39
|
"business_rules.components.actionRow.config.level": "nivel",
|
|
40
|
-
"business_rules.components.actionRow.config.level.debug": "
|
|
40
|
+
"business_rules.components.actionRow.config.level.debug": "Depuración",
|
|
41
41
|
"business_rules.components.actionRow.config.level.error": "Error",
|
|
42
42
|
"business_rules.components.actionRow.config.level.info": "Info",
|
|
43
43
|
"business_rules.components.actionRow.config.level.warn": "Advertencia",
|
|
@@ -76,7 +76,7 @@ import { UserCircle2 } from 'lucide-react'
|
|
|
76
76
|
import { ReassignOwnerDialog } from './components/ReassignOwnerDialog'
|
|
77
77
|
import type { BulkActionExecuteResult } from '@open-mercato/ui/backend/DataTable'
|
|
78
78
|
import { requestBulkOwnerReassignment, buildReassignOwnerSuccess } from '../../../lib/reassignDealOwner'
|
|
79
|
-
import { buildDealDuplicatePayload } from '../../../lib/duplicateDeal'
|
|
79
|
+
import { buildDealDuplicatePayload, formatDealDuplicateTitle } from '../../../lib/duplicateDeal'
|
|
80
80
|
|
|
81
81
|
const logger = createLogger('customers')
|
|
82
82
|
|
|
@@ -563,7 +563,9 @@ export default function CustomersDealsPage() {
|
|
|
563
563
|
if (pendingDuplicateId) return
|
|
564
564
|
const payload = buildDealDuplicatePayload(
|
|
565
565
|
row,
|
|
566
|
-
|
|
566
|
+
formatDealDuplicateTitle(row.title, (title) =>
|
|
567
|
+
t('customers.deals.list.duplicateTitle', '{title} (copy)', { title }),
|
|
568
|
+
),
|
|
567
569
|
)
|
|
568
570
|
setPendingDuplicateId(row.id)
|
|
569
571
|
try {
|
|
@@ -58,7 +58,7 @@ import type { FilterOptionTone } from '@open-mercato/shared/lib/query/advanced-f
|
|
|
58
58
|
import { ViewTabsRow, VIEW_TABS_ROW_COMPONENT_ID, type ViewTabsRowProps } from './components/ViewTabsRow'
|
|
59
59
|
import { LANE_WIDTH_CLASS } from './components/constants'
|
|
60
60
|
import { useCurrencyDictionary } from '../../../../components/detail/hooks/useCurrencyDictionary'
|
|
61
|
-
import { buildDealDuplicatePayload } from '../../../../lib/duplicateDeal'
|
|
61
|
+
import { buildDealDuplicatePayload, formatDealDuplicateTitle } from '../../../../lib/duplicateDeal'
|
|
62
62
|
import { FilterBarRow, type KanbanFilterChip } from './components/FilterBarRow'
|
|
63
63
|
import { Lane, type LaneStage } from './components/Lane'
|
|
64
64
|
import { LaneCurrencyBreakdown } from './components/LaneCurrencyBreakdown'
|
|
@@ -2270,11 +2270,13 @@ export default function DealsKanbanPage(): React.ReactElement {
|
|
|
2270
2270
|
expectedCloseAt: deal.expectedCloseAt,
|
|
2271
2271
|
ownerUserId: deal.owner?.userId,
|
|
2272
2272
|
},
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2273
|
+
formatDealDuplicateTitle(deal.title, (title) =>
|
|
2274
|
+
translateWithFallback(
|
|
2275
|
+
t,
|
|
2276
|
+
'customers.deals.kanban.menu.duplicate.titleSuffix',
|
|
2277
|
+
'{title} (copy)',
|
|
2278
|
+
{ title },
|
|
2279
|
+
),
|
|
2278
2280
|
),
|
|
2279
2281
|
)
|
|
2280
2282
|
|
|
@@ -167,13 +167,14 @@ export function CompanyKpiBar({ data }: CompanyKpiBarProps) {
|
|
|
167
167
|
<div className="space-y-2">
|
|
168
168
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
|
169
169
|
{visibleTiles.map((tile) => (
|
|
170
|
-
<div key={tile.id} className="group relative">
|
|
170
|
+
<div key={tile.id} data-testid="company-kpi-tile" className="group relative flex">
|
|
171
171
|
<KpiCard
|
|
172
172
|
title={tile.title}
|
|
173
173
|
value={tile.value}
|
|
174
174
|
trend={tile.trend}
|
|
175
175
|
formatValue={tile.formatValue}
|
|
176
176
|
comparisonLabel={tile.comparisonLabel}
|
|
177
|
+
className="w-full"
|
|
177
178
|
/>
|
|
178
179
|
<IconButton
|
|
179
180
|
type="button"
|
|
@@ -2833,6 +2833,12 @@
|
|
|
2833
2833
|
"customers.schedule.dueDate": "Fälligkeitsdatum",
|
|
2834
2834
|
"customers.schedule.dueTime": "Due time",
|
|
2835
2835
|
"customers.schedule.duration": "Duration",
|
|
2836
|
+
"customers.schedule.duration.option.15min": "15 Min.",
|
|
2837
|
+
"customers.schedule.duration.option.1h30m": "1 Std. 30 Min.",
|
|
2838
|
+
"customers.schedule.duration.option.1hour": "1 Stunde",
|
|
2839
|
+
"customers.schedule.duration.option.2hours": "2 Stunden",
|
|
2840
|
+
"customers.schedule.duration.option.30min": "30 Min.",
|
|
2841
|
+
"customers.schedule.duration.option.45min": "45 Min.",
|
|
2836
2842
|
"customers.schedule.editTitle": "Aktivität bearbeiten",
|
|
2837
2843
|
"customers.schedule.email.save": "E-Mail senden",
|
|
2838
2844
|
"customers.schedule.email.subtitle": "Verfassen und senden Sie eine getrackte E-Mail",
|
|
@@ -2833,6 +2833,12 @@
|
|
|
2833
2833
|
"customers.schedule.dueDate": "Due date",
|
|
2834
2834
|
"customers.schedule.dueTime": "Due time",
|
|
2835
2835
|
"customers.schedule.duration": "Duration",
|
|
2836
|
+
"customers.schedule.duration.option.15min": "15 min",
|
|
2837
|
+
"customers.schedule.duration.option.1h30m": "1h 30m",
|
|
2838
|
+
"customers.schedule.duration.option.1hour": "1 hour",
|
|
2839
|
+
"customers.schedule.duration.option.2hours": "2 hours",
|
|
2840
|
+
"customers.schedule.duration.option.30min": "30 min",
|
|
2841
|
+
"customers.schedule.duration.option.45min": "45 min",
|
|
2836
2842
|
"customers.schedule.editTitle": "Edit activity",
|
|
2837
2843
|
"customers.schedule.email.save": "Send email",
|
|
2838
2844
|
"customers.schedule.email.subtitle": "Compose and send a tracked email",
|
|
@@ -2833,6 +2833,12 @@
|
|
|
2833
2833
|
"customers.schedule.dueDate": "Fecha límite",
|
|
2834
2834
|
"customers.schedule.dueTime": "Due time",
|
|
2835
2835
|
"customers.schedule.duration": "Duration",
|
|
2836
|
+
"customers.schedule.duration.option.15min": "15 min",
|
|
2837
|
+
"customers.schedule.duration.option.1h30m": "1 h 30 min",
|
|
2838
|
+
"customers.schedule.duration.option.1hour": "1 hora",
|
|
2839
|
+
"customers.schedule.duration.option.2hours": "2 horas",
|
|
2840
|
+
"customers.schedule.duration.option.30min": "30 min",
|
|
2841
|
+
"customers.schedule.duration.option.45min": "45 min",
|
|
2836
2842
|
"customers.schedule.editTitle": "Editar actividad",
|
|
2837
2843
|
"customers.schedule.email.save": "Enviar correo",
|
|
2838
2844
|
"customers.schedule.email.subtitle": "Redacta y envía un correo con seguimiento",
|
|
@@ -2833,6 +2833,12 @@
|
|
|
2833
2833
|
"customers.schedule.dueDate": "기한 날짜",
|
|
2834
2834
|
"customers.schedule.dueTime": "기한 시간",
|
|
2835
2835
|
"customers.schedule.duration": "소요 시간",
|
|
2836
|
+
"customers.schedule.duration.option.15min": "15분",
|
|
2837
|
+
"customers.schedule.duration.option.1h30m": "1시간 30분",
|
|
2838
|
+
"customers.schedule.duration.option.1hour": "1시간",
|
|
2839
|
+
"customers.schedule.duration.option.2hours": "2시간",
|
|
2840
|
+
"customers.schedule.duration.option.30min": "30분",
|
|
2841
|
+
"customers.schedule.duration.option.45min": "45분",
|
|
2836
2842
|
"customers.schedule.editTitle": "활동 편집",
|
|
2837
2843
|
"customers.schedule.email.save": "이메일 보내기",
|
|
2838
2844
|
"customers.schedule.email.subtitle": "추적 가능한 이메일을 작성하여 보내세요",
|
|
@@ -2833,6 +2833,12 @@
|
|
|
2833
2833
|
"customers.schedule.dueDate": "Termin",
|
|
2834
2834
|
"customers.schedule.dueTime": "Godzina",
|
|
2835
2835
|
"customers.schedule.duration": "Czas trwania",
|
|
2836
|
+
"customers.schedule.duration.option.15min": "15 min",
|
|
2837
|
+
"customers.schedule.duration.option.1h30m": "1 godz. 30 min",
|
|
2838
|
+
"customers.schedule.duration.option.1hour": "1 godzina",
|
|
2839
|
+
"customers.schedule.duration.option.2hours": "2 godziny",
|
|
2840
|
+
"customers.schedule.duration.option.30min": "30 min",
|
|
2841
|
+
"customers.schedule.duration.option.45min": "45 min",
|
|
2836
2842
|
"customers.schedule.editTitle": "Edytuj aktywność",
|
|
2837
2843
|
"customers.schedule.email.save": "Wyślij e-mail",
|
|
2838
2844
|
"customers.schedule.email.subtitle": "Napisz i wyślij śledzony e-mail",
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
export function formatDealDuplicateTitle(title: string, formatTitle: (title: string) => string): string {
|
|
2
|
+
const formatted = formatTitle(title)
|
|
3
|
+
const excess = formatted.length - 200
|
|
4
|
+
if (excess <= 0) return formatted
|
|
5
|
+
let shortened = title.slice(0, Math.max(0, title.length - excess)).trimEnd()
|
|
6
|
+
if (/[\uD800-\uDBFF]$/.test(shortened)) shortened = shortened.slice(0, -1)
|
|
7
|
+
return formatTitle(shortened)
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
export type DealDuplicateSource = {
|
|
2
11
|
pipelineId?: string | null
|
|
3
12
|
pipelineStageId?: string | null
|
|
@@ -191,7 +191,8 @@ async function updateCoverageRows(
|
|
|
191
191
|
// overlapping adjustments compose, and drops the `SELECT` (and the window between it and the
|
|
192
192
|
// write) that made the coverage row a contention point in the first place.
|
|
193
193
|
//
|
|
194
|
-
//
|
|
194
|
+
// For non-null tenants, steady state is one statement. NULL-tenant writers first take
|
|
195
|
+
// the scope advisory lock because the unique constraint cannot coordinate their rows. The extra statements are recovery paths that do not
|
|
195
196
|
// fire once a scope has settled: the legacy NULL-organization fold below runs only for
|
|
196
197
|
// global-organization scopes, the insert only until the scope's row exists, and the duplicate
|
|
197
198
|
// prune only when the scope somehow holds more than one row.
|
|
@@ -209,6 +210,7 @@ async function incrementCoverageRow(
|
|
|
209
210
|
scope: CoverageScope,
|
|
210
211
|
deltas: { deltaBase: number; deltaIndex: number; deltaVector: number }
|
|
211
212
|
): Promise<void> {
|
|
213
|
+
if (scope.tenantId == null) await lockCoverageInitialization(db, scope)
|
|
212
214
|
const storedOrgId = normalizeOrganizationForStore(scope.organizationId ?? null)
|
|
213
215
|
let deltaBase = deltas.deltaBase
|
|
214
216
|
let deltaIndex = deltas.deltaIndex
|
|
@@ -237,15 +239,7 @@ async function incrementCoverageRow(
|
|
|
237
239
|
}
|
|
238
240
|
}
|
|
239
241
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (updated.length === 0 && scope.tenantId == null) {
|
|
243
|
-
// The unique constraint cannot serialize a first insert whose tenant is NULL. Take a
|
|
244
|
-
// transaction-scoped lock only on this rowless branch, then repeat the UPDATE: a creator
|
|
245
|
-
// that won while we waited has committed its row, so this adjustment composes into it.
|
|
246
|
-
await lockCoverageInitialization(db, scope)
|
|
247
|
-
updated = await updateCoverageRows(db, scope, { deltaBase, deltaIndex, deltaVector })
|
|
248
|
-
}
|
|
242
|
+
const updated = await updateCoverageRows(db, scope, { deltaBase, deltaIndex, deltaVector })
|
|
249
243
|
|
|
250
244
|
if (updated.length > 0) {
|
|
251
245
|
// In steady state the scope holds exactly the row just incremented, so the adjustment is
|
|
@@ -257,7 +251,7 @@ async function incrementCoverageRow(
|
|
|
257
251
|
}
|
|
258
252
|
|
|
259
253
|
// No row for this scope yet. `ON CONFLICT` closes the insert race for scopes the unique
|
|
260
|
-
// constraint can see. NULL-tenant
|
|
254
|
+
// constraint can see. NULL-tenant writes reach here only while holding the scoped
|
|
261
255
|
// transaction advisory lock above, so it has the same single-creator guarantee.
|
|
262
256
|
const rows = await db
|
|
263
257
|
.insertInto('entity_index_coverage' as any)
|
|
@@ -304,6 +298,27 @@ async function upsertCoverageRow(
|
|
|
304
298
|
await purge.execute()
|
|
305
299
|
}
|
|
306
300
|
|
|
301
|
+
if (scope.tenantId == null) {
|
|
302
|
+
const updated = await db
|
|
303
|
+
.updateTable('entity_index_coverage')
|
|
304
|
+
.set({
|
|
305
|
+
base_count: counts.baseCount,
|
|
306
|
+
indexed_count: counts.indexedCount,
|
|
307
|
+
vector_indexed_count: counts.vectorIndexedCount,
|
|
308
|
+
refreshed_at: sql`now()`,
|
|
309
|
+
})
|
|
310
|
+
.where('entity_type', '=', scope.entityType)
|
|
311
|
+
.where('tenant_id', 'is', null)
|
|
312
|
+
.where('organization_id', '=', storedOrgId)
|
|
313
|
+
.where('with_deleted', '=', scope.withDeleted === true)
|
|
314
|
+
.returning('id')
|
|
315
|
+
.execute() as Array<{ id: string }>
|
|
316
|
+
if (updated.length > 0) {
|
|
317
|
+
if (updated.length > 1) await pruneDuplicateCoverageRows(db, scope, updated[0]!.id)
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
307
322
|
const rows = await db
|
|
308
323
|
.insertInto('entity_index_coverage' as any)
|
|
309
324
|
.values({
|
|
@@ -674,26 +689,34 @@ export async function writeCoverageCounts(
|
|
|
674
689
|
const tenantId = scope.tenantId ?? null
|
|
675
690
|
const organizationId = scope.organizationId ?? null
|
|
676
691
|
const withDeleted = scope.withDeleted === true
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
692
|
+
const write = async (executor: CoverageExecutor): Promise<void> => {
|
|
693
|
+
if (tenantId == null) await lockCoverageInitialization(executor, scope)
|
|
694
|
+
const existing = await fetchCoverageRow(executor, {
|
|
695
|
+
entityType,
|
|
696
|
+
tenantId,
|
|
697
|
+
organizationId,
|
|
698
|
+
withDeleted,
|
|
699
|
+
})
|
|
700
|
+
const baseCount = counts.baseCount !== undefined
|
|
701
|
+
? Math.max(0, Math.trunc(toCount(counts.baseCount)))
|
|
702
|
+
: Math.max(0, Math.trunc(toCount(existing?.base_count)))
|
|
703
|
+
const indexCount = counts.indexedCount !== undefined
|
|
704
|
+
? Math.max(0, Math.trunc(toCount(counts.indexedCount)))
|
|
705
|
+
: Math.max(0, Math.trunc(toCount(existing?.indexed_count)))
|
|
706
|
+
const vectorCount = counts.vectorCount !== undefined
|
|
707
|
+
? Math.max(0, Math.trunc(toCount(counts.vectorCount)))
|
|
708
|
+
: Math.max(0, Math.trunc(toCount(existing?.vector_indexed_count)))
|
|
709
|
+
await upsertCoverageRow(executor, { entityType, tenantId, organizationId, withDeleted }, {
|
|
710
|
+
baseCount,
|
|
711
|
+
indexedCount: indexCount,
|
|
712
|
+
vectorIndexedCount: vectorCount,
|
|
713
|
+
})
|
|
714
|
+
}
|
|
715
|
+
if (tenantId == null && !db.isTransaction) {
|
|
716
|
+
await db.transaction().execute(write)
|
|
717
|
+
} else {
|
|
718
|
+
await write(db)
|
|
719
|
+
}
|
|
697
720
|
}
|
|
698
721
|
|
|
699
722
|
type AggregatedAdjustment = {
|