acp stuff

This commit is contained in:
ntr committed 2022-08-23 23:35:25 +10:00
1 parent deb9eb3fc2
commit 047f606e83
14 files changed
+368 -44

No files matched your search

+37 -5
View File
@@ -6,7 +6,7 @@ import session from 'koa-session';
import koaRouter from '@koa/router'
import cors from '@koa/cors';
import { groupBy } from 'lodash';
import { groupBy, sortBy } from 'lodash';
import Bluebird from 'bluebird';
import type Log from 'bunyan';
@@ -104,14 +104,46 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
ctx.status = 200;
});
router.get('/bundles', async (ctx, next) => {
router.get('/acp/bundles', async function bundlesGet(ctx, next) {
const bundles = await getBundles();
ctx.response.body = bundles;
})
router.post('/offers', async (ctx, next) => {
const { seller, shipping, baseShipping } = ctx.request.body;
ctx.response.body = await offers.generate(seller, shipping, baseShipping);
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) {