@@ -238,3 +238,124 @@ export async function deleteCrew(orm: D1Orm, crewId: number): Promise<CrewResult
238
238
} ;
239
239
}
240
240
}
241
+
242
+ /**
243
+ * Get all crews for a profile
244
+ * @param orm The D1Orm instance from durable object class
245
+ * @param address The Stacks address for the user's profile
246
+ * @returns Promise containing array of crews or error details
247
+ * @throws Error if database query fails
248
+ */
249
+ /**
250
+ * Get all execution steps for a specific execution
251
+ * @param orm The D1Orm instance from durable object class
252
+ * @param executionId The ID of the execution to get steps for
253
+ * @returns Promise containing array of execution steps or error details
254
+ */
255
+ export async function getExecutionSteps ( orm : D1Orm , executionId : number ) : Promise < CrewResult > {
256
+ try {
257
+ userCrewExecutionStepsModel . SetOrm ( orm ) ;
258
+ const result = await userCrewExecutionStepsModel . All ( {
259
+ where : {
260
+ execution_id : executionId
261
+ } ,
262
+ orderBy : [
263
+ {
264
+ column : 'created_at' ,
265
+ ascending : true ,
266
+ } ,
267
+ ] ,
268
+ } ) ;
269
+ return {
270
+ steps : result . results as unknown as UserCrewExecutionStepsTable [ ] ,
271
+ success : true
272
+ } ;
273
+ } catch ( error ) {
274
+ console . error ( `Error in getExecutionSteps: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
275
+ return {
276
+ steps : [ ] ,
277
+ success : false ,
278
+ error : `Failed to get execution steps: ${ error instanceof Error ? error . message : String ( error ) } `
279
+ } ;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Create a new execution step
285
+ * @param orm The D1Orm instance from durable object class
286
+ * @param stepData The step data to create
287
+ * @returns Promise containing the created step or error details
288
+ */
289
+ export async function createExecutionStep (
290
+ orm : D1Orm ,
291
+ stepData : Omit < UserCrewExecutionStepsTable , 'id' | 'created_at' | 'updated_at' >
292
+ ) : Promise < CrewResult > {
293
+ try {
294
+ userCrewExecutionStepsModel . SetOrm ( orm ) ;
295
+ const step = await userCrewExecutionStepsModel . InsertOne ( stepData ) ;
296
+ return {
297
+ step : step as unknown as UserCrewExecutionStepsTable ,
298
+ success : true
299
+ } ;
300
+ } catch ( error ) {
301
+ console . error ( `Error in createExecutionStep: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
302
+ return {
303
+ success : false ,
304
+ error : `Failed to create execution step: ${ error instanceof Error ? error . message : String ( error ) } `
305
+ } ;
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Delete all execution steps for a specific execution
311
+ * @param orm The D1Orm instance from durable object class
312
+ * @param executionId The ID of the execution to delete steps for
313
+ * @returns Promise containing the deletion result or error details
314
+ */
315
+ export async function deleteExecutionSteps ( orm : D1Orm , executionId : number ) : Promise < CrewResult > {
316
+ try {
317
+ userCrewExecutionStepsModel . SetOrm ( orm ) ;
318
+ await userCrewExecutionStepsModel . Delete ( {
319
+ where : {
320
+ execution_id : executionId
321
+ }
322
+ } ) ;
323
+ return {
324
+ success : true
325
+ } ;
326
+ } catch ( error ) {
327
+ console . error ( `Error in deleteExecutionSteps: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
328
+ return {
329
+ success : false ,
330
+ error : `Failed to delete execution steps: ${ error instanceof Error ? error . message : String ( error ) } `
331
+ } ;
332
+ }
333
+ }
334
+
335
+ export async function getCrewsByProfile ( orm : D1Orm , address : string ) : Promise < CrewResult > {
336
+ try {
337
+ userCrewsModel . SetOrm ( orm ) ;
338
+ const result = await userCrewsModel . All ( {
339
+ where : {
340
+ profile_id : address
341
+ } ,
342
+ orderBy : [
343
+ {
344
+ column : 'created_at' ,
345
+ descending : true ,
346
+ } ,
347
+ ] ,
348
+ } ) ;
349
+ return {
350
+ crews : result . results as unknown as UserCrewsTable [ ] ,
351
+ success : true
352
+ } ;
353
+ } catch ( error ) {
354
+ console . error ( `Error in getCrewsByProfile: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
355
+ return {
356
+ crews : [ ] ,
357
+ success : false ,
358
+ error : `Failed to get crews for profile: ${ error instanceof Error ? error . message : String ( error ) } `
359
+ } ;
360
+ }
361
+ }
0 commit comments