forked from Ruderverein-Donau-Linz/rowt
		
	check if already cox on planned events
This commit is contained in:
		@@ -14,6 +14,7 @@ impl UserTrip {
 | 
			
		||||
            return Err(UserTripError::EventAlreadyFull);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //check if cox if own event
 | 
			
		||||
        let is_cox = sqlx::query!(
 | 
			
		||||
            "SELECT count(*) as amount
 | 
			
		||||
            FROM trip 
 | 
			
		||||
@@ -29,6 +30,24 @@ impl UserTrip {
 | 
			
		||||
            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!(
 | 
			
		||||
            "INSERT INTO user_trip (user_id, trip_details_id) VALUES(?, ?)",
 | 
			
		||||
            user_id,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user