feat: add admin inventory JSON export
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-10 00:16:04 -04:00
parent 099ec2fe72
commit d3821e9c76
10 changed files with 176 additions and 15 deletions
@@ -0,0 +1,29 @@
import { createApplicationError } from '../../../shared/errors/application-error.js';
export async function registerAdminExportRoutes(app, options) {
const {
adminExportService,
authenticateAdmin = async () => {
throw createApplicationError('UNAUTHORIZED', 'Authentication is required.', 401);
},
} = options;
app.addHook('preHandler', async (request) => {
const admin = await authenticateAdmin(request);
if (!admin?.sellerId) {
throw createApplicationError('UNAUTHORIZED', 'Authentication is required.', 401);
}
request.admin = admin;
});
app.get('/exports/inventory.json', async (request, reply) => {
const data = await adminExportService.inventoryJson({
sellerId: request.admin.sellerId,
});
return reply
.type('application/json; charset=utf-8')
.header('content-disposition', 'attachment; filename="inventory.json"')
.send(JSON.stringify(data));
});
}
@@ -0,0 +1,10 @@
import { toAdminInventoryItemDto } from '@pokemon-inventory/contracts/inventory';
export function createAdminExportService({ inventoryItemService }) {
return {
async inventoryJson({ sellerId }) {
const inventoryItems = await inventoryItemService.listBySellerId(sellerId);
return inventoryItems.map(toAdminInventoryItemDto);
},
};
}