simplify and automate offer creation

This commit is contained in:
ntr committed 2022-09-02 00:06:51 +10:00
1 parent 7ea2c37116
commit a43d4f32e4
10 files changed
+97 -67

No files matched your search

+1 -41
View File
@@ -37,46 +37,6 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
const router = koaRouter();
interface ListingData extends Listing {
data: any,
want: { user: User },
};
async function getBundles() {
const bundles = await pg.bundleCandidates();
return bundles.map((b: ListingData[]) => {
const total = b.reduce((acc, l) => acc + l.data.price.value, 0);
const items = b.map(l => ({
id: l.data.id,
description: l.data.release.description,
originalPrice: l.data.original_price.value,
originalCurrency: l.data.original_price.curr_abbr,
price: l.data.price.value,
currency: l.data.price.currency,
condition: l.data.condition,
uri: l.data.uri,
user: l.want.user,
}));
const shipping = b[0]?.data.seller.shipping;
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'),
}
return bundle;
});
}
function listen() {
return new Promise((resolve, reject) => {
app.on('error', err => {
@@ -105,7 +65,7 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
});
router.get('/acp/bundles', async function bundlesGet(ctx, next) {
const bundles = await getBundles();
const bundles = await offers.bundles();
ctx.response.body = bundles;
})