feat: connect admin image workflow
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-08 22:16:59 -04:00
parent c382852924
commit a21d1ae854
9 changed files with 120 additions and 0 deletions
@@ -43,6 +43,20 @@ export function createInventoryImageRepository(db) {
return image?.image ?? null;
},
async listByInventoryItemForSeller(inventoryItemId, sellerId) {
return db
.select({ image: inventoryImages })
.from(inventoryImages)
.innerJoin(inventoryItems, eq(inventoryItems.id, inventoryImages.inventoryItemId))
.innerJoin(products, eq(products.id, inventoryItems.productId))
.where(and(
eq(inventoryImages.inventoryItemId, inventoryItemId),
eq(products.sellerId, sellerId),
))
.orderBy(inventoryImages.sortOrder)
.then((rows) => rows.map(({ image }) => image));
},
async updateOrderForSeller(imageId, sortOrder, sellerId) {
const owned = await this.findByIdForSeller(imageId, sellerId);
if (!owned) return null;
@@ -78,6 +78,13 @@ export async function registerAdminImageRoutes(app, options) {
return reply.code(201).send({ data: toAdminInventoryImageDto(image) });
});
app.get('/inventory/:id/images', async (request) => ({
data: (await inventoryImageService.list({
inventoryItemId: request.params.id,
sellerId: (await authenticateAdmin(request)).sellerId,
})).map(toAdminInventoryImageDto),
}));
async function authorizeAdminMutation(request) {
const admin = await authenticateAdmin(request);
if (!admin?.sellerId) {
@@ -23,6 +23,10 @@ export function createInventoryImageService({ inventoryImageRepository, imageDer
return image;
},
async list({ inventoryItemId, sellerId }) {
return inventoryImageRepository.listByInventoryItemForSeller(inventoryItemId, sellerId);
},
async upload(input) {
const { data, ...metadata } = input;
validateInventoryImageMetadata(metadata);