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:
1 parent
d27526e026
commit
d8e7d5d7e6
19 files changed
+806
-58
No files matched your search
@@ -5,6 +5,10 @@
|
||||
|
||||
import { prisma } from "../app";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import {
|
||||
getHighestCustomOfferForListing,
|
||||
getHighestCustomOffersForListings,
|
||||
} from "./purchase-intentions";
|
||||
|
||||
// Re-exportar tipos para compatibilidade
|
||||
export type ListingStatus = "active" | "sold" | "cancelled" | "in_escrow" | "expired";
|
||||
@@ -42,6 +46,8 @@ export interface Listing {
|
||||
initial_price_tibia_coins?: number | null;
|
||||
initial_price_gold_coins?: number | null;
|
||||
seller_character_name?: string | null;
|
||||
highest_custom_offer_amount?: number | null;
|
||||
highest_custom_offer_currency?: string | null;
|
||||
}
|
||||
|
||||
export interface CreateListingData {
|
||||
@@ -141,6 +147,8 @@ export async function createListing(
|
||||
price_gold_coins: listing.price_gold_coins ? Number(listing.price_gold_coins) : null,
|
||||
initial_price_gold_coins: listing.initial_price_gold_coins ? Number(listing.initial_price_gold_coins) : null,
|
||||
seller_character_name: character?.character_name || null,
|
||||
highest_custom_offer_amount: null,
|
||||
highest_custom_offer_currency: null,
|
||||
} as Listing;
|
||||
}
|
||||
|
||||
@@ -165,6 +173,8 @@ export async function getListingById(listingId: number): Promise<Listing | null>
|
||||
},
|
||||
});
|
||||
|
||||
const highestOffer = await getHighestCustomOfferForListing(listingId);
|
||||
|
||||
// Converter todos os campos Decimal e BigInt para números JavaScript
|
||||
return {
|
||||
...listing,
|
||||
@@ -175,6 +185,8 @@ export async function getListingById(listingId: number): Promise<Listing | null>
|
||||
price_gold_coins: listing.price_gold_coins ? Number(listing.price_gold_coins) : null,
|
||||
initial_price_gold_coins: listing.initial_price_gold_coins ? Number(listing.initial_price_gold_coins) : null,
|
||||
seller_character_name: character?.character_name || null,
|
||||
highest_custom_offer_amount: highestOffer?.amount ?? null,
|
||||
highest_custom_offer_currency: highestOffer?.currency ?? null,
|
||||
} as Listing;
|
||||
}
|
||||
|
||||
@@ -264,9 +276,14 @@ export async function getListings(
|
||||
}
|
||||
}
|
||||
|
||||
const highestOffers = await getHighestCustomOffersForListings(
|
||||
listings.map((listing) => listing.listing_id)
|
||||
);
|
||||
|
||||
// Converter todos os campos Decimal e BigInt para números JavaScript
|
||||
const listingsWithCharacterNames = listings.map((listing) => {
|
||||
const key = `${listing.seller_id}:${listing.server_name}`;
|
||||
const highestOffer = highestOffers.get(listing.listing_id);
|
||||
return {
|
||||
...listing,
|
||||
price_pix: listing.price_pix ? Number(listing.price_pix) : null,
|
||||
@@ -276,6 +293,8 @@ export async function getListings(
|
||||
price_gold_coins: listing.price_gold_coins ? Number(listing.price_gold_coins) : null,
|
||||
initial_price_gold_coins: listing.initial_price_gold_coins ? Number(listing.initial_price_gold_coins) : null,
|
||||
seller_character_name: charactersMap.get(key) || null,
|
||||
highest_custom_offer_amount: highestOffer?.amount ?? null,
|
||||
highest_custom_offer_currency: highestOffer?.currency ?? null,
|
||||
} as Listing;
|
||||
});
|
||||
|
||||
@@ -319,6 +338,8 @@ export async function updateListing(
|
||||
},
|
||||
});
|
||||
|
||||
const highestOffer = await getHighestCustomOfferForListing(listing.listing_id);
|
||||
|
||||
// Converter todos os campos Decimal e BigInt para números JavaScript
|
||||
return {
|
||||
...listing,
|
||||
@@ -329,6 +350,8 @@ export async function updateListing(
|
||||
price_gold_coins: listing.price_gold_coins ? Number(listing.price_gold_coins) : null,
|
||||
initial_price_gold_coins: listing.initial_price_gold_coins ? Number(listing.initial_price_gold_coins) : null,
|
||||
seller_character_name: character?.character_name || null,
|
||||
highest_custom_offer_amount: highestOffer?.amount ?? null,
|
||||
highest_custom_offer_currency: highestOffer?.currency ?? null,
|
||||
} as Listing;
|
||||
}
|
||||
|
||||
@@ -486,9 +509,14 @@ export async function getActiveListings(
|
||||
}
|
||||
}
|
||||
|
||||
const highestOffers = await getHighestCustomOffersForListings(
|
||||
listings.map((listing) => listing.listing_id)
|
||||
);
|
||||
|
||||
// Converter todos os campos Decimal e BigInt para números JavaScript
|
||||
const listingsWithCharacterNames = listings.map((listing) => {
|
||||
const key = `${listing.seller_id}:${listing.server_name}`;
|
||||
const highestOffer = highestOffers.get(listing.listing_id);
|
||||
return {
|
||||
...listing,
|
||||
price_pix: listing.price_pix ? Number(listing.price_pix) : null,
|
||||
@@ -498,6 +526,8 @@ export async function getActiveListings(
|
||||
price_gold_coins: listing.price_gold_coins ? Number(listing.price_gold_coins) : null,
|
||||
initial_price_gold_coins: listing.initial_price_gold_coins ? Number(listing.initial_price_gold_coins) : null,
|
||||
seller_character_name: charactersMap.get(key) || null,
|
||||
highest_custom_offer_amount: highestOffer?.amount ?? null,
|
||||
highest_custom_offer_currency: highestOffer?.currency ?? null,
|
||||
} as Listing;
|
||||
});
|
||||
|
||||
@@ -580,6 +610,8 @@ export async function placeBid(
|
||||
price_gold_coins: updatedListing.price_gold_coins ? Number(updatedListing.price_gold_coins) : null,
|
||||
initial_price_gold_coins: updatedListing.initial_price_gold_coins ? Number(updatedListing.initial_price_gold_coins) : null,
|
||||
seller_character_name: character?.character_name || null,
|
||||
highest_custom_offer_amount: null,
|
||||
highest_custom_offer_currency: null,
|
||||
} as Listing,
|
||||
previousBidderId: previousBidderId || undefined,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user