This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
toAdminMarketValuationDto,
|
||||
toAdminMarketValuationSummaryDto,
|
||||
toAdminPricingObservationDto,
|
||||
} from "@pokemon-inventory/contracts/pricing";
|
||||
import {
|
||||
@@ -91,6 +92,14 @@ export async function registerAdminPricingRoutes(app, options) {
|
||||
return reply.code(201).send({ data: override });
|
||||
});
|
||||
|
||||
app.get("/valuations", async (request) => ({
|
||||
data: (
|
||||
await pricingService.listValuations({
|
||||
sellerId: request.admin.sellerId,
|
||||
})
|
||||
).map(toAdminMarketValuationSummaryDto),
|
||||
}));
|
||||
|
||||
app.post("/inventory/:id/pricing/refresh", async (request, reply) => {
|
||||
await authorizeUnsafeRequest?.(
|
||||
request.cookies[sessionCookieName],
|
||||
|
||||
@@ -203,6 +203,10 @@ export function createPricingService({
|
||||
return pricingRefreshJobRepository?.listForSeller(sellerId) ?? [];
|
||||
},
|
||||
|
||||
async listValuations({ sellerId }) {
|
||||
return pricingRepository.listLatestValuationsForSeller(sellerId);
|
||||
},
|
||||
|
||||
async retryJob({ sellerId, jobId }) {
|
||||
const job = await pricingRefreshJobRepository?.retryForSeller(
|
||||
jobId,
|
||||
|
||||
@@ -182,3 +182,38 @@ test("lists jobs and retries a failed job with CSRF protection", async (testCont
|
||||
assert.equal(retryResponse.statusCode, 202);
|
||||
assert.equal(csrfChecks, 1);
|
||||
});
|
||||
|
||||
test("lists seller-scoped latest market valuations", async (testContext) => {
|
||||
const app = buildApp({
|
||||
authenticateAdmin: async () => ({ sellerId: "seller-1" }),
|
||||
pricingService: {
|
||||
async listValuations({ sellerId }) {
|
||||
assert.equal(sellerId, "seller-1");
|
||||
return [
|
||||
{
|
||||
id: "valuation-1",
|
||||
inventoryItemId: "item-1",
|
||||
valueMinor: 2500,
|
||||
currency: "USD",
|
||||
strategy: "MEDIAN",
|
||||
confidence: "MEDIUM",
|
||||
sourceCount: 2,
|
||||
calculatedAt: new Date().toISOString(),
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
});
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const response = await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/v1/admin/valuations",
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
const [valuation] = response.json().data;
|
||||
assert.equal(valuation.inventoryItemId, "item-1");
|
||||
assert.equal(valuation.valueMinor, 2500);
|
||||
assert.equal(valuation.stale, false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user