Skip to content

[WIP] provider reassigned orders (single column on payment_orders)#731

Draft
sundayonah wants to merge 1 commit intomainfrom
feat/reassigned-orders-plan
Draft

[WIP] provider reassigned orders (single column on payment_orders)#731
sundayonah wants to merge 1 commit intomainfrom
feat/reassigned-orders-plan

Conversation

@sundayonah
Copy link
Collaborator

@sundayonah sundayonah commented Mar 18, 2026

Reassigned Orders

Overview

Providers see orders that were automatically moved away from them (reassigned due to inactivity) by adding one nullable column on payment_orders and using it for the "Reassigned" list and display status. No new table.


User Story (Reference)

As a Provider on Paycrest,
I want to see orders that were automatically moved away from me due to inactivity,
So that I can track missed orders and improve my response time.

Acceptance criteria:

  1. When the aggregator reassigns an order, the original provider’s order history retains a record.
  2. When the original provider views Order History, that order shows status "Reassigned".
  3. Provider can filter by "Reassigned" and see total count and details.

Schema Change

What Details
Table payment_orders (existing)
New field reassigned_from_provider_id (nullable, FK → provider_profiles.id)
Meaning When set, this order was reassigned from that provider.
Index On reassigned_from_provider_id for list queries.

Migration: One migration adding the column, FK, and index. No new tables.


Implementation Flow

Step 1: Schema (Ent)

  • In payment_orders schema, add optional edge/field: reassigned_from_provider (FK to ProviderProfile).
  • Run Ent codegen and generate migration (e.g. go run ent/migrate/main.go or Atlas).

Step 2: Reassign Logic (tasks/order_requests.go)

In reassignCancelledOrder, before clearing the provider and setting status:

  1. Update the order: set reassigned_from_provider_id = order.Edges.Provider.ID.
  2. Then perform existing logic: clear provider, set status to Pending, Redis exclude list, etc.

Order of operations: set reassigned-from → then clear provider → then (optional) release balance, delete fulfillment, etc.

Step 3: List API – Reassigned (controllers/provider/provider.go)

When status=reassigned:

  1. Query payment_orders where reassigned_from_provider_id = provider.ID.
  2. Apply same filters as other lists (currency via institution codes, etc.).
  3. Order by updated_at desc, apply pagination (page, pageSize).
  4. Count total for that provider (same filters).
  5. Build response: same shape as existing order list, with displayStatus: "reassigned" for each order.

Reuse existing response builder; only the query and displayStatus differ.

Step 4: Clear Reassigned-From When Order Is (Re)assigned (optional)

When an order is assigned to a new provider (queue or OTC) or accepted:

  • Set reassigned_from_provider_id = nil so the order no longer appears in the previous provider’s "Reassigned" list.

(If product wants it to stay in "Reassigned" even after someone else takes it, skip this step.)

Step 5: Dashboard

  • Add "Reassigned" filter/tab on provider Order History.
  • Call GET /provider/orders?currency=...&status=reassigned&page=...&pageSize=....
  • Show list and total count; display displayStatus (e.g. badge "Reassigned") in list and detail.

Data Flow (Summary)

[Reassign trigger]
→ reassignCancelledOrder:

  1. Set order.reassigned_from_provider_id = current_provider_id
  2. ClearProvider(), SetStatus(Pending)
  3. Redis exclude list, balance release, etc.

[Provider GET /orders?status=reassigned]
→ Query: payment_orders WHERE reassigned_from_provider_id = :provider_id
(+ currency/institution filters)
→ Paginate, build response
→ Each order: displayStatus: "reassigned"


Files to Touch (Checklist)

Area File(s)
Schema aggregator/ent/schema/paymentorder.go (add edge/field)
Migration New file under aggregator/ent/migrate/migrations/
Reassign aggregator/tasks/order_requests.go
List API aggregator/controllers/provider/provider.go
Assign/Accept (clear field) aggregator/services/priority_queue.go, aggregator/controllers/provider/provider.go (if clearing on assign/accept)
Dashboard Types, API client, _provider.provider.orders.tsx, ListProviderOrders.tsx

@sundayonah sundayonah marked this pull request as draft March 18, 2026 17:47
@sundayonah sundayonah changed the title chore(env): update VOYAGER_MONTHLY_LIMIT in .env.example feat: provider reassigned orders (single column on payment_orders) Mar 18, 2026
@sundayonah sundayonah changed the title feat: provider reassigned orders (single column on payment_orders) [WIP] provider reassigned orders (single column on payment_orders) Mar 18, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4be82570-f822-412c-b2d7-acb622235fed

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/reassigned-orders-plan
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant