Changes to deactivate/reactivate products (#89)

This commit is contained in:
rleed 2024-11-04 05:59:04 -03:00 committed by GitHub
parent cf82ed478d
commit 83c94e94db
5 changed files with 41 additions and 13 deletions

View file

@ -236,6 +236,7 @@ class PartialProduct(BaseModel):
images: List[str] = []
price: float
quantity: int
active: bool = True
pending: bool = False
config: ProductConfig = ProductConfig()
@ -257,20 +258,24 @@ class Product(PartialProduct, Nostrable):
"currency": self.config.currency,
"price": self.price,
"quantity": self.quantity,
"active": self.active,
"shipping": [dict(s) for s in self.config.shipping or []]
}
categories = [["t", tag] for tag in self.categories]
event = NostrEvent(
pubkey=pubkey,
created_at=round(time.time()),
kind=30018,
tags=[["d", self.id]] + categories,
content=json.dumps(content, separators=(",", ":"), ensure_ascii=False),
)
event.id = event.event_id
if self.active:
event = NostrEvent(
pubkey=pubkey,
created_at=round(time.time()),
kind=30018,
tags=[["d", self.id]] + categories,
content=json.dumps(content, separators=(",", ":"), ensure_ascii=False),
)
event.id = event.event_id
return event
return event
else:
return self.to_nostr_delete_event(pubkey)
def to_nostr_delete_event(self, pubkey: str) -> NostrEvent:
delete_event = NostrEvent(