Merge pull request #20 from lnbits/map_orders_with_dms
Map orders with dms
This commit is contained in:
commit
2fbd68854b
16 changed files with 107 additions and 40 deletions
16
crud.py
16
crud.py
|
|
@ -448,6 +448,14 @@ async def get_orders_for_stall(merchant_id: str, stall_id: str) -> List[Order]:
|
||||||
return [Order.from_row(row) for row in rows]
|
return [Order.from_row(row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
|
async def get_public_keys_for_orders(merchant_id: str) -> List[str]:
|
||||||
|
rows = await db.fetchall(
|
||||||
|
"SELECT DISTINCT public_key FROM nostrmarket.orders WHERE merchant_id = ?",
|
||||||
|
(merchant_id,),
|
||||||
|
)
|
||||||
|
return [row[0] for row in rows]
|
||||||
|
|
||||||
|
|
||||||
async def get_last_order_time(public_key: str) -> int:
|
async def get_last_order_time(public_key: str) -> int:
|
||||||
row = await db.fetchone(
|
row = await db.fetchone(
|
||||||
"""
|
"""
|
||||||
|
|
@ -572,3 +580,11 @@ async def delete_merchant_direct_messages(merchant_id: str) -> None:
|
||||||
"DELETE FROM nostrmarket.direct_messages WHERE merchant_id = ?",
|
"DELETE FROM nostrmarket.direct_messages WHERE merchant_id = ?",
|
||||||
(merchant_id,),
|
(merchant_id,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_public_keys_for_direct_messages(merchant_id: str) -> List[str]:
|
||||||
|
rows = await db.fetchall(
|
||||||
|
"SELECT DISTINCT public_key FROM nostrmarket.direct_messages WHERE merchant_id = ?",
|
||||||
|
(merchant_id),
|
||||||
|
)
|
||||||
|
return [row[0] for row in rows]
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ def test_decrypt_encrypt(encoded_message: str, encryption_key):
|
||||||
assert (
|
assert (
|
||||||
encoded_message == ecrypted_msg
|
encoded_message == ecrypted_msg
|
||||||
), f"expected '{encoded_message}', but got '{ecrypted_msg}'"
|
), f"expected '{encoded_message}', but got '{ecrypted_msg}'"
|
||||||
print("### test_decrypt_encrypt", encoded_message == ecrypted_msg)
|
|
||||||
|
|
||||||
|
|
||||||
ffi = FFI()
|
ffi = FFI()
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ class NostrClient:
|
||||||
logger.info("Connected to 'nostrclient' websocket")
|
logger.info("Connected to 'nostrclient' websocket")
|
||||||
|
|
||||||
def on_message(_, message):
|
def on_message(_, message):
|
||||||
# print("### on_message", message)
|
|
||||||
self.recieve_event_queue.put_nowait(message)
|
self.recieve_event_queue.put_nowait(message)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -66,7 +65,6 @@ class NostrClient:
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
async def publish_nostr_event(self, e: NostrEvent):
|
async def publish_nostr_event(self, e: NostrEvent):
|
||||||
print("### publish_nostr_event", e.dict())
|
|
||||||
await self.send_req_queue.put(["EVENT", e.dict()])
|
await self.send_req_queue.put(["EVENT", e.dict()])
|
||||||
|
|
||||||
async def subscribe_to_direct_messages(self, public_key: str, since: int):
|
async def subscribe_to_direct_messages(self, public_key: str, since: int):
|
||||||
|
|
@ -75,8 +73,6 @@ class NostrClient:
|
||||||
if since != 0:
|
if since != 0:
|
||||||
in_messages_filter["since"] = since
|
in_messages_filter["since"] = since
|
||||||
out_messages_filter["since"] = since
|
out_messages_filter["since"] = since
|
||||||
print("### in_messages_filter", in_messages_filter)
|
|
||||||
print("### out_messages_filter", out_messages_filter)
|
|
||||||
|
|
||||||
await self.send_req_queue.put(
|
await self.send_req_queue.put(
|
||||||
["REQ", f"direct-messages-in:{public_key}", in_messages_filter]
|
["REQ", f"direct-messages-in:{public_key}", in_messages_filter]
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,6 @@ async def process_nostr_message(msg: str):
|
||||||
await _handle_nip04_message(merchant_public_key, event)
|
await _handle_nip04_message(merchant_public_key, event)
|
||||||
return
|
return
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("####### bad message", msg)
|
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -199,7 +198,6 @@ async def _handle_nip04_message(merchant_public_key: str, event: NostrEvent):
|
||||||
merchant = await get_merchant_by_pubkey(merchant_public_key)
|
merchant = await get_merchant_by_pubkey(merchant_public_key)
|
||||||
assert merchant, f"Merchant not found for public key '{merchant_public_key}'"
|
assert merchant, f"Merchant not found for public key '{merchant_public_key}'"
|
||||||
|
|
||||||
# print("### clear_text_msg", subscription_name, clear_text_msg)
|
|
||||||
if event.pubkey == merchant_public_key:
|
if event.pubkey == merchant_public_key:
|
||||||
assert len(event.tag_values("p")) != 0, "Outgong message has no 'p' tag"
|
assert len(event.tag_values("p")) != 0, "Outgong message has no 'p' tag"
|
||||||
clear_text_msg = merchant.decrypt_message(
|
clear_text_msg = merchant.decrypt_message(
|
||||||
|
|
@ -260,7 +258,6 @@ async def _handle_dirrect_message(
|
||||||
order["event_created_at"] = event_created_at
|
order["event_created_at"] = event_created_at
|
||||||
return await _handle_new_order(PartialOrder(**order))
|
return await _handle_new_order(PartialOrder(**order))
|
||||||
else:
|
else:
|
||||||
# print("### text_msg", text_msg, event_created_at, event_id)
|
|
||||||
dm = PartialDirectMessage(
|
dm = PartialDirectMessage(
|
||||||
event_id=event_id,
|
event_id=event_id,
|
||||||
event_created_at=event_created_at,
|
event_created_at=event_created_at,
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,14 @@
|
||||||
<q-separator></q-separator>
|
<q-separator></q-separator>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<!-- <q-select
|
<q-select
|
||||||
v-model="customerKey"
|
v-model="activePublicKey"
|
||||||
:options="Object.keys(messages).map(k => ({label: `${k.slice(0, 25)}...`, value: k}))"
|
:options="customersPublicKeys.map(k => ({label: `${k.slice(0, 16)}...${k.slice(k.length - 16)}`, value: k}))"
|
||||||
label="Customers"
|
label="Select Customer"
|
||||||
@input="chatRoom(customerKey)"
|
|
||||||
emit-value
|
emit-value
|
||||||
></q-select> -->
|
@input="selectActiveCustomer()"
|
||||||
|
>
|
||||||
|
</q-select>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<div class="chat-container" ref="chatCard">
|
<div class="chat-container" ref="chatCard">
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,32 @@ async function directMessages(path) {
|
||||||
const template = await loadTemplateAsync(path)
|
const template = await loadTemplateAsync(path)
|
||||||
Vue.component('direct-messages', {
|
Vue.component('direct-messages', {
|
||||||
name: 'direct-messages',
|
name: 'direct-messages',
|
||||||
props: ['adminkey', 'inkey'],
|
props: ['active-public-key', 'adminkey', 'inkey'],
|
||||||
template,
|
template,
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
activePublicKey: async function (n) {
|
||||||
|
await this.getDirectMessages(n)
|
||||||
|
}
|
||||||
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
activePublicKey:
|
customersPublicKeys: [],
|
||||||
'186895a32209c3a92f0efaa7c65c3f8da690c75b952b815718c0d55d3eed821e',
|
|
||||||
messages: [],
|
messages: [],
|
||||||
newMessage: ''
|
newMessage: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
sendMessage: async function () {},
|
sendMessage: async function () {},
|
||||||
getDirectMessages: async function () {
|
getDirectMessages: async function (pubkey) {
|
||||||
if (!this.activePublicKey) {
|
if (!pubkey) {
|
||||||
|
this.messages = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const {data} = await LNbits.api.request(
|
const {data} = await LNbits.api.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/nostrmarket/api/v1/message/' + this.activePublicKey,
|
'/nostrmarket/api/v1/message/' + pubkey,
|
||||||
this.inkey
|
this.inkey
|
||||||
)
|
)
|
||||||
this.messages = data
|
this.messages = data
|
||||||
|
|
@ -35,6 +40,18 @@ async function directMessages(path) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getCustomersPublicKeys: async function () {
|
||||||
|
try {
|
||||||
|
const {data} = await LNbits.api.request(
|
||||||
|
'GET',
|
||||||
|
'/nostrmarket/api/v1/customers',
|
||||||
|
this.inkey
|
||||||
|
)
|
||||||
|
this.customersPublicKeys = data
|
||||||
|
} catch (error) {
|
||||||
|
LNbits.utils.notifyApiError(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
sendDirectMesage: async function () {
|
sendDirectMesage: async function () {
|
||||||
try {
|
try {
|
||||||
const {data} = await LNbits.api.request(
|
const {data} = await LNbits.api.request(
|
||||||
|
|
@ -47,13 +64,15 @@ async function directMessages(path) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
this.messages = this.messages.concat([data])
|
this.messages = this.messages.concat([data])
|
||||||
console.log('### this.messages', this.messages)
|
|
||||||
this.newMessage = ''
|
this.newMessage = ''
|
||||||
this.focusOnChatBox(this.messages.length - 1)
|
this.focusOnChatBox(this.messages.length - 1)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
selectActiveCustomer: async function () {
|
||||||
|
await this.getDirectMessages(this.activePublicKey)
|
||||||
|
},
|
||||||
focusOnChatBox: function (index) {
|
focusOnChatBox: function (index) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const lastChatBox = document.getElementsByClassName(
|
const lastChatBox = document.getElementsByClassName(
|
||||||
|
|
@ -66,7 +85,7 @@ async function directMessages(path) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: async function () {
|
created: async function () {
|
||||||
await this.getDirectMessages()
|
await this.getCustomersPublicKeys()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,12 @@
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
<q-td key="public_key" :props="props">
|
<q-td key="public_key" :props="props">
|
||||||
|
<span
|
||||||
|
@click="customerSelected(props.row.public_key)"
|
||||||
|
class="cursor-pointer"
|
||||||
|
>
|
||||||
{{toShortId(props.row.public_key)}}
|
{{toShortId(props.row.public_key)}}
|
||||||
|
</span>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td key="time" :props="props"> {{formatDate(props.row.time)}} </q-td>
|
<q-td key="time" :props="props"> {{formatDate(props.row.time)}} </q-td>
|
||||||
</q-tr>
|
</q-tr>
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ async function orderList(path) {
|
||||||
field: 'shipped'
|
field: 'shipped'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'pubkey',
|
name: 'public_key',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
label: 'Customer',
|
label: 'Customer',
|
||||||
field: 'pubkey'
|
field: 'pubkey'
|
||||||
|
|
@ -91,13 +91,11 @@ async function orderList(path) {
|
||||||
this.inkey
|
this.inkey
|
||||||
)
|
)
|
||||||
this.orders = data.map(s => ({...s, expanded: false}))
|
this.orders = data.map(s => ({...s, expanded: false}))
|
||||||
console.log('### this.orders', this.orders)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateOrderShipped: async function () {
|
updateOrderShipped: async function () {
|
||||||
console.log('### order', this.selectedOrder)
|
|
||||||
this.selectedOrder.shipped = !this.selectedOrder.shipped
|
this.selectedOrder.shipped = !this.selectedOrder.shipped
|
||||||
try {
|
try {
|
||||||
await LNbits.api.request(
|
await LNbits.api.request(
|
||||||
|
|
@ -128,6 +126,9 @@ async function orderList(path) {
|
||||||
// do not change the status yet
|
// do not change the status yet
|
||||||
this.selectedOrder.shipped = !order.shipped
|
this.selectedOrder.shipped = !order.shipped
|
||||||
this.showShipDialog = true
|
this.showShipDialog = true
|
||||||
|
},
|
||||||
|
customerSelected: function (customerPubkey) {
|
||||||
|
this.$emit('customer-selected', customerPubkey)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: async function () {
|
created: async function () {
|
||||||
|
|
|
||||||
|
|
@ -102,13 +102,11 @@ async function shippingZones(path) {
|
||||||
this.inkey
|
this.inkey
|
||||||
)
|
)
|
||||||
this.zones = data
|
this.zones = data
|
||||||
console.log('### data', data)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sendZoneFormData: async function () {
|
sendZoneFormData: async function () {
|
||||||
console.log('### data', this.zoneDialog.data)
|
|
||||||
this.zoneDialog.showDialog = false
|
this.zoneDialog.showDialog = false
|
||||||
if (this.zoneDialog.data.id) {
|
if (this.zoneDialog.data.id) {
|
||||||
await this.updateShippingZone(this.zoneDialog.data)
|
await this.updateShippingZone(this.zoneDialog.data)
|
||||||
|
|
@ -118,7 +116,6 @@ async function shippingZones(path) {
|
||||||
await this.getZones()
|
await this.getZones()
|
||||||
},
|
},
|
||||||
createShippingZone: async function (newZone) {
|
createShippingZone: async function (newZone) {
|
||||||
console.log('### newZone', newZone)
|
|
||||||
try {
|
try {
|
||||||
await LNbits.api.request(
|
await LNbits.api.request(
|
||||||
'POST',
|
'POST',
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,7 @@
|
||||||
:adminkey="adminkey"
|
:adminkey="adminkey"
|
||||||
:inkey="inkey"
|
:inkey="inkey"
|
||||||
:stall-id="stallId"
|
:stall-id="stallId"
|
||||||
|
@customer-selected="customerSelectedForOrder"
|
||||||
></order-list>
|
></order-list>
|
||||||
</div>
|
</div>
|
||||||
</q-tab-panel>
|
</q-tab-panel>
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,6 @@ async function stallDetails(path) {
|
||||||
this.inkey
|
this.inkey
|
||||||
)
|
)
|
||||||
this.stall = this.mapStall(data)
|
this.stall = this.mapStall(data)
|
||||||
|
|
||||||
console.log('### this.stall', this.stall)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
|
|
@ -197,8 +195,6 @@ async function stallDetails(path) {
|
||||||
this.inkey
|
this.inkey
|
||||||
)
|
)
|
||||||
this.products = data
|
this.products = data
|
||||||
|
|
||||||
console.log('### this.products', this.products)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
|
|
@ -305,6 +301,9 @@ async function stallDetails(path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.productDialog.showDialog = true
|
this.productDialog.showDialog = true
|
||||||
|
},
|
||||||
|
customerSelectedForOrder: function (customerPubkey) {
|
||||||
|
this.$emit('customer-selected-for-order', customerPubkey)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: async function () {
|
created: async function () {
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,7 @@
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
<q-td key="id" :props="props">
|
<q-td key="id" :props="props">
|
||||||
<a style="color: unset" :href="props.row.id" target="_blank">
|
{{props.row.name}}
|
||||||
{{props.row.name}}</a
|
|
||||||
>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td key="currency" :props="props"> {{props.row.currency}} </q-td>
|
<q-td key="currency" :props="props"> {{props.row.currency}} </q-td>
|
||||||
<q-td key="description" :props="props">
|
<q-td key="description" :props="props">
|
||||||
|
|
@ -74,6 +72,7 @@
|
||||||
:currencies="currencies"
|
:currencies="currencies"
|
||||||
@stall-deleted="handleStallDeleted"
|
@stall-deleted="handleStallDeleted"
|
||||||
@stall-updated="handleStallUpdated"
|
@stall-updated="handleStallUpdated"
|
||||||
|
@customer-selected-for-order="customerSelectedForOrder"
|
||||||
></stall-details>
|
></stall-details>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,9 @@ async function stallList(path) {
|
||||||
shippingZones: []
|
shippingZones: []
|
||||||
}
|
}
|
||||||
this.stallDialog.show = true
|
this.stallDialog.show = true
|
||||||
|
},
|
||||||
|
customerSelectedForOrder: function (customerPubkey) {
|
||||||
|
this.$emit('customer-selected-for-order', customerPubkey)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: async function () {
|
created: async function () {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ const merchant = async () => {
|
||||||
return {
|
return {
|
||||||
merchant: {},
|
merchant: {},
|
||||||
shippingZones: [],
|
shippingZones: [],
|
||||||
|
activeChatCustomer: '',
|
||||||
showKeys: false,
|
showKeys: false,
|
||||||
importKeyDialog: {
|
importKeyDialog: {
|
||||||
show: false,
|
show: false,
|
||||||
|
|
@ -92,6 +93,9 @@ const merchant = async () => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
customerSelectedForOrder: function (customerPubkey) {
|
||||||
|
this.activeChatCustomer = customerPubkey
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: async function () {
|
created: async function () {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
:adminkey="g.user.wallets[0].adminkey"
|
:adminkey="g.user.wallets[0].adminkey"
|
||||||
:inkey="g.user.wallets[0].inkey"
|
:inkey="g.user.wallets[0].inkey"
|
||||||
:wallet-options="g.user.walletOptions"
|
:wallet-options="g.user.walletOptions"
|
||||||
|
@customer-selected-for-order="customerSelectedForOrder"
|
||||||
></stall-list>
|
></stall-list>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -114,6 +115,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div v-if="merchant && merchant.id" class="col-12">
|
<div v-if="merchant && merchant.id" class="col-12">
|
||||||
<direct-messages
|
<direct-messages
|
||||||
|
:active-public-key="activeChatCustomer"
|
||||||
:inkey="g.user.wallets[0].inkey"
|
:inkey="g.user.wallets[0].inkey"
|
||||||
:adminkey="g.user.wallets[0].adminkey"
|
:adminkey="g.user.wallets[0].adminkey"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
36
views_api.py
36
views_api.py
|
|
@ -39,6 +39,8 @@ from .crud import (
|
||||||
get_orders_for_stall,
|
get_orders_for_stall,
|
||||||
get_product,
|
get_product,
|
||||||
get_products,
|
get_products,
|
||||||
|
get_public_keys_for_direct_messages,
|
||||||
|
get_public_keys_for_orders,
|
||||||
get_stall,
|
get_stall,
|
||||||
get_stalls,
|
get_stalls,
|
||||||
get_zone,
|
get_zone,
|
||||||
|
|
@ -643,14 +645,11 @@ async def api_update_order_status(
|
||||||
try:
|
try:
|
||||||
assert data.shipped != None, "Shipped value is required for order"
|
assert data.shipped != None, "Shipped value is required for order"
|
||||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||||
assert merchant, "Merchant cannot be found"
|
assert merchant, "Merchant cannot be found for order {data.id}"
|
||||||
|
|
||||||
order = await update_order_shipped_status(merchant.id, data.id, data.shipped)
|
order = await update_order_shipped_status(merchant.id, data.id, data.shipped)
|
||||||
assert order, "Cannot find updated order"
|
assert order, "Cannot find updated order"
|
||||||
|
|
||||||
merchant = await get_merchant_for_user(merchant.id)
|
|
||||||
assert merchant, f"Merchant cannot be found for order {data.id}"
|
|
||||||
|
|
||||||
data.paid = order.paid
|
data.paid = order.paid
|
||||||
dm_content = json.dumps(data.dict(), separators=(",", ":"), ensure_ascii=False)
|
dm_content = json.dumps(data.dict(), separators=(",", ":"), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
@ -727,6 +726,35 @@ async def api_create_message(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
######################################## CUSTOMERS ########################################
|
||||||
|
|
||||||
|
|
||||||
|
@nostrmarket_ext.get("/api/v1/customers")
|
||||||
|
async def api_create_message(
|
||||||
|
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||||
|
) -> DirectMessage:
|
||||||
|
try:
|
||||||
|
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||||
|
assert merchant, f"Merchant cannot be found"
|
||||||
|
|
||||||
|
dm_pubkeys = await get_public_keys_for_direct_messages(merchant.id)
|
||||||
|
orders_pubkeys = await get_public_keys_for_orders(merchant.id)
|
||||||
|
|
||||||
|
return list(dict.fromkeys(dm_pubkeys + orders_pubkeys))
|
||||||
|
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
|
except Exception as ex:
|
||||||
|
logger.warning(ex)
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Cannot create message",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
######################################## OTHER ########################################
|
######################################## OTHER ########################################
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue