check if already cox on planned events

This commit is contained in:
philipp 2023-04-06 18:48:18 +02:00
parent 9a41614922
commit 194577f9bd

View File

@ -14,6 +14,7 @@ impl UserTrip {
return Err(UserTripError::EventAlreadyFull); return Err(UserTripError::EventAlreadyFull);
} }
//check if cox if own event
let is_cox = sqlx::query!( let is_cox = sqlx::query!(
"SELECT count(*) as amount "SELECT count(*) as amount
FROM trip FROM trip
@ -29,6 +30,24 @@ impl UserTrip {
return Err(UserTripError::AlreadyRegisteredAsCox); return Err(UserTripError::AlreadyRegisteredAsCox);
} }
//check if cox if planned_event
let is_cox = sqlx::query!(
"SELECT count(*) as amount
FROM trip
WHERE planned_event_id = (
SELECT id FROM planned_event WHERE trip_details_id = ?
)
AND cox_id = ?",
trip_details_id,
user_id
)
.fetch_one(db)
.await
.unwrap();
if is_cox.amount > 0 {
return Err(UserTripError::AlreadyRegisteredAsCox);
}
match sqlx::query!( match sqlx::query!(
"INSERT INTO user_trip (user_id, trip_details_id) VALUES(?, ?)", "INSERT INTO user_trip (user_id, trip_details_id) VALUES(?, ?)",
user_id, user_id,