show notification to vorstand if boat entry with 'externes boot' or on multiple days is entered
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
2024-04-15 22:03:20 +02:00
parent 8315a27ea8
commit 219b80377d
4 changed files with 69 additions and 4 deletions

View File

@ -4,7 +4,7 @@ use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
use super::user::User;
use super::{role::Role, user::User};
#[derive(FromRow, Debug, Serialize, Deserialize)]
pub struct Notification {
@ -55,6 +55,20 @@ impl Notification {
tx.commit().await.unwrap();
}
pub async fn create_for_role_tx(
db: &mut Transaction<'_, Sqlite>,
role: &Role,
message: &str,
category: &str,
link: Option<&str>,
) {
let users = User::all_with_role_tx(db, role).await;
for user in users {
Self::create_with_tx(db, &user, message, category, link).await;
}
}
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
sqlx::query_as!(
Self,