This commit is contained in:
@@ -20,6 +20,7 @@ import { registerAdminAcquisitionRoutes } from "../modules/acquisitions/routes/a
|
||||
import { registerAdminDashboardRoutes } from "../modules/dashboard/routes/admin-dashboard-routes.js";
|
||||
import { registerAdminPricingRoutes } from "../modules/pricing/routes/admin-pricing-routes.js";
|
||||
import { registerAdminProviderMappingRoutes } from "../modules/pricing/routes/admin-provider-mapping-routes.js";
|
||||
import { registerAdminExportRoutes } from "../modules/exports/routes/admin-export-routes.js";
|
||||
|
||||
export function buildApp(dependencies) {
|
||||
const app = Fastify();
|
||||
@@ -88,6 +89,10 @@ export function buildApp(dependencies) {
|
||||
...dependencies,
|
||||
prefix: "/api/v1/admin",
|
||||
});
|
||||
app.register(registerAdminExportRoutes, {
|
||||
...dependencies,
|
||||
prefix: "/api/v1/admin",
|
||||
});
|
||||
app.register(registerPublicSearchRoutes, {
|
||||
...dependencies,
|
||||
prefix: "/api/v1",
|
||||
|
||||
+18
-15
@@ -52,6 +52,7 @@ import { createProviderMappingService } from "../modules/pricing/services/provid
|
||||
import { createPricingProviderRegistry } from "../modules/pricing/providers/pricing-provider.js";
|
||||
import { createFixturePricingProvider } from "../modules/pricing/providers/fixture-pricing-provider.js";
|
||||
import { createHttpPricingProvider } from "../modules/pricing/providers/http-pricing-provider.js";
|
||||
import { createAdminExportService } from "../modules/exports/services/admin-export-service.js";
|
||||
|
||||
function parsePort(value) {
|
||||
const port = Number.parseInt(value ?? "3000", 10);
|
||||
@@ -101,6 +102,18 @@ async function startServer() {
|
||||
}),
|
||||
);
|
||||
const pricingProviders = createPricingProviderRegistry(providers);
|
||||
const pricingService = createPricingService({
|
||||
pricingRepository,
|
||||
pricingRefreshJobRepository,
|
||||
providerMappingRepository,
|
||||
pricingProviderRegistry: pricingProviders,
|
||||
});
|
||||
const inventoryItemService = createInventoryItemService({
|
||||
conditionRepository,
|
||||
inventoryItemRepository,
|
||||
pricingService,
|
||||
productRepository,
|
||||
});
|
||||
const userRepository = createUserRepository(database.db);
|
||||
const sessionRepository = createSessionRepository(database.db);
|
||||
const passwordResetRepository = createPasswordResetRepository(database.db);
|
||||
@@ -146,10 +159,9 @@ async function startServer() {
|
||||
keyPrefix: "pokemon-inventory:auth:password-reset:",
|
||||
redisClient: redis.client,
|
||||
}),
|
||||
inventoryItemService: createInventoryItemService({
|
||||
conditionRepository,
|
||||
inventoryItemRepository,
|
||||
productRepository,
|
||||
inventoryItemService,
|
||||
adminExportService: createAdminExportService({
|
||||
inventoryItemService,
|
||||
}),
|
||||
catalogLookupRepository,
|
||||
publicImageService,
|
||||
@@ -170,11 +182,7 @@ async function startServer() {
|
||||
acquisitionService: createAcquisitionService({ acquisitionRepository }),
|
||||
dashboardService: createDashboardService({
|
||||
productService: createProductService({ productRepository }),
|
||||
inventoryItemService: createInventoryItemService({
|
||||
conditionRepository,
|
||||
inventoryItemRepository,
|
||||
productRepository,
|
||||
}),
|
||||
inventoryItemService,
|
||||
listingService: createListingService({
|
||||
listingRepository,
|
||||
inventoryImageRepository,
|
||||
@@ -184,12 +192,7 @@ async function startServer() {
|
||||
pricingRepository,
|
||||
pricingRefreshJobRepository,
|
||||
}),
|
||||
pricingService: createPricingService({
|
||||
pricingRepository,
|
||||
pricingRefreshJobRepository,
|
||||
providerMappingRepository,
|
||||
pricingProviderRegistry: pricingProviders,
|
||||
}),
|
||||
pricingService,
|
||||
providerMappingService: createProviderMappingService({
|
||||
providerMappingRepository,
|
||||
}),
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user