From 4139ee83fd608fd20e6c6edc286970978afc828e Mon Sep 17 00:00:00 2001 From: German Martinez Date: Mon, 16 Dec 2024 14:22:47 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor(CoI):=20adding=20man?= =?UTF-8?q?ually=20linked=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ribution-to-indicator-result.repository.ts | 62 +++++++++++++------ .../contribution-to-indicators.repository.ts | 29 ++++++++- 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicator-result.repository.ts b/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicator-result.repository.ts index 373181c94..8a928a59c 100644 --- a/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicator-result.repository.ts +++ b/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicator-result.repository.ts @@ -74,28 +74,52 @@ export class ContributionToIndicatorResultsRepository extends Repository { const dataQuery = ` select main_ctir.id as contribution_id, main_ctir.is_active, main_r.id as result_id, main_r.result_code, main_r.title, - main_v.phase_name, main_v.id as version_id, main_rt.name as result_type, main_ci.official_code as result_submitter, - main_rs.status_name, date_format(main_r.created_date, '%Y-%m-%d') as created_date - from ${env.DB_TOC}.toc_results_indicators tri - right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id - right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id - right join ${env.DB_NAME}.results_toc_result rtr on rtr.toc_result_id = outcomes.id and rtr.is_active - left join ${env.DB_NAME}.contribution_to_indicators cti on - convert(cti.toc_result_id using utf8mb4) = convert(tri.toc_result_indicator_id using utf8mb4) and cti.is_active - left join ${env.DB_NAME}.result main_r on main_r.id = rtr.results_id and main_r.is_active - left join ${env.DB_NAME}.contribution_to_indicator_results main_ctir on main_ctir.result_id = main_r.id - and main_ctir.contribution_to_indicator_id = cti.id - left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id - left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id - left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id - and main_rbi.initiative_role_id = 1 and rtr.initiative_id = main_rbi.inititiative_id - left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id - left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id - where tri.toc_result_indicator_id = ? and tri.is_active and main_r.id is not null + main_v.phase_name, main_v.id as version_id, main_rt.name as result_type, main_ci.official_code as result_submitter, + main_rs.status_name, date_format(main_r.created_date, '%Y-%m-%d') as created_date, true as is_manually_mapped + from ${env.DB_TOC}.toc_results_indicators tri + right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id + right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id + right join ${env.DB_NAME}.results_toc_result rtr on rtr.toc_result_id = outcomes.id and rtr.is_active + left join ${env.DB_NAME}.contribution_to_indicators cti on + convert(cti.toc_result_id using utf8mb4) = convert(tri.toc_result_indicator_id using utf8mb4) and cti.is_active + left join ${env.DB_NAME}.result main_r on main_r.id = rtr.results_id and main_r.is_active + left join ${env.DB_NAME}.contribution_to_indicator_results main_ctir on main_ctir.result_id = main_r.id + and main_ctir.contribution_to_indicator_id = cti.id + left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id + left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id + left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id + and main_rbi.initiative_role_id = 1 and rtr.initiative_id = main_rbi.inititiative_id + left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id + left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id + where tri.toc_result_indicator_id = ? and tri.is_active and main_r.id is not null + union all + select main_ctir.id as contribution_id, main_ctir.is_active, main_r.id as result_id, main_r.result_code, main_r.title, + main_v.phase_name, main_v.id as version_id, main_rt.name as result_type, main_ci.official_code as result_submitter, + main_rs.status_name, date_format(main_r.created_date, '%Y-%m-%d') as created_date, false as is_manually_mapped + from ${env.DB_NAME}.contribution_to_indicator_results main_ctir + left join ${env.DB_NAME}.contribution_to_indicators cti on main_ctir.contribution_to_indicator_id = cti.id and cti.is_active + left join ${env.DB_NAME}.result main_r on main_r.id = main_ctir.result_id and main_r.is_active + left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id + left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id + left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id + and main_rbi.initiative_role_id = 1 + left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id + left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id + where cti.toc_result_id = ? and main_ctir.result_id not in ( + select rtr.results_id + from ${env.DB_NAME}.results_toc_result rtr + where rtr.is_active and rtr.toc_result_id in ( + select outcomes.id + from ${env.DB_TOC}.toc_results_indicators tri + right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id + right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id + where convert(cti.toc_result_id using utf8mb4) = convert(tri.toc_result_indicator_id using utf8mb4) and tri.is_active + ) + ) `; return this.dataSource - .query(dataQuery, [tocId]) + .query(dataQuery, [tocId, tocId]) .then((result) => result) .catch((err) => { throw this._handlersError.returnErrorRepository({ diff --git a/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicators.repository.ts b/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicators.repository.ts index 93be88a5b..484144548 100644 --- a/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicators.repository.ts +++ b/onecgiar-pr-server/src/api/contribution-to-indicators/repositories/contribution-to-indicators.repository.ts @@ -128,12 +128,13 @@ export class ContributionToIndicatorsRepository extends Repository