Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Dec 13, 2024
1 parent 206b496 commit 48f5c42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ describe('getDocumentLogsWithMetadata', () => {
document: doc2,
commit,
})

const dateThatMatch = new Date('2024-12-10T23:00:01Z')
const { documentLog: anotherWorkspaceLog } =
await factories.createDocumentLog({
document: another.documents[0]!,
Expand All @@ -182,51 +180,32 @@ describe('getDocumentLogsWithMetadata', () => {
new Date('2024-12-10T22:59:59Z'),
log1,
)
const log2Between = await updateLogCreatedAt(dateThatMatch, log3)
const log2Between = await updateLogCreatedAt(
new Date('2024-12-10T23:00:01Z'),
log2,
)
const anotherWorkspacelogBetween = await updateLogCreatedAt(
dateThatMatch,
new Date('2024-12-10T23:00:01Z'),
anotherWorkspaceLog,
)
const log3InAfter = await updateLogCreatedAt(
new Date('2024-12-11T23:00:01Z'),
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)

const createdAt = parseSafeCreatedAtRange(
'2024-12-11T00:00:00+01:00,2024-12-11T23:59:59+01:00',
'2024-12-11T00:00:00 01:00,2024-12-11T23:59:59 01:00',
)
console.log('CREATED_AT', createdAt)

const result = await computeDocumentLogsWithMetadataQuery({
workspaceId: project.workspaceId,
workspaceId: workspace.id,
filterOptions: {
commitIds: [commit.id, commit2.id, another.commit.id],
logSources: LOG_SOURCES,
createdAt,
},
})

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 @@ -40,14 +40,11 @@ export function computeDocumentLogsWithMetadataQuery(
documentUuid ? eq(documentLogs.documentUuid, documentUuid) : undefined,
filterOptions ? buildLogsFilterSQLConditions(filterOptions) : undefined,
].filter(Boolean)
const foo = repo.scope
return repo.scope
.where(and(...conditions))
.orderBy(desc(documentLogs.createdAt))
.limit(parseInt(pageSize))
.offset(offset)

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

export async function computeDocumentLogsWithMetadataCount(
Expand Down

0 comments on commit 48f5c42

Please sign in to comment.