summaryrefslogtreecommitdiff
path: root/makima/src/db/repository.rs
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-02-16 15:09:25 +0000
committerGitHub <noreply@github.com>2026-02-16 15:09:25 +0000
commitb6a29bb563499b2fd6280c742bd2106d66393112 (patch)
tree6f8d13fe989613b687b12e37277b661ff4d607c8 /makima/src/db/repository.rs
parent0676468e3e69ff36f1e509d775f191dd41f6080b (diff)
downloadsoryu-b6a29bb563499b2fd6280c742bd2106d66393112.tar.gz
soryu-b6a29bb563499b2fd6280c742bd2106d66393112.zip
Add pick-up-orders feature for directives (#64)
* WIP: heartbeat checkpoint * WIP: heartbeat checkpoint * feat: soryu-co/soryu - makima: Add frontend pick-up-orders button and API integration * feat: soryu-co/soryu - makima: Add pick-up-orders backend endpoint and repository functions
Diffstat (limited to 'makima/src/db/repository.rs')
-rw-r--r--makima/src/db/repository.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs
index b5888c9..2ef3fbc 100644
--- a/makima/src/db/repository.rs
+++ b/makima/src/db/repository.rs
@@ -6319,3 +6319,58 @@ pub async fn convert_order_to_step(
Ok(Some(step))
}
+// =============================================================================
+// Order Pickup
+// =============================================================================
+
+/// Get available orders for pickup: open orders with no directive assigned,
+/// sorted by priority (critical first) then creation date.
+pub async fn get_available_orders_for_pickup(
+ pool: &PgPool,
+ owner_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
+ ORDER BY CASE priority
+ WHEN 'critical' THEN 0
+ WHEN 'high' THEN 1
+ WHEN 'medium' THEN 2
+ WHEN 'low' THEN 3
+ ELSE 4
+ END ASC, created_at ASC
+ "#,
+ )
+ .bind(owner_id)
+ .fetch_all(pool)
+ .await
+}
+
+/// Bulk-link orders to a directive by setting directive_id on matching orders.
+/// Returns the count of updated rows.
+pub async fn bulk_link_orders_to_directive(
+ pool: &PgPool,
+ owner_id: Uuid,
+ order_ids: &[Uuid],
+ directive_id: Uuid,
+) -> Result<i64, sqlx::Error> {
+ let result = sqlx::query(
+ r#"
+ UPDATE orders
+ SET directive_id = $1, updated_at = NOW()
+ WHERE id = ANY($2)
+ AND owner_id = $3
+ "#,
+ )
+ .bind(directive_id)
+ .bind(order_ids)
+ .bind(owner_id)
+ .execute(pool)
+ .await?;
+ Ok(result.rows_affected() as i64)
+}
+