feat: add public seller directory
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { and, asc, eq, inArray } from 'drizzle-orm';
|
||||
|
||||
import {
|
||||
inventoryItems,
|
||||
listings,
|
||||
products,
|
||||
sellers,
|
||||
} from '../../../infrastructure/database/schema.js';
|
||||
|
||||
export function createSellerRepository(db) {
|
||||
return {
|
||||
async listPublic() {
|
||||
return db
|
||||
.select({
|
||||
id: sellers.id,
|
||||
displayName: sellers.displayName,
|
||||
createdAt: sellers.createdAt,
|
||||
updatedAt: sellers.updatedAt,
|
||||
})
|
||||
.from(sellers)
|
||||
.innerJoin(products, eq(products.sellerId, sellers.id))
|
||||
.innerJoin(inventoryItems, eq(inventoryItems.productId, products.id))
|
||||
.innerJoin(listings, eq(listings.inventoryItemId, inventoryItems.id))
|
||||
.where(and(
|
||||
eq(inventoryItems.status, 'ACTIVE'),
|
||||
inArray(listings.status, ['AVAILABLE', 'PENDING']),
|
||||
))
|
||||
.groupBy(sellers.id, sellers.displayName, sellers.createdAt, sellers.updatedAt)
|
||||
.orderBy(asc(sellers.displayName));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { toPublicSellerDto } from '@pokemon-inventory/contracts/public-seller';
|
||||
|
||||
export async function registerPublicSellerRoutes(app, options) {
|
||||
const { publicSellerService } = options;
|
||||
|
||||
app.get('/public/sellers', async () => ({
|
||||
data: (await publicSellerService.list()).map(toPublicSellerDto),
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export function createPublicSellerService({ sellerRepository }) {
|
||||
return {
|
||||
async list() {
|
||||
return sellerRepository.listPublic();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user