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

+28 -1
View File
@@ -11,9 +11,10 @@ import routerAuth from './routers/router.auth';
export enum Events {
WantsAdded = 'WantsAdded',
StartupSync = 'StartupSync',
ListingsUpdated = 'ListingsUpdated',
}
export default function createEvents(log: Log, pg: Pg, discogs) {
export default function createEvents(log: Log, pg: Pg, discogs, offers) {
const events = new EventEmitter({ captureRejections: true });
events.on('error', function eventError(e) {
@@ -50,5 +51,31 @@ export default function createEvents(log: Log, pg: Pg, discogs) {
});
events.on(Events.ListingsUpdated, async function listingsUpdated() {
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);
const updatedOffers = await offers.generate(listingIds, 100, 30)
log.info({ offers: updatedOffers.length }, 'offers set');
}
log.info('offers up to date');
});
return events;
}