This commit is contained in:
NotII
2025-03-10 17:39:37 +00:00
parent c08df8919d
commit 20d5559832
69 changed files with 7676 additions and 78 deletions

View File

@@ -0,0 +1,39 @@
// Handle notifications from Telegram to vendors
export const notifyVendor = async (req, res) => {
try {
const { buyerId, storeId, message, source } = req.body;
if (!buyerId || !storeId || !message) {
return res.status(400).json({ error: "Missing required parameters" });
}
// Find the store and check if it exists
const store = await Store.findById(storeId);
if (!store) {
logger.warn("Store not found for vendor notification", { storeId });
return res.status(404).json({ error: "Store not found" });
}
// Get the vendor
const vendor = await Vendor.findById(store.vendorId);
if (!vendor) {
logger.warn("Vendor not found for notification", { storeId, vendorId: store.vendorId });
return res.status(404).json({ error: "Vendor not found" });
}
// Future enhancement: could implement WebSocket/Server-Sent Events for real-time notifications
// For now, we'll just track that the notification was processed
logger.info("Processed vendor notification", {
buyerId,
storeId,
vendorId: vendor._id,
source: source || "unknown"
});
return res.status(200).json({ success: true });
} catch (error) {
logger.error("Error processing vendor notification", { error: error.message, stack: error.stack });
return res.status(500).json({ error: "Server error processing notification" });
}
};