summaryrefslogtreecommitdiff
path: root/nexus/src/main
diff options
context:
space:
mode:
authorMS <ms@taler.net>2020-05-14 20:57:45 +0200
committerMS <ms@taler.net>2020-05-14 20:57:45 +0200
commitdee6d7b62215972e958a8a5e03242d11e22117b9 (patch)
tree0e58c4ff93e601d7749a6581176b0f347d970182 /nexus/src/main
parent081f9a4f105c6f2855a382df09dab5eea4bf4fb9 (diff)
downloadlibeufin-dee6d7b62215972e958a8a5e03242d11e22117b9.tar.gz
libeufin-dee6d7b62215972e958a8a5e03242d11e22117b9.tar.bz2
libeufin-dee6d7b62215972e958a8a5e03242d11e22117b9.zip
Moving DB statements inside transaction block.
Diffstat (limited to 'nexus/src/main')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt25
1 files changed, 15 insertions, 10 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index aa73709a..15b4a8b1 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -280,19 +280,22 @@ fun main() {
/**
* Submit one particular payment at the bank.
*/
- post("/bank-accounts/{accountid}/prepared-payments/submit") {
+ post("/bank-accounts/prepared-payments/submit") {
val userId = authenticateRequest(call.request.headers["Authorization"])
val body = call.receive<SubmitPayment>()
val preparedPayment = getPreparedPayment(body.uuid)
- if (preparedPayment.nexusUser.id.value != userId) throw NexusError(
- HttpStatusCode.Forbidden,
- "No rights over such payment"
- )
- if (preparedPayment.submitted) {
- throw NexusError(
- HttpStatusCode.PreconditionFailed,
- "Payment ${body.uuid} was submitted already"
+ transaction {
+ if (preparedPayment.nexusUser.id.value != userId) throw NexusError(
+ HttpStatusCode.Forbidden,
+ "No rights over such payment"
)
+ if (preparedPayment.submitted) {
+ throw NexusError(
+ HttpStatusCode.PreconditionFailed,
+ "Payment ${body.uuid} was submitted already"
+ )
+ }
+
}
val pain001document = createPain001document(preparedPayment)
if (body.transport != null) {
@@ -314,7 +317,9 @@ fun main() {
client, userId, null, pain001document
)
}
- preparedPayment.submitted = true
+ transaction {
+ preparedPayment.submitted = true
+ }
call.respondText("Payment ${body.uuid} submitted")
return@post
}