@@ -43,19 +43,35 @@ impl StatusMutations {
4343 input : CreateStatusBreakInput ,
4444 ) -> Result < StatusBreakRecord > {
4545 let pool = ctx. data :: < Arc < PgPool > > ( ) . expect ( "Pool must be in context" ) ;
46- let status = sqlx:: query_as :: < _ , StatusBreakRecord > (
47- "INSERT INTO StatusBreaks (start_date, end_date, year, reason)
48- VALUES ($1, $2, $3, $4)
46+
47+ match ( & input. year , & input. member_id ) {
48+ ( Some ( _) , Some ( _) ) => {
49+ return Err ( "Cannot specify both year and member_id. A status break must apply to either a year or a member, not both." . into ( ) ) ;
50+ }
51+ ( None , None ) => {
52+ return Err ( "Must specify either year or member_id. A status break must apply to either a year or a member." . into ( ) ) ;
53+ }
54+ _ => { }
55+ }
56+
57+ if input. start_date >= input. end_date {
58+ return Err ( "start_date must be before end_date" . into ( ) ) ;
59+ }
60+
61+ let status_break = sqlx:: query_as :: < _ , StatusBreakRecord > (
62+ "INSERT INTO StatusBreaks (start_date, end_date, year, member_id, reason)
63+ VALUES ($1, $2, $3, $4, $5)
4964 RETURNING *
5065 " ,
5166 )
5267 . bind ( input. start_date )
5368 . bind ( input. end_date )
5469 . bind ( input. year )
70+ . bind ( input. member_id )
5571 . bind ( & input. reason )
5672 . fetch_one ( pool. as_ref ( ) )
5773 . await ?;
5874
59- Ok ( status )
75+ Ok ( status_break )
6076 }
6177}
0 commit comments