Skip to content

Commit

Permalink
fix: do not include deleted projects in findAllActiveDocumentsWithAgr…
Browse files Browse the repository at this point in the history
…eggatedData
  • Loading branch information
geclos committed Sep 21, 2024
1 parent 29c1a90 commit 71d1811
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/core/src/repositories/projectsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,25 @@ describe('ProjectsRepository', async () => {

expect(projects).toHaveLength(1)
})

it('should not include deleted projects', async () => {
const { project: deletedProject } = await createProject({
workspace,
deletedAt: new Date(),
})

const { project: activeProject } = await createProject({
workspace,
})

const result = await repository.findAllActiveDocumentsWithAgreggatedData()

expect(result.ok).toBe(true)
const projects = result.unwrap()

expect(projects).toHaveLength(1)
expect(projects[0]?.id).toBe(activeProject.id)
expect(projects.find((p) => p.id === deletedProject.id)).toBeUndefined()
})
})
})
1 change: 1 addition & 0 deletions packages/core/src/repositories/projectsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class ProjectsRepository extends Repository<typeof tt, Project> {
})
.from(this.scope)
.leftJoin(aggredatedData, eq(aggredatedData.id, this.scope.id))
.where(isNull(this.scope.deletedAt))

return Result.ok(result)
}
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/tests/factories/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DocumentVersion, Providers, User, Workspace } from '../../browser'
import { unsafelyGetUser } from '../../data-access'
import { mergeCommit } from '../../services/commits'
import { createNewDocument, updateDocument } from '../../services/documents'
import { destroyProject, updateProject } from '../../services/projects'

Check failure on line 7 in packages/core/src/tests/factories/projects.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

'destroyProject' is defined but never used. Allowed unused vars must match /^_/u
import { createProject as createProjectFn } from '../../services/projects/create'
import { createApiKey } from './apiKeys'
import { createDraft } from './commits'
Expand Down Expand Up @@ -40,6 +41,7 @@ export async function flattenDocumentStructure({

export type ICreateProject = {
name?: string
deletedAt?: Date
workspace?: Workspace | ICreateWorkspace
providers?: { type: Providers; name: string }[]
evaluations?: Omit<IEvaluationData, 'workspace'>[]
Expand Down Expand Up @@ -74,6 +76,11 @@ export async function createProject(projectData: Partial<ICreateProject> = {}) {
})
let { project, commit } = result.unwrap()

if (projectData.deletedAt)
await updateProject(project, { deletedAt: projectData.deletedAt }).then(
(r) => r.unwrap(),
)

const providersToCreate =
projectData.providers == undefined
? [{ type: Providers.OpenAI, name: faker.internet.domainName() }]
Expand Down

0 comments on commit 71d1811

Please sign in to comment.