Skip to content

Commit 0b98041

Browse files
committed
add transform for BountyCharge
1 parent 2600a66 commit 0b98041

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

scripts/database_migration.exs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ defmodule DatabaseMigration do
3535
"GithubPullRequest" => nil,
3636
"Bounty" => "bounties",
3737
"Reward" => nil,
38+
"BountyCharge" => "transactions",
3839
"BountyTransfer" => "transactions",
3940
"Claim" => nil
4041
}
@@ -48,6 +49,7 @@ defmodule DatabaseMigration do
4849
"GithubPullRequest" => nil,
4950
"Bounty" => Bounty,
5051
"Reward" => nil,
52+
"BountyCharge" => Transaction,
5153
"BountyTransfer" => Transaction,
5254
"Claim" => nil
5355
}
@@ -292,6 +294,51 @@ defmodule DatabaseMigration do
292294
}
293295
end
294296

297+
defp transform("BountyCharge", row, db) do
298+
user = db |> Map.get("Org", []) |> Enum.find(&(&1["id"] == row["org_id"]))
299+
300+
amount = Money.from_integer(String.to_integer(row["amount"]), row["currency"])
301+
302+
if !user || row["succeeded_at"] == nil do
303+
raise "User not found: #{inspect(row)}"
304+
end
305+
306+
%{
307+
"id" => row["id"],
308+
"provider" => "stripe",
309+
"provider_id" => row["charge_id"],
310+
"provider_charge_id" => row["charge_id"],
311+
"provider_payment_intent_id" => nil,
312+
"provider_transfer_id" => nil,
313+
"provider_invoice_id" => nil,
314+
"provider_balance_transaction_id" => nil,
315+
"provider_meta" => nil,
316+
# TODO: incorrect
317+
"gross_amount" => amount,
318+
"net_amount" => amount,
319+
# TODO: incorrect
320+
"total_fee" => Money.zero(:USD),
321+
"provider_fee" => nil,
322+
"line_items" => nil,
323+
"type" => "charge",
324+
"status" => if(row["succeeded_at"] == nil, do: :initialized, else: :succeeded),
325+
"succeeded_at" => row["succeeded_at"],
326+
"reversed_at" => nil,
327+
"group_id" => nil,
328+
## TODO: this might be null but shouldn't
329+
"user_id" => user["id"],
330+
"contract_id" => nil,
331+
"original_contract_id" => nil,
332+
"timesheet_id" => nil,
333+
"bounty_id" => nil,
334+
"tip_id" => nil,
335+
"linked_transaction_id" => nil,
336+
"inserted_at" => row["created_at"],
337+
"updated_at" => row["updated_at"],
338+
"claim_id" => nil
339+
}
340+
end
341+
295342
defp transform("BountyTransfer", row, db) do
296343
claim = db |> Map.get("Claim", []) |> Enum.find(&(&1["id"] == row["claim_id"]))
297344

0 commit comments

Comments
 (0)