diff options
Diffstat (limited to 'src/jobs/weekly_report.rs')
-rw-r--r-- | src/jobs/weekly_report.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/jobs/weekly_report.rs b/src/jobs/weekly_report.rs index 0c10143..5058c52 100644 --- a/src/jobs/weekly_report.rs +++ b/src/jobs/weekly_report.rs @@ -1,6 +1,5 @@ use sqlx::sqlite::SqlitePool; use std::collections::HashMap; -use tera::{Context, Tera}; use crate::db; use crate::mail; @@ -10,9 +9,9 @@ use crate::payer; pub async fn send( config: &Config, pool: &SqlitePool, - templates: &Tera, + env: &minijinja::Environment<'_>, ) -> bool { - match get_weekly_report(pool, templates).await { + match get_weekly_report(pool, env).await { Ok(report) => { let users = db::users::list(pool).await; mail::send( @@ -30,7 +29,10 @@ pub async fn send( .await } Err(err) => { - log::error!("Error preparing weekly report from template: {:?}", err); + log::error!( + "Error preparing weekly report from template: {:?}", + err + ); false } } @@ -38,8 +40,8 @@ pub async fn send( async fn get_weekly_report( pool: &SqlitePool, - templates: &Tera, -) -> Result<String, tera::Error> { + env: &minijinja::Environment<'_>, +) -> Result<String, minijinja::Error> { let users = db::users::list(pool).await; let incomes_from = db::incomes::defined_for_all(pool).await; let user_incomes = match incomes_from { @@ -53,10 +55,11 @@ async fn get_weekly_report( let last_week_payments = db::payments::last_week(pool).await; let last_week_incomes = db::incomes::last_week(pool).await; - let mut context = Context::new(); - context.insert("exceeding_payers", &exceeding_payers); - context.insert("payments", &last_week_payments); - context.insert("incomes", &last_week_incomes); - - templates.render("report/report.j2", &context) + let template = env.get_template("report/report.j2")?; + template.render(minijinja::context!( + name => "John", + exceeding_payers => exceeding_payers, + payments => last_week_payments, + incomes => last_week_incomes + )) } |