From 59460afcdba53cc90015ca591471e8f28600e5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sans=C3=B3n?= Date: Fri, 20 Sep 2024 17:01:23 +0200 Subject: [PATCH] Fix: Default project --- packages/core/src/repositories/projectsRepository.ts | 2 +- packages/core/src/services/projects/create.ts | 6 +++--- packages/core/src/services/projects/import.ts | 12 +----------- packages/core/src/tests/factories/createProject.ts | 5 +---- packages/core/src/tests/factories/projects.ts | 5 +---- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/packages/core/src/repositories/projectsRepository.ts b/packages/core/src/repositories/projectsRepository.ts index 4fc68b99f..9bf7081a8 100644 --- a/packages/core/src/repositories/projectsRepository.ts +++ b/packages/core/src/repositories/projectsRepository.ts @@ -100,7 +100,7 @@ export class ProjectsRepository extends Repository { 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) } diff --git a/packages/core/src/services/projects/create.ts b/packages/core/src/services/projects/create.ts index 6369c726d..f8f262073 100644 --- a/packages/core/src/services/projects/create.ts +++ b/packages/core/src/services/projects/create.ts @@ -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' @@ -18,7 +18,7 @@ export async function createProject( }, db = database, ) { - return Transaction.call(async (tx) => { + return Transaction.call<{ project: Project; commit: Commit }>(async (tx) => { const project = ( await tx .insert(projects) @@ -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) } diff --git a/packages/core/src/services/projects/import.ts b/packages/core/src/services/projects/import.ts index 286f77883..ba1663687 100644 --- a/packages/core/src/services/projects/import.ts +++ b/packages/core/src/services/projects/import.ts @@ -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' @@ -39,7 +37,7 @@ export async function importDefaultProject( if (defaultDocuments.error) return defaultDocuments return Transaction.call(async (tx) => { - const project = await createProject( + const { project, commit } = await createProject( { workspace, user, @@ -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( @@ -68,7 +59,6 @@ export async function importDefaultProject( }), ) - await mergeCommit(commit, tx).then((r) => r.unwrap()) return Result.ok(project) }, db) } diff --git a/packages/core/src/tests/factories/createProject.ts b/packages/core/src/tests/factories/createProject.ts index a715c919a..5efebf4a4 100644 --- a/packages/core/src/tests/factories/createProject.ts +++ b/packages/core/src/tests/factories/createProject.ts @@ -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' @@ -32,9 +31,7 @@ export async function createProject(projectData: Partial = {}) { 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[] = [] diff --git a/packages/core/src/tests/factories/projects.ts b/packages/core/src/tests/factories/projects.ts index f020d5f3f..e9ad3719e 100644 --- a/packages/core/src/tests/factories/projects.ts +++ b/packages/core/src/tests/factories/projects.ts @@ -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' @@ -68,9 +67,7 @@ export async function createProject(projectData: Partial = {}) { 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