Recommendation question: not for admins and authors
CI / test (push) Successful in 2m38s
CI / build (push) Skipped
CI / deploy (push) Skipped

The team's answers would only blur the number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-24 07:49:26 +00:00
co-authored by Claude Opus 5.5
parent e1dee3a20d
commit 6731955fce
3 changed files with 12 additions and 4 deletions
+5 -3
View File
@@ -8,7 +8,7 @@
//! * messages from the "Visszajelzés" page (bug, idea, question), with a
//! state and the operator's reply, both shown to the user there;
//! * one "would you recommend us?" question (0–10, NPS), asked once in the
//! app after a couple of finished contents.
//! app after a couple of finished contents (not of the team).
//!
//! Admins see it all on Admin → Visszajelzések; the admin menu counts what is
//! new.
@@ -356,11 +356,13 @@ pub async fn unseen_replies(conn: &mut PgConnection, user: Uuid) -> Result<i64,
// --- the recommendation question (NPS) -----------------------------------------------------------
/// Whether to ask the user now: not asked before, and has a couple of
/// finished contents (the free summary does not count).
/// Whether to ask the user now: not asked before, has a couple of finished
/// contents (the free summary does not count), and is no one of the team
/// (admins and authors).
pub async fn nps_due(conn: &mut PgConnection, user: Uuid) -> Result<bool, sqlx::Error> {
sqlx::query_scalar(&format!(
"SELECT NOT EXISTS (SELECT 1 FROM nps_answers WHERE user_id = $1) \
AND NOT EXISTS (SELECT 1 FROM users WHERE id = $1 AND roles && ARRAY['admin', 'creator']) \
AND (SELECT count(*) FROM analyses WHERE requested_by = $1 AND status = 'done' \
AND kind IN ('natal', 'synastry', 'forecast', 'tarot')) \
+ (SELECT count(*) FROM questions WHERE asked_by = $1 AND status = 'done') >= {NPS_AFTER}"