Skip to content

Commit

Permalink
Merge pull request #2098 from openmsupply/1955-omSupply-Cold-Chain-Te…
Browse files Browse the repository at this point in the history
…mperature-Sensors

1955 om supply cold chain temperature sensors
  • Loading branch information
adrianwb authored Aug 21, 2023
2 parents f4cfc3c + 918882b commit eb67b96
Show file tree
Hide file tree
Showing 45 changed files with 2,530 additions and 7 deletions.
1 change: 1 addition & 0 deletions server/graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ graphql_programs = { path = "programs" }
graphql_types = { path = "types" }
graphql_general = { path = "general" }
graphql_location = { path = "location" }
graphql_sensor = { path = "sensor" }
graphql_reports = { path = "reports" }
graphql_invoice = { path = "invoice" }
graphql_invoice_line = { path = "invoice_line" }
Expand Down
2 changes: 2 additions & 0 deletions server/graphql/core/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod program_enrolment;
mod requisition;
mod requisition_line;
mod requisition_supply_status;
mod sensor;
mod stock_line;
mod stocktake_lines;
mod store;
Expand Down Expand Up @@ -45,6 +46,7 @@ pub use program_enrolment::*;
pub use requisition::*;
pub use requisition_line::*;
pub use requisition_supply_status::*;
pub use sensor::*;
pub use stock_line::*;
pub use stocktake_lines::*;
pub use store::*;
Expand Down
32 changes: 32 additions & 0 deletions server/graphql/core/src/loader/sensor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use repository::EqualFilter;
use repository::{
sensor::{Sensor, SensorFilter, SensorRepository},
RepositoryError, StorageConnectionManager,
};

use async_graphql::dataloader::*;
use async_graphql::*;
use std::collections::HashMap;

pub struct SensorByIdLoader {
pub connection_manager: StorageConnectionManager,
}

#[async_trait::async_trait]
impl Loader<String> for SensorByIdLoader {
type Value = Sensor;
type Error = RepositoryError;

async fn load(&self, ids: &[String]) -> Result<HashMap<String, Self::Value>, Self::Error> {
let connection = self.connection_manager.connection()?;
let repo = SensorRepository::new(&connection);

let result =
repo.query_by_filter(SensorFilter::new().id(EqualFilter::equal_any(ids.to_owned())))?;

Ok(result
.into_iter()
.map(|sensor| (sensor.sensor_row.id.clone(), sensor))
.collect())
}
}
1 change: 1 addition & 0 deletions server/graphql/core/src/simple_generic_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl InvoiceLineBelongsToAnotherInvoice {
#[graphql(rename_items = "camelCase")]
pub enum UniqueValueKey {
Code,
Serial,
}

pub struct UniqueValueViolation(pub UniqueValueKey);
Expand Down
7 changes: 6 additions & 1 deletion server/graphql/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ use graphql_general::{
use graphql_invoice::{InvoiceMutations, InvoiceQueries};
use graphql_invoice_line::InvoiceLineMutations;
use graphql_location::{LocationMutations, LocationQueries};
use graphql_repack::{RepackMutations, RepackQueries};
use graphql_programs::{ProgramsMutations, ProgramsQueries};
use graphql_repack::{RepackMutations, RepackQueries};
use graphql_reports::ReportQueries;
use graphql_requisition::{RequisitionMutations, RequisitionQueries};
use graphql_requisition_line::RequisitionLineMutations;
use graphql_sensor::{SensorMutations, SensorQueries};
use graphql_stock_line::{StockLineMutations, StockLineQueries};
use graphql_stocktake::{StocktakeMutations, StocktakeQueries};
use graphql_stocktake_line::StocktakeLineMutations;
Expand All @@ -48,6 +49,7 @@ pub type InitialisationSchema = async_graphql::Schema<
pub struct Queries(
pub InvoiceQueries,
pub LocationQueries,
pub SensorQueries,
pub StocktakeQueries,
pub GeneralQueries,
pub RequisitionQueries,
Expand All @@ -64,6 +66,7 @@ impl Queries {
Queries(
InvoiceQueries,
LocationQueries,
SensorQueries,
StocktakeQueries,
GeneralQueries,
RequisitionQueries,
Expand All @@ -82,6 +85,7 @@ pub struct Mutations(
pub InvoiceMutations,
pub InvoiceLineMutations,
pub LocationMutations,
pub SensorMutations,
pub StocktakeMutations,
pub StocktakeLineMutations,
pub BatchMutations,
Expand All @@ -100,6 +104,7 @@ impl Mutations {
InvoiceMutations,
InvoiceLineMutations,
LocationMutations,
SensorMutations,
StocktakeMutations,
StocktakeLineMutations,
BatchMutations,
Expand Down
36 changes: 36 additions & 0 deletions server/graphql/sensor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "graphql_sensor"
version = "0.1.0"
edition = "2018"

[lib]
path = "src/lib.rs"
doctest = false

[dependencies]

repository = { path = "../../repository" }
service = { path = "../../service" }
util = { path = "../../util" }
graphql_core = { path = "../core" }
graphql_types = { path = "../types" }

actix-web = { workspace = true }
anymap= { workspace = true }
async-graphql = { workspace = true }
async-graphql-actix-web = { workspace = true }
async-trait = { workspace = true }
chrono = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
actix-rt = { workspace = true }
assert-json-diff = { workspace = true }

[features]
default = ["sqlite"]
sqlite = ["repository/sqlite"]
postgres = ["repository/postgres"]
Loading

0 comments on commit eb67b96

Please sign in to comment.