Skip to content

Commit

Permalink
FIX sample
Browse files Browse the repository at this point in the history
  • Loading branch information
juliecoust committed Nov 14, 2024
1 parent fef1c2f commit 01051ba
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/data/data-sources/sqlite/sqlite-sample-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -530,7 +530,6 @@ export class SQLiteSampleDataSource implements SampleDataSource {
// Update One Sample
// Returns the number of lines updates
async updateOne(sample: PrivateSampleUpdateModel): Promise<number> {
console.log("######TODO: updateOne sample#######")
const { sample_id, ...sampleData } = sample; // Destructure the sample object
const params: any[] = []
let placeholders: string = ""
Expand Down
1 change: 1 addition & 0 deletions src/domain/interfaces/repositories/project-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ProjectRequestCreationModel, ProjectRequestModel, ProjectUpdateModel, P
import { PreparedSearchOptions, SearchResult } from "../../entities/search";

export interface ProjectRepository {
createProjectRootFolder(root_folder_path: string): Promise<void>;
formatProjectRequestCreationModel(public_project: PublicProjectRequestCreationModel, instrument: InstrumentModelResponseModel): ProjectRequestCreationModel;
toPublicProject(project: ProjectResponseModel, privileges: PublicPrivilege): PublicProjectResponseModel;
standardUpdateProject(project_to_update: ProjectUpdateModel): Promise<number>;
Expand Down
16 changes: 14 additions & 2 deletions src/domain/repositories/project-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -181,6 +183,16 @@ export class ProjectRepositoryImpl implements ProjectRepository {

return publicProject;
}


async createProjectRootFolder(root_folder_path: string): Promise<void> {
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 });
}
}
2 changes: 1 addition & 1 deletion src/domain/repositories/sample-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 16 additions & 2 deletions src/domain/use-cases/project/create-project.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<PublicProjectResponseModel> {
Expand All @@ -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);

Expand Down Expand Up @@ -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);

}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 01051ba

Please sign in to comment.