@@ -180,7 +180,7 @@ export async function openStewardshipByPurl(
180180export async function assignSteward (
181181 qx : QueryExecutor ,
182182 stewardshipId : number ,
183- data : { userId : string ; role : 'lead' | 'co_steward' ; assignedBy : string } ,
183+ data : { userId : string ; role : 'lead' | 'co_steward' ; assignedBy : string ; moveToAssessing ?: boolean } ,
184184) : Promise < { stewardship : StewardshipRecord ; stewards : StewardshipStewardRecord [ ] } | null > {
185185 return qx . tx ( async ( tx ) => {
186186 const stewardship = await getStewardshipById ( tx , stewardshipId )
@@ -213,6 +213,37 @@ export async function assignSteward(
213213 } ,
214214 )
215215
216+ let finalStewardship = stewardship
217+
218+ if ( data . moveToAssessing ) {
219+ const updated : Record < string , unknown > | null = await tx . selectOneOrNone (
220+ `
221+ WITH upd AS (
222+ UPDATE stewardships
223+ SET status = 'assessing',
224+ last_status_at = NOW(),
225+ resolution_path = NULL,
226+ status_note = NULL,
227+ updated_at = NOW()
228+ WHERE id = $(stewardshipId)
229+ AND status IN ('unassigned', 'open')
230+ RETURNING id, package_id, status, origin, version, opened_at,
231+ last_status_at, inactive_reason, resolution_path, status_note, created_at, updated_at
232+ ),
233+ _log AS (
234+ INSERT INTO stewardship_activity
235+ (stewardship_id, actor_user_id, actor_type, activity_type, content, metadata)
236+ SELECT id, $(actorUserId), 'user', 'state_changed',
237+ 'Status updated to assessing', $(metadata)::jsonb
238+ FROM upd
239+ )
240+ SELECT * FROM upd
241+ ` ,
242+ { stewardshipId, actorUserId : data . assignedBy , metadata : JSON . stringify ( { status : 'assessing' } ) } ,
243+ )
244+ if ( updated ) finalStewardship = mapStewardshipRow ( updated )
245+ }
246+
216247 const stewards : Array < Record < string , unknown > > = await tx . select (
217248 `SELECT id, stewardship_id, user_id, role, assigned_at, assigned_by
218249 FROM stewardship_stewards
@@ -223,7 +254,7 @@ export async function assignSteward(
223254 )
224255
225256 return {
226- stewardship,
257+ stewardship : finalStewardship ,
227258 stewards : stewards . map ( mapStewardStewardRow ) ,
228259 }
229260 } )
0 commit comments