This commit is contained in:
@@ -25,6 +25,16 @@ export function createInventoryItemRepository(db) {
|
||||
.orderBy(asc(inventoryItems.createdAt));
|
||||
},
|
||||
|
||||
async listBySellerId(sellerId) {
|
||||
return db
|
||||
.select({ item: inventoryItems })
|
||||
.from(inventoryItems)
|
||||
.innerJoin(products, eq(products.id, inventoryItems.productId))
|
||||
.where(eq(products.sellerId, sellerId))
|
||||
.orderBy(asc(inventoryItems.createdAt))
|
||||
.then((rows) => rows.map(({ item }) => item));
|
||||
},
|
||||
|
||||
async searchPublic({ page = 1, limit = 20 } = {}) {
|
||||
const conditions = [
|
||||
eq(inventoryItems.status, 'ACTIVE'),
|
||||
|
||||
@@ -54,4 +54,8 @@ export async function registerAdminInventoryRoutes(app, options) {
|
||||
|
||||
return reply.code(201).send({ data: toAdminInventoryItemDto(inventoryItem) });
|
||||
});
|
||||
|
||||
app.get('/inventory', async (request) => ({
|
||||
data: (await inventoryItemService.listBySellerId(request.admin.sellerId)).map(toAdminInventoryItemDto),
|
||||
}));
|
||||
}
|
||||
@@ -7,6 +7,10 @@ export function createInventoryItemService({
|
||||
productRepository,
|
||||
}) {
|
||||
return {
|
||||
async listBySellerId(sellerId) {
|
||||
return inventoryItemRepository.listBySellerId(sellerId);
|
||||
},
|
||||
|
||||
async create(input) {
|
||||
const inventoryItem = createInventoryItem(input);
|
||||
const [product, condition] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user