diff --git a/src/data/data-sources/sqlite/sqlite-sample-data-source.ts b/src/data/data-sources/sqlite/sqlite-sample-data-source.ts index 67e7753..7463815 100644 --- a/src/data/data-sources/sqlite/sqlite-sample-data-source.ts +++ b/src/data/data-sources/sqlite/sqlite-sample-data-source.ts @@ -138,8 +138,8 @@ export class SQLiteSampleDataSource implements SampleDataSource { instrument_settings_particle_minimum_size_esd INTEGER, instrument_settings_vignettes_minimum_size_esd INTEGER, instrument_settings_acq_shutter_speed INTEGER, - instrument_settings_acq_shutter_speed INTEGER, instrument_settings_acq_exposure INTEGER, + instrument_settings_acq_shutter INTEGER, visual_qc_validator_user_id INTEGER NOT NULL, visual_qc_status_id INTEGER NOT NULL DEFAULT 1, @@ -530,7 +530,6 @@ export class SQLiteSampleDataSource implements SampleDataSource { // Update One Sample // Returns the number of lines updates async updateOne(sample: PrivateSampleUpdateModel): Promise { - console.log("######TODO: updateOne sample#######") const { sample_id, ...sampleData } = sample; // Destructure the sample object const params: any[] = [] let placeholders: string = "" diff --git a/src/domain/interfaces/repositories/project-repository.ts b/src/domain/interfaces/repositories/project-repository.ts index 54f5182..6a75c3c 100644 --- a/src/domain/interfaces/repositories/project-repository.ts +++ b/src/domain/interfaces/repositories/project-repository.ts @@ -4,6 +4,7 @@ import { ProjectRequestCreationModel, ProjectRequestModel, ProjectUpdateModel, P import { PreparedSearchOptions, SearchResult } from "../../entities/search"; export interface ProjectRepository { + createProjectRootFolder(root_folder_path: string): Promise; formatProjectRequestCreationModel(public_project: PublicProjectRequestCreationModel, instrument: InstrumentModelResponseModel): ProjectRequestCreationModel; toPublicProject(project: ProjectResponseModel, privileges: PublicPrivilege): PublicProjectResponseModel; standardUpdateProject(project_to_update: ProjectUpdateModel): Promise; diff --git a/src/domain/repositories/project-repository.ts b/src/domain/repositories/project-repository.ts index e0fd765..7dec6e2 100644 --- a/src/domain/repositories/project-repository.ts +++ b/src/domain/repositories/project-repository.ts @@ -6,6 +6,8 @@ import { ProjectRequestCreationModel, ProjectRequestModel, ProjectUpdateModel, P import { PreparedSearchOptions, SearchResult } from "../entities/search"; import { ProjectRepository } from "../interfaces/repositories/project-repository"; +import { promises as fs } from 'fs'; + export class ProjectRepositoryImpl implements ProjectRepository { projectDataSource: ProjectDataSource @@ -181,6 +183,16 @@ export class ProjectRepositoryImpl implements ProjectRepository { return publicProject; } - - + async createProjectRootFolder(root_folder_path: string): Promise { + try { + // Check if the folder exists + await fs.access(root_folder_path); + // If it exists, remove it recursively + await fs.rm(root_folder_path, { recursive: true, force: true }); + } catch (error) { + // Folder does not exist; no need to delete anything + } + // Create the root folder + await fs.mkdir(root_folder_path, { recursive: true }); + } } \ No newline at end of file diff --git a/src/domain/repositories/sample-repository.ts b/src/domain/repositories/sample-repository.ts index a97b0d9..40ea085 100644 --- a/src/domain/repositories/sample-repository.ts +++ b/src/domain/repositories/sample-repository.ts @@ -465,7 +465,7 @@ export class SampleRepositoryImpl implements SampleRepository { filename: ini_content.sample_metadata['filename'] as string, filter_first_image: ini_content.sample_metadata['firstimage'] as string, filter_last_image: ini_content.sample_metadata['endimg'] as string, - instrument_settings_acq_gain: ini_content.ACQ_CONF['Gain'] as number, + instrument_settings_acq_gain: ini_content.HW_CONF['Gain'] as number, instrument_settings_acq_description: undefined, instrument_settings_acq_task_type: undefined, instrument_settings_acq_choice: undefined, diff --git a/src/domain/use-cases/project/create-project.ts b/src/domain/use-cases/project/create-project.ts index 040e137..78b7616 100644 --- a/src/domain/use-cases/project/create-project.ts +++ b/src/domain/use-cases/project/create-project.ts @@ -1,3 +1,4 @@ +import path from "path"; import { ProjectRequestCreationModel, PublicProjectRequestCreationModel, PublicProjectResponseModel } from "../../entities/project"; import { UserUpdateModel } from "../../entities/user"; import { InstrumentModelRepository } from "../../interfaces/repositories/instrument_model-repository"; @@ -11,12 +12,14 @@ export class CreateProject implements CreateProjectUseCase { projectRepository: ProjectRepository instrument_modelRepository: InstrumentModelRepository privilegeRepository: PrivilegeRepository + DATA_STORAGE_FS_STORAGE: string - constructor(userRepository: UserRepository, projectRepository: ProjectRepository, instrument_modelRepository: InstrumentModelRepository, privilegeRepository: PrivilegeRepository) { + constructor(userRepository: UserRepository, projectRepository: ProjectRepository, instrument_modelRepository: InstrumentModelRepository, privilegeRepository: PrivilegeRepository, DATA_STORAGE_FS_STORAGE: string) { this.userRepository = userRepository this.projectRepository = projectRepository this.instrument_modelRepository = instrument_modelRepository this.privilegeRepository = privilegeRepository + this.DATA_STORAGE_FS_STORAGE = DATA_STORAGE_FS_STORAGE } async execute(current_user: UserUpdateModel, public_project: PublicProjectRequestCreationModel): Promise { @@ -34,9 +37,12 @@ export class CreateProject implements CreateProjectUseCase { // Format the provided information const project: ProjectRequestCreationModel = this.projectRepository.formatProjectRequestCreationModel(public_project, instrument) - // Create the project and retrieve its ID + // Create the project in the database and retrieve its ID const createdProjectId = await this.projectRepository.createProject(project); + // Create the project root folder + await this.createProjectRootFolder(createdProjectId); + // Retrieve the newly created project information const createdProject = await this.getCreatedProject(createdProjectId); @@ -102,4 +108,12 @@ export class CreateProject implements CreateProjectUseCase { } return privileges; } + + // Create the project root folder + private async createProjectRootFolder(projectId: number) { + const root_folder_path = path.join(this.DATA_STORAGE_FS_STORAGE, `${projectId}`); + // create with fs + await this.projectRepository.createProjectRootFolder(root_folder_path); + + } } diff --git a/src/main.ts b/src/main.ts index 495d9d8..362f2d2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -170,7 +170,7 @@ async function getSQLiteDS() { new MiddlewareAuthCookie(jwtAdapter, config.ACCESS_TOKEN_SECRET, config.REFRESH_TOKEN_SECRET), new MiddlewareProjectValidation(), new MiddlewareSampleValidation(), - new CreateProject(user_repo, project_repo, instrument_model_repo, privilege_repo), + new CreateProject(user_repo, project_repo, instrument_model_repo, privilege_repo, config.DATA_STORAGE_FS_STORAGE), new DeleteProject(user_repo, project_repo, privilege_repo), new UpdateProject(user_repo, project_repo, instrument_model_repo, privilege_repo), new SearchProject(user_repo, project_repo, search_repo, instrument_model_repo, privilege_repo),