feat: add admin image management
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-08 22:12:30 -04:00
parent 9704c2db02
commit efeca42d0f
5 changed files with 221 additions and 0 deletions
@@ -77,4 +77,61 @@ export async function registerAdminImageRoutes(app, options) {
return reply.code(201).send({ data: toAdminInventoryImageDto(image) });
});
async function authorizeAdminMutation(request) {
const admin = await authenticateAdmin(request);
if (!admin?.sellerId) {
throw createApplicationError('UNAUTHORIZED', 'Authentication is required.', 401);
}
await authorizeUnsafeRequest?.(
request.cookies[sessionCookieName],
request.headers['x-csrf-token'],
);
return admin;
}
app.patch('/images/:id/order', async (request) => {
const admin = await authorizeAdminMutation(request);
const image = await inventoryImageService.updateOrder({
imageId: request.params.id,
sortOrder: request.body?.sortOrder,
sellerId: admin.sellerId,
});
return { data: toAdminInventoryImageDto(image) };
});
app.post('/images/:id/primary', async (request) => {
const admin = await authorizeAdminMutation(request);
const image = await inventoryImageService.setPrimary({
imageId: request.params.id,
sellerId: admin.sellerId,
});
return { data: toAdminInventoryImageDto(image) };
});
app.patch('/images/:id/alt-text', async (request) => {
const admin = await authorizeAdminMutation(request);
const image = await inventoryImageService.updateAltText({
imageId: request.params.id,
altText: request.body?.altText ?? null,
sellerId: admin.sellerId,
});
return { data: toAdminInventoryImageDto(image) };
});
app.post('/images/:id/retry', async (request) => {
const admin = await authorizeAdminMutation(request);
const image = await inventoryImageService.retry({
imageId: request.params.id,
sellerId: admin.sellerId,
});
return { data: toAdminInventoryImageDto(image) };
});
app.delete('/images/:id', async (request, reply) => {
const admin = await authorizeAdminMutation(request);
await inventoryImageService.delete({ imageId: request.params.id, sellerId: admin.sellerId });
return reply.code(204).send();
});
}