Skip to content

Commit 882f96f

Browse files
authored
Merge pull request #19 from SiegfriedBz/feature/fix-cqrs-senior-reviewer-assignments-filter
fix(cqrs): apply IN_REVIEW status filter to senior reviewer assignments # PR: Fix Senior Reviewer Assignment Filtering ## Summary Fixed a bug where Senior Reviewers still saw finished (`PUBLISHED`) or failed (`SLASHED`) publications in their "Active Assignments" table. ## The Problem While Peer Reviewers saw the correctly filtered list, Senior Reviewers were seeing all assignments regardless of the publication's current status. ## Root Cause A SQL operator precedence bug in the `getMemberAssignments` function. A raw SQL template literal was used where `AND` bound more tightly than `OR`, causing the status filter to only apply to the Peer Reviewer branch. * **Incorrect Logic:** `WHERE reviewerType = 'peer' AND status = 2 OR reviewerType = 'senior'` * **Actual Execution:** `(Peer AND Active) OR (Senior)` ## The Fix Refactored the query to use Drizzle ORM’s `or()` and `and()` helpers. This ensures proper parenthesization in the emitted SQL so that the status filter is applied to both reviewer types. * **Corrected Logic:** `WHERE (reviewerType = 'peer' OR reviewerType = 'senior') AND status = 2` ## Changes * **`getMemberAssignments`**: Swapped raw SQL for Drizzle functional syntax for better type safety and correct operator grouping. * **Verification**: Confirmed that Senior Reviewer dashboards now correctly filter out non-active publications.
2 parents 43461e0 + 0091597 commit 882f96f

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/cqrs/src/queries/member-assignments.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type Publication,
55
publicationDbSchema,
66
} from "@packages/schema"
7-
import { and, count, desc, eq, sql } from "drizzle-orm"
7+
import { and, count, desc, eq, or, sql } from "drizzle-orm"
88

99
export type MemberAssignmentsResponse = {
1010
items: Publication[]
@@ -24,7 +24,10 @@ export async function getMemberAssignments(
2424
const { userAddress, limit, offset = 0 } = params
2525
const address = userAddress.toLowerCase()
2626

27-
const reviewerClause = sql`${address} = ANY(${publicationDbSchema.reviewers}) OR ${publicationDbSchema.seniorReviewer} = ${address}`
27+
const reviewerClause = or(
28+
sql`${address} = ANY(${publicationDbSchema.reviewers})`,
29+
eq(publicationDbSchema.seniorReviewer, address),
30+
)
2831

2932
const whereClause = and(eq(publicationDbSchema.status, 2), reviewerClause)
3033

0 commit comments

Comments
 (0)