simplify and automate offer creation
This commit is contained in:
1 parent
7ea2c37116
commit
a43d4f32e4
10 files changed
+97
-67
No files matched your search
+46
-2
@@ -19,9 +19,11 @@ export default function createOffers(log: Log, pg: Pg) {
|
||||
log.info('generateOffers', { listingIds, bulkShipping, baseShipping });
|
||||
const listings = await pg.listingByIds(listingIds);
|
||||
|
||||
log.info({ listings }, 'creating offers for listings')
|
||||
// log.info({ listings }, 'creating offers for listings')
|
||||
|
||||
const shipping = bulkShipping / listings.length;
|
||||
const shipping = 10 + Math.random(); // yolt
|
||||
|
||||
// const shipping = bulkShipping / listings.length;
|
||||
// how to deal with users who don't want all items in a bundle...
|
||||
|
||||
const offers = listings.map(l => ({
|
||||
@@ -60,8 +62,50 @@ export default function createOffers(log: Log, pg: Pg) {
|
||||
return pg.offerSetStatus(offer.id, Status.Accepted);
|
||||
}
|
||||
|
||||
async function bundles() {
|
||||
const bundles = await pg.bundleCandidates();
|
||||
|
||||
interface ListingData extends Listing {
|
||||
data: any,
|
||||
want: { user: User },
|
||||
};
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
generate,
|
||||
accept,
|
||||
bundles,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user