delete cancelled trips if all rowers have seen the notification
All checks were successful
CI/CD Pipeline / test (push) Successful in 11m21s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2024-09-03 17:39:08 +03:00
parent 76022a1f0e
commit a441d99b5e
4 changed files with 145 additions and 31 deletions

View File

@ -5,7 +5,7 @@ use regex::Regex;
use serde::{Deserialize, Serialize};
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
use super::{role::Role, user::User};
use super::{role::Role, user::User, usertrip::UserTrip};
#[derive(FromRow, Debug, Serialize, Deserialize, Clone)]
pub struct Notification {
@ -140,15 +140,13 @@ ORDER BY read_at DESC, created_at DESC;
let re = Regex::new(r"^remove_user_trip_with_trip_details_id:(\d+)$").unwrap();
if let Some(caps) = re.captures(action) {
if let Some(matched) = caps.get(1) {
if let Ok(number) = matched.as_str().parse::<i32>() {
let _ = sqlx::query!(
"DELETE FROM user_trip WHERE user_id = ? AND trip_details_id = ?",
self.user_id,
number
)
.execute(db)
.await
.unwrap();
if let Ok(number) = matched.as_str().parse::<i64>() {
if let Some(usertrip) =
UserTrip::find_by_userid_and_trip_detail_id(db, self.user_id, number)
.await
{
let _ = usertrip.self_delete(db).await;
}
}
}
}