File tree Expand file tree Collapse file tree
backend/src/api/public/v1/ossprey
services/libs/data-access-layer/src/osspckgs Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,8 +9,21 @@ import { validateOrThrow } from '@/utils/validation'
99
1010import { STEWARDSHIP_STATUS_VALUES } from '../packages/types'
1111
12+ const statusEnum = z . enum ( STEWARDSHIP_STATUS_VALUES )
13+
14+ function normalizeToArray ( v : unknown ) : unknown [ ] | undefined {
15+ if ( v === undefined ) return undefined
16+ if ( Array . isArray ( v ) ) return v
17+ if ( typeof v === 'string' && v . includes ( ',' ) )
18+ return v
19+ . split ( ',' )
20+ . map ( ( s ) => s . trim ( ) )
21+ . filter ( Boolean )
22+ return [ v ]
23+ }
24+
1225const scatterQuerySchema = z . object ( {
13- status : z . enum ( STEWARDSHIP_STATUS_VALUES ) . optional ( ) ,
26+ status : z . preprocess ( normalizeToArray , z . array ( statusEnum ) . min ( 1 ) ) . optional ( ) ,
1427} )
1528
1629export async function packageScatterHandler ( req : Request , res : Response ) : Promise < void > {
Original file line number Diff line number Diff line change @@ -667,17 +667,16 @@ export interface ScatterPoint {
667667
668668export async function listPackagesForScatter (
669669 qx : QueryExecutor ,
670- options : { status ?: string } = { } ,
670+ options : { status ?: string [ ] } = { } ,
671671) : Promise < ScatterPoint [ ] > {
672672 const { status } = options
673673
674674 // 'unassigned' covers packages with no stewardship row (s.id IS NULL) in addition
675- // to rows explicitly marked unassigned. All other statuses filter via s.status directly .
675+ // to rows explicitly marked unassigned. All other statuses filter via s.status = ANY(...) .
676676 // The query always uses LEFT JOIN — the filter is applied in the WHERE clause, not the join.
677- const statusFilter = status
678- ? status === 'unassigned'
679- ? `AND (s.status = 'unassigned' OR s.id IS NULL)`
680- : `AND s.status = $(status)`
677+ const includesUnassigned = status ?. includes ( 'unassigned' ) ?? false
678+ const statusFilter = status ?. length
679+ ? `AND (s.status = ANY($(status)::text[])${ includesUnassigned ? ' OR s.id IS NULL' : '' } )`
681680 : ''
682681
683682 const rows : Array < {
You can’t perform that action at this time.
0 commit comments