feat: enhance purchase intentions with chat integration and offer tracking

- Added MongoDB chat/message integration for seller responses
- Improved seller response validation and default messaging
- Integrated automatic chat creation/update when responding to intentions
- Added highest custom offer fields to listing queries and models
- Enhanced listing data with top offer information for buyers
This commit is contained in:
Evandro Fonseca Junior committed 2025-11-08 11:51:21 -03:00
1 parent d27526e026
commit d8e7d5d7e6
19 files changed
+806 -58

No files matched your search

+15 -9
View File
@@ -43,6 +43,9 @@ export interface PurchaseIntention {
buyer_id: number;
payment_method: string;
payment_method_change_count: number;
custom_offer_amount: number | string | null;
custom_offer_currency: string | null;
custom_offer_created_at: Date | string | null;
chat_id: string | null;
status: PurchaseIntentionStatus;
buyer_message: string | null;
@@ -61,17 +64,12 @@ interface PurchaseIntentionsResponse {
count: number;
}
/**
* Hook para buscar intenções de compra do usuário autenticado
* Atualiza automaticamente a cada 30 segundos
*/
export function useMyPurchaseIntentions(status?: PurchaseIntentionStatus) {
export function useMyPurchaseIntentions() {
const queryParams = new URLSearchParams();
if (status) queryParams.set("status", status);
queryParams.set("limit", "100"); // Limite alto para mostrar todas
queryParams.set("limit", "100");
const { data, isLoading, error, refetch } = useQuery<PurchaseIntentionsResponse>({
queryKey: ["my-purchase-intentions", status],
queryKey: ["my-purchase-intentions"],
queryFn: async () => {
const res = await fetch(`/api/purchase-intentions/my?${queryParams.toString()}`);
if (!res.ok) {
@@ -89,8 +87,16 @@ export function useMyPurchaseIntentions(status?: PurchaseIntentionStatus) {
enabled: true, // Sempre habilitado (autenticação é verificada no backend)
});
const normalizedIntentions = (data?.intentions || []).map((intention) => ({
...intention,
custom_offer_amount:
intention.custom_offer_amount !== null && intention.custom_offer_amount !== undefined
? Number(intention.custom_offer_amount)
: null,
}));
return {
intentions: data?.intentions || [],
intentions: normalizedIntentions,
count: data?.count || 0,
isLoading,
error,