Implement overproduction notification handling in ProduceWorker: Add logic to check for existing notifications and update them if necessary, or create a new notification if none exist. Introduce SQL queries for finding and updating overproduction notifications to enhance database interactions.
This commit is contained in:
@@ -1452,6 +1452,31 @@ pub const QUERY_ADD_OVERPRODUCTION_NOTIFICATION: &str = r#"
|
||||
) VALUES ($1, $2, FALSE, NOW(), NOW());
|
||||
"#;
|
||||
|
||||
pub const QUERY_UPDATE_OVERPRODUCTION_NOTIFICATION: &str = r#"
|
||||
UPDATE falukant_log.notification
|
||||
SET tr = jsonb_set(
|
||||
tr::jsonb,
|
||||
'{value}',
|
||||
to_jsonb(COALESCE((tr::jsonb->>'value')::int, 0) + $3)
|
||||
)::text,
|
||||
updated_at = NOW()
|
||||
WHERE user_id = $1
|
||||
AND shown = FALSE
|
||||
AND tr::text LIKE '%"tr":"production.overproduction"%'
|
||||
AND (tr::jsonb->>'branch_id')::int = $2;
|
||||
"#;
|
||||
|
||||
pub const QUERY_FIND_OVERPRODUCTION_NOTIFICATION: &str = r#"
|
||||
SELECT id, tr
|
||||
FROM falukant_log.notification
|
||||
WHERE user_id = $1
|
||||
AND shown = FALSE
|
||||
AND tr::text LIKE '%"tr":"production.overproduction"%'
|
||||
AND (tr::jsonb->>'branch_id')::int = $2
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1;
|
||||
"#;
|
||||
|
||||
// Aliases for personal variants (keeps original prepared statement names used in events.worker)
|
||||
pub const QUERY_REDUCE_INVENTORY_PERSONAL: &str = QUERY_REDUCE_INVENTORY;
|
||||
pub const QUERY_DELETE_INVENTORY_PERSONAL: &str = QUERY_DELETE_INVENTORY;
|
||||
|
||||
Reference in New Issue
Block a user