purchase as string

This commit is contained in:
mr
2026-04-22 09:48:16 +02:00
parent a08c9b084d
commit 6741e929cc

View File

@@ -22,7 +22,7 @@ import (
// AbstractResource is the struct containing all of the attributes commons to all ressources
type AbstractResource struct {
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
PurchaseInfo *purchase_resource.PurchaseResource `json:"purchase_info,omitempty"` // is_buy precise if a resource is buy or not
PurchaseID string `json:"purchase_id,omitempty"` // is_buy precise if a resource is buy or not
Type string `json:"type,omitempty" bson:"type,omitempty"` // Type is the type of the resource
Logo string `json:"logo,omitempty" bson:"logo,omitempty"` // Logo is the logo of the resource
Description string `json:"description,omitempty" bson:"description,omitempty"` // Description is the description of the resource
@@ -36,6 +36,20 @@ type AbstractResource struct {
Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"`
}
func (ri *AbstractResource) Extend(typ ...string) map[string][]tools.DataType {
dt := map[string][]tools.DataType{}
for _, t := range typ {
switch t {
case "purchase":
if _, ok := dt[t]; !ok {
dt[t] = []tools.DataType{}
}
dt[t] = append(dt[t], tools.PURCHASE_RESOURCE)
}
}
return dt
}
func (abs *AbstractResource) VerifyBuy() {
p := &purchase_resource.PurchaseResource{}
access := p.GetAccessor(&tools.APIRequest{Admin: true})
@@ -46,7 +60,7 @@ func (abs *AbstractResource) VerifyBuy() {
},
}, "", false, 0, 1)
if len(purchase) > 0 {
abs.PurchaseInfo = purchase[0].(*purchase_resource.PurchaseResource)
abs.PurchaseID = purchase[0].GetID()
}
}