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(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO nostrmarket.products
|
INSERT INTO nostrmarket.products
|
||||||
(merchant_id, id, stall_id, name, price, quantity, pending, event_id, event_created_at, image_urls, category_list, meta)
|
(merchant_id, id, stall_id, name, price, quantity, active, pending, event_id, event_created_at, image_urls, category_list, meta)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
ON CONFLICT(id) DO NOTHING
|
ON CONFLICT(id) DO NOTHING
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
|
@ -303,6 +303,7 @@ async def create_product(merchant_id: str, data: PartialProduct) -> Product:
|
||||||
data.name,
|
data.name,
|
||||||
data.price,
|
data.price,
|
||||||
data.quantity,
|
data.quantity,
|
||||||
|
data.active,
|
||||||
data.pending,
|
data.pending,
|
||||||
data.event_id,
|
data.event_id,
|
||||||
data.event_created_at,
|
data.event_created_at,
|
||||||
|
|
@ -321,13 +322,14 @@ async def update_product(merchant_id: str, product: Product) -> Product:
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
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 = ?
|
WHERE merchant_id = ? AND id = ?
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
product.name,
|
product.name,
|
||||||
product.price,
|
product.price,
|
||||||
product.quantity,
|
product.quantity,
|
||||||
|
product.active,
|
||||||
product.pending,
|
product.pending,
|
||||||
product.event_id,
|
product.event_id,
|
||||||
product.event_created_at,
|
product.event_created_at,
|
||||||
|
|
@ -385,7 +387,7 @@ async def get_products_by_ids(
|
||||||
q = ",".join(["?"] * len(product_ids))
|
q = ",".join(["?"] * len(product_ids))
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
f"""
|
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
|
FROM nostrmarket.products
|
||||||
WHERE merchant_id = ? AND pending = false AND id IN ({q})
|
WHERE merchant_id = ? AND pending = false AND id IN ({q})
|
||||||
""",
|
""",
|
||||||
|
|
|
||||||
|
|
@ -173,3 +173,8 @@ async def m004_add_merchant_timestamp(db):
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"ALTER TABLE nostrmarket.merchants ADD COLUMN time TIMESTAMP;"
|
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;"
|
||||||
|
)
|
||||||
|
|
@ -236,6 +236,7 @@ class PartialProduct(BaseModel):
|
||||||
images: List[str] = []
|
images: List[str] = []
|
||||||
price: float
|
price: float
|
||||||
quantity: int
|
quantity: int
|
||||||
|
active: bool = True
|
||||||
pending: bool = False
|
pending: bool = False
|
||||||
config: ProductConfig = ProductConfig()
|
config: ProductConfig = ProductConfig()
|
||||||
|
|
||||||
|
|
@ -257,10 +258,12 @@ class Product(PartialProduct, Nostrable):
|
||||||
"currency": self.config.currency,
|
"currency": self.config.currency,
|
||||||
"price": self.price,
|
"price": self.price,
|
||||||
"quantity": self.quantity,
|
"quantity": self.quantity,
|
||||||
|
"active": self.active,
|
||||||
"shipping": [dict(s) for s in self.config.shipping or []]
|
"shipping": [dict(s) for s in self.config.shipping or []]
|
||||||
}
|
}
|
||||||
categories = [["t", tag] for tag in self.categories]
|
categories = [["t", tag] for tag in self.categories]
|
||||||
|
|
||||||
|
if self.active:
|
||||||
event = NostrEvent(
|
event = NostrEvent(
|
||||||
pubkey=pubkey,
|
pubkey=pubkey,
|
||||||
created_at=round(time.time()),
|
created_at=round(time.time()),
|
||||||
|
|
@ -271,6 +274,8 @@ class Product(PartialProduct, Nostrable):
|
||||||
event.id = event.event_id
|
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:
|
def to_nostr_delete_event(self, pubkey: str) -> NostrEvent:
|
||||||
delete_event = NostrEvent(
|
delete_event = NostrEvent(
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,16 @@
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn size="sm" color="primary" dense @click="editProduct(props.row)" icon="edit" />
|
<q-btn size="sm" color="primary" dense @click="editProduct(props.row)" icon="edit" />
|
||||||
</q-td>
|
</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="id" :props="props"> {{props.row.id}} </q-td>
|
||||||
<q-td key="name" :props="props"> {{shortLabel(props.row.name)}} </q-td>
|
<q-td key="name" :props="props"> {{shortLabel(props.row.name)}} </q-td>
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,12 @@ async function stallDetails(path) {
|
||||||
label: '',
|
label: '',
|
||||||
field: ''
|
field: ''
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'activate',
|
||||||
|
align: 'left',
|
||||||
|
label: '',
|
||||||
|
field: ''
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue