diff --git a/apps/backend/src/repositories/worker-platform/work-order-query-repo.ts b/apps/backend/src/repositories/worker-platform/work-order-query-repo.ts index 099a107a..82dcaf42 100644 --- a/apps/backend/src/repositories/worker-platform/work-order-query-repo.ts +++ b/apps/backend/src/repositories/worker-platform/work-order-query-repo.ts @@ -457,6 +457,24 @@ export async function countWorkerTimeoutEvents(workerId: number | string): Promi return counts.get(Number(workerId)) || 0 } +export async function countWorkerCancellationsSince( + workerId: number | string, + sinceIso: string, +): Promise { + const result = await query<{ total: number }>( + ` + SELECT COUNT(*)::int AS total + FROM work_order_events + WHERE actor_type = 'worker' + AND actor_id = $1 + AND event_type = 'cancelled_by_worker' + AND created_at >= $2 + `, + [String(workerId), sinceIso], + ) + return Number(result.rows[0]?.total || 0) +} + export async function getWorkOrderByIdWithClient( client: PoolClient, workOrderId: number | string, diff --git a/apps/backend/src/repositories/worker-platform/work-order-repo.ts b/apps/backend/src/repositories/worker-platform/work-order-repo.ts index ade6a5e4..cefd649f 100644 --- a/apps/backend/src/repositories/worker-platform/work-order-repo.ts +++ b/apps/backend/src/repositories/worker-platform/work-order-repo.ts @@ -11,6 +11,7 @@ import { import { createWorkOrderEventWithClient } from './work-order-event-repo.js' import { countTimeoutEventsByWorkerIds, + countWorkerCancellationsSince, countWorkerActiveOrders, countWorkerTimeoutEvents, getWorkOrderById, @@ -714,24 +715,6 @@ export async function reopenCancelledWorkOrder(input: { }) } -export async function countWorkerCancellationsSince( - workerId: number | string, - sinceIso: string, -): Promise { - const result = await query<{ total: number }>( - ` - SELECT COUNT(*)::int AS total - FROM work_order_events - WHERE actor_type = 'worker' - AND actor_id = $1 - AND event_type = 'cancelled_by_worker' - AND created_at >= $2 - `, - [String(workerId), sinceIso], - ) - return Number(result.rows[0]?.total || 0) -} - export async function acceptWorkOrderAndSettle(input: { workOrderId: number unfreezeDays: number