Changes to deactivate/reactivate products (#89)
This commit is contained in:
parent
cf82ed478d
commit
83c94e94db
5 changed files with 41 additions and 13 deletions
10
crud.py
10
crud.py
|
|
@ -292,8 +292,8 @@ async def create_product(merchant_id: str, data: PartialProduct) -> Product:
|
|||
await db.execute(
|
||||
f"""
|
||||
INSERT INTO nostrmarket.products
|
||||
(merchant_id, id, stall_id, name, price, quantity, pending, event_id, event_created_at, image_urls, category_list, meta)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
(merchant_id, id, stall_id, name, price, quantity, active, pending, event_id, event_created_at, image_urls, category_list, meta)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO NOTHING
|
||||
""",
|
||||
(
|
||||
|
|
@ -303,6 +303,7 @@ async def create_product(merchant_id: str, data: PartialProduct) -> Product:
|
|||
data.name,
|
||||
data.price,
|
||||
data.quantity,
|
||||
data.active,
|
||||
data.pending,
|
||||
data.event_id,
|
||||
data.event_created_at,
|
||||
|
|
@ -321,13 +322,14 @@ async def update_product(merchant_id: str, product: Product) -> Product:
|
|||
|
||||
await db.execute(
|
||||
f"""
|
||||
UPDATE nostrmarket.products set name = ?, price = ?, quantity = ?, pending = ?, event_id =?, event_created_at = ?, image_urls = ?, category_list = ?, meta = ?
|
||||
UPDATE nostrmarket.products set name = ?, price = ?, quantity = ?, active = ?, pending = ?, event_id =?, event_created_at = ?, image_urls = ?, category_list = ?, meta = ?
|
||||
WHERE merchant_id = ? AND id = ?
|
||||
""",
|
||||
(
|
||||
product.name,
|
||||
product.price,
|
||||
product.quantity,
|
||||
product.active,
|
||||
product.pending,
|
||||
product.event_id,
|
||||
product.event_created_at,
|
||||
|
|
@ -385,7 +387,7 @@ async def get_products_by_ids(
|
|||
q = ",".join(["?"] * len(product_ids))
|
||||
rows = await db.fetchall(
|
||||
f"""
|
||||
SELECT id, stall_id, name, price, quantity, category_list, meta
|
||||
SELECT id, stall_id, name, price, quantity, active, category_list, meta
|
||||
FROM nostrmarket.products
|
||||
WHERE merchant_id = ? AND pending = false AND id IN ({q})
|
||||
""",
|
||||
|
|
|
|||
|
|
@ -172,4 +172,9 @@ async def m003_update_direct_message_type(db):
|
|||
async def m004_add_merchant_timestamp(db):
|
||||
await db.execute(
|
||||
f"ALTER TABLE nostrmarket.merchants ADD COLUMN time TIMESTAMP;"
|
||||
)
|
||||
|
||||
async def m005_update_product_activation(db):
|
||||
await db.execute(
|
||||
"ALTER TABLE nostrmarket.products ADD COLUMN active BOOLEAN NOT NULL DEFAULT true;"
|
||||
)
|
||||
23
models.py
23
models.py
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -100,6 +100,16 @@
|
|||
<q-td auto-width>
|
||||
<q-btn size="sm" color="primary" dense @click="editProduct(props.row)" icon="edit" />
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-toggle
|
||||
@input="updateProduct({ ...props.row, active: props.row.active })"
|
||||
size="xs"
|
||||
checked-icon="check"
|
||||
v-model="props.row.active"
|
||||
color="green"
|
||||
unchecked-icon="clear"
|
||||
/>
|
||||
</q-td>
|
||||
|
||||
<q-td key="id" :props="props"> {{props.row.id}} </q-td>
|
||||
<q-td key="name" :props="props"> {{shortLabel(props.row.name)}} </q-td>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ async function stallDetails(path) {
|
|||
label: '',
|
||||
field: ''
|
||||
},
|
||||
{
|
||||
name: 'activate',
|
||||
align: 'left',
|
||||
label: '',
|
||||
field: ''
|
||||
},
|
||||
|
||||
{
|
||||
name: 'id',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue