Skip to content

Commit

Permalink
Fix: Default project
Browse files Browse the repository at this point in the history
  • Loading branch information
csansoon committed Sep 20, 2024
1 parent 07767df commit 59460af
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/repositories/projectsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class ProjectsRepository extends Repository<typeof tt, Project> {
lastCreatedAtDocument: aggredatedData.lastCreatedAtDocument,
})
.from(this.scope)
.innerJoin(aggredatedData, eq(aggredatedData.id, this.scope.id))
.leftJoin(aggredatedData, eq(aggredatedData.id, this.scope.id))

return Result.ok(result)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/services/projects/create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Project, User, Workspace } from '../../browser'
import { Commit, Project, User, Workspace } from '../../browser'
import { database } from '../../client'
import { Result, Transaction } from '../../lib'
import { projects } from '../../schema'
Expand All @@ -18,7 +18,7 @@ export async function createProject(
},
db = database,
) {
return Transaction.call<Project>(async (tx) => {
return Transaction.call<{ project: Project; commit: Commit }>(async (tx) => {
const project = (
await tx
.insert(projects)
Expand All @@ -38,6 +38,6 @@ export async function createProject(
})
if (result.error) return result

return Result.ok(project)
return Result.ok({ project, commit: result.value })
}, db)
}
12 changes: 1 addition & 11 deletions packages/core/src/services/projects/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { database } from '../../client'
import { NotFoundError, Result, Transaction } from '../../lib'
import { DocumentVersionsRepository } from '../../repositories'
import { projects } from '../../schema'
import { mergeCommit } from '../commits'
import { createCommit } from '../commits/create'
import { createNewDocument } from '../documents'
import { createProject } from './create'

Expand Down Expand Up @@ -39,7 +37,7 @@ export async function importDefaultProject(
if (defaultDocuments.error) return defaultDocuments

return Transaction.call<Project>(async (tx) => {
const project = await createProject(
const { project, commit } = await createProject(
{
workspace,
user,
Expand All @@ -48,13 +46,6 @@ export async function importDefaultProject(
tx,
).then((r) => r.unwrap())

const commit = await createCommit({
project,
user,
data: { title: 'Initial version' },
db: tx,
}).then((r) => r.unwrap())

await Promise.all(
defaultDocuments.value.map(async (document) => {
await createNewDocument(
Expand All @@ -68,7 +59,6 @@ export async function importDefaultProject(
}),
)

await mergeCommit(commit, tx).then((r) => r.unwrap())
return Result.ok(project)
}, db)
}
5 changes: 1 addition & 4 deletions packages/core/src/tests/factories/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { faker } from '@faker-js/faker'

import type { DocumentVersion, User, Workspace } from '../../browser'
import { unsafelyGetUser } from '../../data-access'
import { CommitsRepository } from '../../repositories'
import { mergeCommit } from '../../services/commits'
import { createNewDocument, updateDocument } from '../../services/documents'
import { createProject as createProjectFn } from '../../services/projects'
Expand Down Expand Up @@ -32,9 +31,7 @@ export async function createProject(projectData: Partial<ICreateProject> = {}) {
workspace,
user,
})
const project = result.unwrap()
const commitsScope = new CommitsRepository(workspace.id)
let commit = (await commitsScope.getFirstCommitForProject(project)).unwrap()
let { project, commit } = result.unwrap()

const documents: DocumentVersion[] = []

Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/tests/factories/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { faker } from '@faker-js/faker'

import { DocumentVersion, Providers, User, Workspace } from '../../browser'
import { unsafelyGetUser } from '../../data-access'
import { CommitsRepository } from '../../repositories'
import { mergeCommit } from '../../services/commits'
import { createNewDocument, updateDocument } from '../../services/documents'
import { createProject as createProjectFn } from '../../services/projects/create'
Expand Down Expand Up @@ -68,9 +67,7 @@ export async function createProject(projectData: Partial<ICreateProject> = {}) {
user,
mergedAt: new Date(),
})
const project = result.unwrap()
const commitsScope = new CommitsRepository(workspace.id)
let commit = (await commitsScope.getFirstCommitForProject(project)).unwrap()
let { project, commit } = result.unwrap()

const providersToCreate =
projectData.providers == undefined
Expand Down

0 comments on commit 59460af

Please sign in to comment.