This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user