fix: validate image order and alt text updates
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-11 00:18:11 -04:00
parent 0e81fc4022
commit cce395baf6
11 changed files with 169 additions and 14 deletions
@@ -1,5 +1,5 @@
import { toAdminInventoryImageDto } from '@pokemon-inventory/contracts/image';
import { createInventoryImageSchema, moveInventoryImageSchema } from '@pokemon-inventory/validation/image';
import { createInventoryImageSchema, moveInventoryImageSchema, updateImageOrderSchema, updateImageAltTextSchema } from '@pokemon-inventory/validation/image';
import { randomUUID } from 'node:crypto';
import { createApplicationError } from '../../../shared/errors/application-error.js';
@@ -110,11 +110,13 @@ export async function registerAdminImageRoutes(app, options) {
return { data: toAdminInventoryImageDto(image) };
});
app.patch('/images/:id/order', async (request) => {
app.patch('/images/:id/order', async (request, reply) => {
const admin = await authorizeAdminMutation(request);
const result = updateImageOrderSchema.safeParse(request.body);
if (!result.success) return validationError(reply, result);
const image = await inventoryImageService.updateOrder({
imageId: request.params.id,
sortOrder: request.body?.sortOrder,
sortOrder: result.data.sortOrder,
sellerId: admin.sellerId,
});
return { data: toAdminInventoryImageDto(image) };
@@ -129,11 +131,13 @@ export async function registerAdminImageRoutes(app, options) {
return { data: toAdminInventoryImageDto(image) };
});
app.patch('/images/:id/alt-text', async (request) => {
app.patch('/images/:id/alt-text', async (request, reply) => {
const admin = await authorizeAdminMutation(request);
const result = updateImageAltTextSchema.safeParse(request.body);
if (!result.success) return validationError(reply, result);
const image = await inventoryImageService.updateAltText({
imageId: request.params.id,
altText: request.body?.altText ?? null,
altText: result.data.altText,
sellerId: admin.sellerId,
});
return { data: toAdminInventoryImageDto(image) };