@@ -8,39 +8,44 @@ import { getPackagesQx } from '@/db/packagesDb'
88import { ok } from '@/utils/api'
99import { validateOrThrow } from '@/utils/validation'
1010
11+ import { actorInputSchema } from './actorSchema'
12+
1113const paramsSchema = z . object ( {
1214 id : z . coerce . number ( ) . int ( ) . positive ( ) ,
1315} )
1416
15- const bodySchema = z
16- . object ( {
17- userId : z . string ( ) . trim ( ) . min ( 1 ) ,
18- username : z . string ( ) . trim ( ) . min ( 1 ) . optional ( ) . nullable ( ) ,
19- displayName : z . string ( ) . trim ( ) . min ( 1 ) . optional ( ) . nullable ( ) ,
20- role : z . enum ( [ 'lead' , 'co_steward' ] ) ,
21- note : z . string ( ) . trim ( ) . min ( 1 ) . optional ( ) ,
22- moveToAssessing : z . boolean ( ) . optional ( ) . default ( false ) ,
23- } )
24- . refine ( ( d ) => ( d . username == null ) === ( d . displayName == null ) , {
25- message : 'username and displayName must both be provided or both be absent' ,
26- path : [ 'displayName' ] ,
27- } )
17+ const bodySchema = z . object ( {
18+ steward : z
19+ . object ( {
20+ userId : z . string ( ) . trim ( ) . min ( 1 ) ,
21+ username : z . string ( ) . trim ( ) . min ( 1 ) . optional ( ) . nullable ( ) ,
22+ displayName : z . string ( ) . trim ( ) . min ( 1 ) . optional ( ) . nullable ( ) ,
23+ role : z . enum ( [ 'lead' , 'co_steward' ] ) ,
24+ } )
25+ . refine ( ( d ) => ( d . username == null ) === ( d . displayName == null ) , {
26+ message : 'username and displayName must both be provided or both be absent' ,
27+ path : [ 'displayName' ] ,
28+ } ) ,
29+ note : z . string ( ) . trim ( ) . min ( 1 ) . optional ( ) ,
30+ moveToAssessing : z . boolean ( ) . optional ( ) . default ( false ) ,
31+ actor : actorInputSchema ,
32+ } )
2833
2934export async function assignStewardHandler ( req : Request , res : Response ) : Promise < void > {
3035 const { id } = validateOrThrow ( paramsSchema , req . params )
31- const { userId, username, displayName, role, note, moveToAssessing } = validateOrThrow (
32- bodySchema ,
33- req . body ,
34- )
36+ const { steward, note, moveToAssessing, actor } = validateOrThrow ( bodySchema , req . body )
3537
3638 const qx = await getPackagesQx ( )
3739 const result = await assignSteward ( qx , id , {
38- userId,
39- username,
40- displayName,
41- role,
40+ userId : steward . userId ,
41+ username : steward . username ,
42+ displayName : steward . displayName ,
43+ role : steward . role ,
4244 note,
4345 assignedBy : req . actor . id ,
46+ actorUsername : actor . username ?? null ,
47+ actorDisplayName : actor . displayName ?? null ,
48+ actorAvatarUrl : actor . avatarUrl ?? null ,
4449 moveToAssessing,
4550 } )
4651
0 commit comments