mirror of
https://github.com/grassrootseconomics/farmstar-survey-backend.git
synced 2024-12-04 15:36:48 +01: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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
@ -50,7 +51,6 @@ func (r *RouterContainer) bootstrapTransactionRoute() {
|
||||
}
|
||||
|
||||
if requestData.Tx == "buy" {
|
||||
log.Println("buy")
|
||||
counterpartyRecord, err := r.PB.Dao().FindFirstRecordByData("users", "phone", requestData.TxBuyType)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
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["distributor_name"] = requestData.DistributorName
|
||||
txData["counterparty"] = counterpartyRecord.Id
|
||||
@ -67,7 +76,6 @@ func (r *RouterContainer) bootstrapTransactionRoute() {
|
||||
}
|
||||
|
||||
if requestData.Tx == "sell" {
|
||||
log.Println("sell")
|
||||
counterpartyRecord, err := r.PB.Dao().FindFirstRecordByData("users", "phone", requestData.TxSellType)
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("", err)
|
||||
|
Loading…
Reference in New Issue
Block a user