diff options
| author | soryu <soryu@soryu.co> | 2026-02-16 19:01:56 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-16 19:01:56 +0000 |
| commit | 4bd40f047a6f4703945c6db2811d8feda27241d6 (patch) | |
| tree | b53feed7931309520c0886585487d143fc2957f4 /makima/src/db | |
| parent | b3de779d87450033f1e0361144c621a1d5f1dbf8 (diff) | |
| download | soryu-4bd40f047a6f4703945c6db2811d8feda27241d6.tar.gz soryu-4bd40f047a6f4703945c6db2811d8feda27241d6.zip | |
soryu-co/soryu - makima (#66)
* feat: soryu-co/soryu - makima: Fix contracts page scrolling overflow
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
Diffstat (limited to 'makima/src/db')
| -rw-r--r-- | makima/src/db/models.rs | 2 | ||||
| -rw-r--r-- | makima/src/db/repository.rs | 42 |
2 files changed, 40 insertions, 4 deletions
diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs index 2951159..33b9795 100644 --- a/makima/src/db/models.rs +++ b/makima/src/db/models.rs @@ -2897,7 +2897,7 @@ pub struct Order { pub order_type: String, /// Flexible labels as JSON array of strings pub labels: serde_json::Value, - /// Linked directive (optional) + /// Linked directive (required for new orders, nullable for legacy rows) pub directive_id: Option<Uuid>, /// Linked directive step (optional) pub directive_step_id: Option<Uuid>, diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index cb6a0c6..d274548 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -6305,19 +6305,21 @@ pub async fn convert_order_to_step( // Order Pickup // ============================================================================= -/// Get available orders for pickup: open orders with no directive assigned, +/// Get available orders for pickup: open orders with no directive assigned +/// OR orders already linked to this specific directive that are not yet done, /// sorted by priority (critical first) then creation date. pub async fn get_available_orders_for_pickup( pool: &PgPool, owner_id: Uuid, + directive_id: Uuid, ) -> Result<Vec<Order>, sqlx::Error> { sqlx::query_as::<_, Order>( r#" SELECT * FROM orders WHERE owner_id = $1 - AND status = 'open' - AND directive_id IS NULL + AND status IN ('open', 'in_progress') + AND (directive_id IS NULL OR directive_id = $2) ORDER BY CASE priority WHEN 'critical' THEN 0 WHEN 'high' THEN 1 @@ -6328,6 +6330,7 @@ pub async fn get_available_orders_for_pickup( "#, ) .bind(owner_id) + .bind(directive_id) .fetch_all(pool) .await } @@ -6356,3 +6359,36 @@ pub async fn bulk_link_orders_to_directive( Ok(result.rows_affected() as i64) } +/// Bulk update order status for a set of order IDs. +/// Returns the count of updated rows. +pub async fn bulk_update_order_status( + pool: &PgPool, + owner_id: Uuid, + order_ids: &[Uuid], + status: &str, +) -> Result<i64, sqlx::Error> { + let result = sqlx::query( + r#"UPDATE orders SET status = $1, updated_at = NOW() + WHERE id = ANY($2) AND owner_id = $3"#, + ) + .bind(status) + .bind(order_ids) + .bind(owner_id) + .execute(pool) + .await?; + Ok(result.rows_affected() as i64) +} + +/// Get orders linked to a specific directive step. +pub async fn get_orders_by_step_id( + pool: &PgPool, + step_id: Uuid, +) -> Result<Vec<Order>, sqlx::Error> { + sqlx::query_as::<_, Order>( + r#"SELECT * FROM orders WHERE directive_step_id = $1"#, + ) + .bind(step_id) + .fetch_all(pool) + .await +} + |
