From 246e007dea3bc887c0d8c9e8a85339813945dca6 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Thu, 30 May 2024 16:43:14 -0400 Subject: [PATCH] fix: Load document by client. --- src/models/browser.rs | 20 ++++++++++++++++---- src/models/process.rs | 18 +++++++++++++++--- src/models/window.rs | 18 +++++++++++++++--- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/models/browser.rs b/src/models/browser.rs index e04425b..d612db6 100644 --- a/src/models/browser.rs +++ b/src/models/browser.rs @@ -3,7 +3,9 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}}; +use crate::controller::opensearch::{IndexDocument, get_by_id, find, exists_index}; + +use super::{client_index, user_index, role_index}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -317,8 +319,9 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id); let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id); + let _client_index = client_index(_index.to_owned(), _language, _client_id); - // Find index + // Find index match exists_index(_user_index.to_owned()).await { Ok(_) => { log::info!("Find with user index `{:}`", _user_index); @@ -332,8 +335,17 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, Ok(_role_index) }, Err(error) => { - log::error!("No role index `{:}`", _role_index); - return Err(Error::new(ErrorKind::InvalidData.into(), error)) + log::warn!("No role index `{:}`", _role_index); + match exists_index(_client_index.to_owned()).await { + Ok(_) => { + log::info!("Find with client index `{:}`", _client_index); + Ok(_client_index) + }, + Err(_) => { + log::error!("No client index `{:}`", _client_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) + } + } } } } diff --git a/src/models/process.rs b/src/models/process.rs index 9d5aea3..8b6fbbf 100644 --- a/src/models/process.rs +++ b/src/models/process.rs @@ -3,7 +3,9 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}}; +use crate::controller::opensearch::{IndexDocument, get_by_id, find, exists_index}; + +use super::{client_index, user_index, role_index}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -285,6 +287,7 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id); let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id); + let _client_index = client_index(_index.to_owned(), _language, _client_id); // Find index match exists_index(_user_index.to_owned()).await { @@ -300,8 +303,17 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, Ok(_role_index) }, Err(error) => { - log::error!("No role index `{:}`", _role_index); - return Err(Error::new(ErrorKind::InvalidData.into(), error)) + log::warn!("No role index `{:}`", _role_index); + match exists_index(_client_index.to_owned()).await { + Ok(_) => { + log::info!("Find with client index `{:}`", _client_index); + Ok(_client_index) + }, + Err(_) => { + log::error!("No client index `{:}`", _client_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) + } + } } } } diff --git a/src/models/window.rs b/src/models/window.rs index 08e37e1..4520685 100644 --- a/src/models/window.rs +++ b/src/models/window.rs @@ -3,7 +3,9 @@ use salvo::prelude::*; use serde_json::json; use std::{io::ErrorKind, io::Error}; -use crate::{controller::opensearch::{IndexDocument, get_by_id, find, exists_index}, models::{user_index, role_index}}; +use crate::controller::opensearch::{IndexDocument, get_by_id, find, exists_index}; + +use super::{client_index, user_index, role_index}; #[derive(Deserialize, Extractible, Debug, Clone)] #[salvo(extract(default_source(from = "body")))] @@ -325,6 +327,7 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, let _user_index = user_index(_index.to_owned(), _language, _client_id, _role_id, _user_id); let _role_index = role_index(_index.to_owned(), _language, _client_id, _role_id); + let _client_index = client_index(_index.to_owned(), _language, _client_id); // Find index match exists_index(_user_index.to_owned()).await { @@ -340,8 +343,17 @@ async fn get_index_name(_language: Option<&String>, _client_id: Option<&String>, Ok(_role_index) }, Err(error) => { - log::error!("No role index `{:}`", _role_index); - return Err(Error::new(ErrorKind::InvalidData.into(), error)) + log::warn!("No role index `{:}`", _role_index); + match exists_index(_client_index.to_owned()).await { + Ok(_) => { + log::info!("Find with client index `{:}`", _client_index); + Ok(_client_index) + }, + Err(_) => { + log::error!("No client index `{:}`", _client_index); + return Err(Error::new(ErrorKind::InvalidData.into(), error)) + } + } } } }