feat: check distributor -> shop registration when recording purchase

* closes #12
This commit is contained in:
Mohamed Sohail 2024-02-05 16:23:43 +03:00
parent cc21913568
commit 639d0cd67d
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
1 changed files with 10 additions and 2 deletions

View File

@ -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)