This commit is contained in:
@@ -17,6 +17,8 @@ import {
|
||||
marketValueOverrides,
|
||||
marketValuations,
|
||||
products,
|
||||
sellers,
|
||||
sellerSettings,
|
||||
} from "../../../infrastructure/database/schema.js";
|
||||
|
||||
export function createListingRepository(db) {
|
||||
@@ -220,7 +222,12 @@ export function createListingRepository(db) {
|
||||
|
||||
async findPublicById(listingId) {
|
||||
const [result] = await db
|
||||
.select({ listing: listings, condition: conditions })
|
||||
.select({
|
||||
listing: listings,
|
||||
condition: conditions,
|
||||
sellerDisplayName: sellers.displayName,
|
||||
sellerSettings: sellerSettings.settings,
|
||||
})
|
||||
.from(listings)
|
||||
.innerJoin(
|
||||
inventoryItems,
|
||||
@@ -228,6 +235,8 @@ export function createListingRepository(db) {
|
||||
)
|
||||
.innerJoin(products, eq(products.id, inventoryItems.productId))
|
||||
.innerJoin(conditions, eq(conditions.id, inventoryItems.conditionId))
|
||||
.innerJoin(sellers, eq(sellers.id, products.sellerId))
|
||||
.leftJoin(sellerSettings, eq(sellerSettings.sellerId, sellers.id))
|
||||
.where(
|
||||
and(
|
||||
eq(listings.id, listingId),
|
||||
@@ -263,6 +272,9 @@ export function createListingRepository(db) {
|
||||
marketValueMinor: override?.valueMinor ?? valuation?.valueMinor ?? null,
|
||||
marketValueCurrency: override?.currency ?? valuation?.currency ?? null,
|
||||
marketValueUpdatedAt: override?.createdAt ?? valuation?.calculatedAt ?? null,
|
||||
sellerDisplayName: result.sellerDisplayName,
|
||||
sellerContactEmail: result.sellerSettings?.general?.publicContactEmail ?? null,
|
||||
sellerContactPhone: result.sellerSettings?.general?.publicContactPhone ?? null,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
inventoryItems,
|
||||
listings,
|
||||
products,
|
||||
sellers,
|
||||
sellerSettings,
|
||||
} from '../../../infrastructure/database/schema.js';
|
||||
|
||||
export function createProductRepository(db) {
|
||||
@@ -24,10 +26,16 @@ export function createProductRepository(db) {
|
||||
|
||||
async findPublicBySlug(slug) {
|
||||
const [result] = await db
|
||||
.select({ product: products })
|
||||
.select({
|
||||
product: products,
|
||||
sellerDisplayName: sellers.displayName,
|
||||
sellerSettings: sellerSettings.settings,
|
||||
})
|
||||
.from(products)
|
||||
.innerJoin(inventoryItems, eq(inventoryItems.productId, products.id))
|
||||
.innerJoin(listings, eq(listings.inventoryItemId, inventoryItems.id))
|
||||
.innerJoin(sellers, eq(sellers.id, products.sellerId))
|
||||
.leftJoin(sellerSettings, eq(sellerSettings.sellerId, sellers.id))
|
||||
.where(and(
|
||||
eq(products.slug, slug),
|
||||
eq(inventoryItems.status, 'ACTIVE'),
|
||||
@@ -35,7 +43,13 @@ export function createProductRepository(db) {
|
||||
))
|
||||
.limit(1);
|
||||
|
||||
return result?.product ?? null;
|
||||
if (!result) return null;
|
||||
return {
|
||||
...result.product,
|
||||
sellerDisplayName: result.sellerDisplayName,
|
||||
sellerContactEmail: result.sellerSettings?.general?.publicContactEmail ?? null,
|
||||
sellerContactPhone: result.sellerSettings?.general?.publicContactPhone ?? null,
|
||||
};
|
||||
},
|
||||
|
||||
async findBySellerIdAndSlug(sellerId, slug) {
|
||||
|
||||
Reference in New Issue
Block a user