mirror of
https://github.com/grassrootseconomics/farmstar-survey-backend.git
synced 2025-05-08 11:11:01 +02:00
feat: check distributor -> shop registration when recording purchase
* closes #12
This commit is contained in:
parent
cc21913568
commit
639d0cd67d
@ -1,6 +1,7 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/labstack/echo/v5"
|
"github.com/labstack/echo/v5"
|
||||||
@ -50,7 +51,6 @@ func (r *RouterContainer) bootstrapTransactionRoute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if requestData.Tx == "buy" {
|
if requestData.Tx == "buy" {
|
||||||
log.Println("buy")
|
|
||||||
counterpartyRecord, err := r.PB.Dao().FindFirstRecordByData("users", "phone", requestData.TxBuyType)
|
counterpartyRecord, err := r.PB.Dao().FindFirstRecordByData("users", "phone", requestData.TxBuyType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apis.NewNotFoundError("Counterparty not registered", err)
|
return apis.NewNotFoundError("Counterparty not registered", err)
|
||||||
@ -60,6 +60,15 @@ func (r *RouterContainer) bootstrapTransactionRoute() {
|
|||||||
return apis.NewNotFoundError("Counterparty is not registered as a distributor", err)
|
return apis.NewNotFoundError("Counterparty is not registered as a distributor", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
distributorRecord, err := r.PB.Dao().FindFirstRecordByData("distributor_base", "user", counterpartyRecord.Id)
|
||||||
|
if err != nil {
|
||||||
|
return apis.NewNotFoundError("Counterparty not found in distributors record", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if distributorRecord.GetString("distributor_name") != requestData.DistributorName {
|
||||||
|
return apis.NewNotFoundError(fmt.Sprintf("Counterparty is not registered to %s", requestData.DistributorName), err)
|
||||||
|
}
|
||||||
|
|
||||||
txData["evergrow_quantity"] = requestData.EvergrowQuantityPurchase
|
txData["evergrow_quantity"] = requestData.EvergrowQuantityPurchase
|
||||||
txData["distributor_name"] = requestData.DistributorName
|
txData["distributor_name"] = requestData.DistributorName
|
||||||
txData["counterparty"] = counterpartyRecord.Id
|
txData["counterparty"] = counterpartyRecord.Id
|
||||||
@ -67,7 +76,6 @@ func (r *RouterContainer) bootstrapTransactionRoute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if requestData.Tx == "sell" {
|
if requestData.Tx == "sell" {
|
||||||
log.Println("sell")
|
|
||||||
counterpartyRecord, err := r.PB.Dao().FindFirstRecordByData("users", "phone", requestData.TxSellType)
|
counterpartyRecord, err := r.PB.Dao().FindFirstRecordByData("users", "phone", requestData.TxSellType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apis.NewNotFoundError("", err)
|
return apis.NewNotFoundError("", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user