Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Dec 12, 2024
1 parent a985d02 commit 206b496
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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: {
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function computeDocumentLogsWithMetadataQuery(
.limit(parseInt(pageSize))
.offset(offset)

console.log("SQL", foo.toSQL())
/* console.log("SQL", foo.toSQL()) */
return foo
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 206b496

Please sign in to comment.