remove unused api methods

This commit is contained in:
ntr committed 2022-09-16 21:48:14 +10:00
1 parent 73248f7d9f
commit acf7e54be9
10 files changed
+23 -201

No files matched your search

-42
View File
@@ -59,48 +59,6 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
ctx.status = 200;
});
router.get('/acp/bundles', async function bundlesGet(ctx, next) {
const bundles = await offers.bundles();
ctx.response.body = bundles;
})
router.get('/acp/offers', async function acpOffers(ctx, next) {
const offers = await pg.offersAdmin();
const grouped = groupBy(offers, o => o.listing.data.seller.id);
const bundles = sortBy(Object.values(grouped).map(offers => {
const shipping = offers[0]?.listing.data.seller.shipping;
const bundle = {
username: offers[0]?.listing.data.seller.username,
seller: offers[0]?.listing.data.seller.id,
shipsFrom: offers[0]?.listing.data.ships_from,
shipping,
offers,
mentionsAustralia: shipping.toLowerCase().includes('australia'),
mentionsWorldwide: shipping.toLowerCase().includes('world'),
}
return bundle;
}), bundle => -bundle.offers.length);
ctx.response.body = bundles;
})
router.post('/offers', async function postOffers(ctx, next) {
const { listingIds, shipping, baseShipping } = ctx.request.body;
ctx.assert(listingIds.length, 400, 'listingIds required');
ctx.assert([listingIds, shipping, baseShipping].every(i => i), 400, 'listingIds, shipping, baseShipping required');
ctx.response.body = await offers.generate(listingIds, shipping, baseShipping);
})
router.post('/offer/accept', async function postOffers(ctx, next) {
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
ctx.response.body = await offers.accept(ctx);
})
router.get('/user/offers', async function userOffersGet(ctx, next) {
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
const user = ctx.state.user;
-12
View File
@@ -62,18 +62,6 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) {
const bundles = await offers.bundles();
log.info({ event: Events.ListingsUpdated, bundles: bundles.length });
// const bundle = {
// username: b[0]?.data.seller.username,
// seller: b[0]?.data.seller.id,
// shipsFrom: b[0]?.data.ships_from,
// total,
// currency: b[0]?.data.price.currency,
// shipping: '...',
// items,
// mentionsAustralia: shipping.toLowerCase().includes('australia'),
// mentionsWorldwide: shipping.toLowerCase().includes('world'),
// }
for (const bundle of bundles) {
log.info({ seller: bundle.seller, items: bundle.items.length }, 'generating offers...');
const listingIds = bundle.items.map(i => i.id);
+12 -2
View File
@@ -23,6 +23,10 @@ export default function createRpc(log: Log, pg: Pg, user: User, ws, discogs, off
return [RpcMessageType.Pong, []];
}
async function userOffers(): Promise<OffersMessage> {
return [RpcMessageType.Offers, await pg.userOffers(user)];
}
async function offerStatusSet(params: OfferStatusSetParams): Promise<OffersMessage> {
const { id, status } = params;
assert(id, 'no id supplied');
@@ -70,14 +74,20 @@ export default function createRpc(log: Log, pg: Pg, user: User, ws, discogs, off
switch (msgType) {
case RpcMessageType.Ping:
return ping();
case RpcMessageType.Offers:
return userOffers();
case RpcMessageType.OfferStatusSet:
return offerStatusSet(params);
case RpcMessageType.WantRm:
return wantRm(params);
case RpcMessageType.AcpOfferStatusSet:
return acpOfferStatusSet(params);
case RpcMessageType.AcpOffers:
return acpOffers();
case RpcMessageType.WantRm:
return wantRm(params);
default:
throw new Error(`Message type ${msgType} is known but unhandled`);
}