Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shifted code from scheduler to paymentstreammanager, added some new queries for admin on the UI side #29

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions backend/hasura-actions/src/PaymentStreamManager.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions backend/hasura-actions/src/PaymentStreamManager.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,90 @@ let createStream = Serbet.endpoint({
)
}),
})

let addPaymentEntry = (~streamID, ~timestamp, ~amount) => {
gqlClient.mutate(
~mutation=module(Query.AddPaymentEntry),
Query.AddPaymentEntry.makeVariables(
~streamID,
~paymentTimestamp=timestamp,
~paymentState="PENDING",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, we should make paymentState an enum.

#31

~paymentAmount=amount,
(),
),
)
->JsPromise.map(result =>
switch result {
| Ok({data}) => Js.log2("success payment added", data.insert_payments_one)
| Error(error) => Js.log2("error payment added: ", error)
}
)
->ignore
}

let updatePaymentEntry = (~paymentID, ~state) => {
gqlClient.mutate(
~mutation=module(Query.UpdatePaymentEntry),
Query.UpdatePaymentEntry.makeVariables(~paymentID, ~paymentState=state, ()),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log2("success update payment: ", state)
| Error(error) => Js.log3("error update payment: ", state, error)
}
)
->ignore
}

let updateStreamEntry = (~streamID, ~totalPaymentsMade, ~nextPayment, ~lastPayment) => {
gqlClient.mutate(
~mutation=module(Query.UpdateStreamEntry),
Query.UpdateStreamEntry.makeVariables(
~id=streamID,
~paymentsMade=totalPaymentsMade,
~nextPayment,
~lastPayment,
(),
),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log3("success payment made: ", totalPaymentsMade, nextPayment)
| Error(error) => Js.log2("error payment made: ", error)
}
)
->ignore
}

let closeStreamEntry = (~streamID, ~totalPaymentsMade) => {
gqlClient.mutate(
~mutation=module(Query.CloseStreamEntry),
Query.CloseStreamEntry.makeVariables(
~id=streamID,
~paymentsMade=totalPaymentsMade,
~state="CLOSED",
(),
),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log("success close entry: CLOSED")
| Error(error) => Js.log2("error close entry: ", error)
}
)
->ignore
}

let addUser = (~username, ~ethAddress, ~description) => {
gqlClient.mutate(
~mutation=module(Query.AddUser),
Query.AddUser.makeVariables(~name=username, ~address=ethAddress, ~description, ()),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log("success user added")
| Error(error) => Js.log2("error user added: ", error)
}
)
->ignore
}
Loading