From 206b49601d1e91673ec39d082be3db62a883177b Mon Sep 17 00:00:00 2001 From: andresgutgon Date: Thu, 12 Dec 2024 18:19:09 +0100 Subject: [PATCH] feat: wip --- .../computeDocumentLogsWithMetadata.test.ts | 32 +++++++++++++------ .../computeDocumentLogsWithMetadata.ts | 2 +- .../buildLogsFilterSQLConditions.ts | 5 ++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.test.ts b/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.test.ts index 8e1ca384d..9768d840d 100644 --- a/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.test.ts +++ b/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.test.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it } from 'vitest' -import { eq } from 'drizzle-orm' +import { and, eq, gte, lte, sql } from 'drizzle-orm' import { Commit, @@ -182,10 +182,7 @@ describe('getDocumentLogsWithMetadata', () => { new Date('2024-12-10T22:59:59Z'), log1, ) - const log2Between = await updateLogCreatedAt( - dateThatMatch, - log3, - ) + const log2Between = await updateLogCreatedAt(dateThatMatch, log3) const anotherWorkspacelogBetween = await updateLogCreatedAt( dateThatMatch, anotherWorkspaceLog, @@ -195,15 +192,16 @@ describe('getDocumentLogsWithMetadata', () => { log3, ) + console.log('LOG_BEFORE.id', log1Before.id) console.log('LOG_BETWEEN.createdAt', log2Between.createdAt) - console.log("LOG_BETWEEN.commitId", log2Between.commitId) - console.log("LOG_BETWEEN.source", log2Between.source) - console.log("WORSPACE_ID", project.workspaceId) + console.log('LOG_BETWEEN.commitId', log2Between.commitId) + console.log('LOG_BETWEEN.source', log2Between.source) + console.log('WORSPACE_ID', project.workspaceId) const createdAt = parseSafeCreatedAtRange( '2024-12-11T00:00:00+01:00,2024-12-11T23:59:59+01:00', ) - console.log("CREATED_AT", createdAt) + console.log('CREATED_AT', createdAt) const result = await computeDocumentLogsWithMetadataQuery({ workspaceId: project.workspaceId, filterOptions: { @@ -213,6 +211,22 @@ describe('getDocumentLogsWithMetadata', () => { }, }) + console.log("OTHER_WORKSPACE_LOGS", anotherWorkspacelogBetween.id) + const allLogs = await database.query.documentLogs.findMany({ + where: and( + /* gte(documentLogs.createdAt, new Date('2024-12-10T23:00:00Z')), */ + /* lte(documentLogs.createdAt, new Date('2024-12-11T23:59:59Z')), */ + gte(documentLogs.createdAt, createdAt.from!), + lte(documentLogs.createdAt, createdAt.to!), + ), + }) + + const allLogsCreatedAt = allLogs.map((l) => ({ + id: l.id, + createdAt: l.createdAt, + })) + console.log('ALL_LOGS_CREATED_AT', allLogsCreatedAt) + expect(result.length).toBe(1) expect(result.find((l) => l.uuid === log1Before.uuid)).toBeUndefined() expect(result.find((l) => l.uuid === log2Between.uuid)).toBeDefined() diff --git a/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.ts b/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.ts index 63973ea5f..4ac618557 100644 --- a/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.ts +++ b/packages/core/src/services/documentLogs/computeDocumentLogsWithMetadata.ts @@ -46,7 +46,7 @@ export function computeDocumentLogsWithMetadataQuery( .limit(parseInt(pageSize)) .offset(offset) - console.log("SQL", foo.toSQL()) + /* console.log("SQL", foo.toSQL()) */ return foo } diff --git a/packages/core/src/services/documentLogs/logsFilterUtils/buildLogsFilterSQLConditions.ts b/packages/core/src/services/documentLogs/logsFilterUtils/buildLogsFilterSQLConditions.ts index 62cea6764..4bdeeeef6 100644 --- a/packages/core/src/services/documentLogs/logsFilterUtils/buildLogsFilterSQLConditions.ts +++ b/packages/core/src/services/documentLogs/logsFilterUtils/buildLogsFilterSQLConditions.ts @@ -1,4 +1,4 @@ -import { and, or, sql, inArray, gte, lte } from 'drizzle-orm' +import { and, or, sql, inArray, gte, lte, between } from 'drizzle-orm' import { documentLogs } from '../../../schema' import { DocumentLogFilterOptions } from '../../../constants' import { endOfDay } from 'date-fns' @@ -28,8 +28,7 @@ export function buildLogsFilterSQLConditions({ : sql`1 = 0`, // Return none createdAt ? and( - gte(documentLogs.createdAt, createdAt.from), - lte(documentLogs.createdAt, createdAt.to), + between(documentLogs.createdAt, createdAt.from, createdAt.to), ) : sql`1 = 1`, // Return all if createdAt is not set )