various styles
This commit is contained in:
1 parent
2761456009
commit
77428aa7de
11 files changed
+111
-52
No files matched your search
+1
-1
@@ -28,7 +28,7 @@ async function start() {
|
||||
events,
|
||||
} = createServices(log);
|
||||
|
||||
// events.emit(Events.StartupSync);
|
||||
events.emit(Events.StartupSync);
|
||||
// events.emit(Events.ListingsUpdated);
|
||||
|
||||
api.listen();
|
||||
|
||||
+2
-2
@@ -72,7 +72,7 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
|
||||
const user = await pg.userFindId(ctx.state.user.id);
|
||||
const release = await discogs.release(releaseId);
|
||||
const want = await pg.wantCreate(release, user);
|
||||
events.emit(Events.WantAdded, want);
|
||||
events.emit(Events.WantsAdded, [want]);
|
||||
ctx.response.body = [want];
|
||||
});
|
||||
|
||||
@@ -81,7 +81,7 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
|
||||
const { username } = ctx.request.body;
|
||||
const user = await pg.userFindId(ctx.state.user.id);
|
||||
const wants = await discogs.wantListSync(username, user);
|
||||
wants.forEach(w => events.emit(Events.WantAdded, w));
|
||||
events.emit(Events.WantsAdded, [wants]);
|
||||
ctx.response.body = wants;
|
||||
});
|
||||
|
||||
|
||||
+1
-3
@@ -84,11 +84,9 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
.get();
|
||||
|
||||
const unlisted = await pg.listingRmUnlisted(want, ids);
|
||||
if (unlisted) log.info({ wantId: want.id, unlisted: unlisted }, 'missing listings removed');
|
||||
if (unlisted) log.info({ unlisted: unlisted, ...wantDetails(want) }, 'missing listings removed');
|
||||
|
||||
// preferentially take listings from sellers if we hit req limits
|
||||
|
||||
log.info({ listings: ids.length, ...wantDetails(want)}, 'found listings');
|
||||
return Bluebird.mapSeries(ids, async id => listing(id, want));
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -9,7 +9,7 @@ import { wantDetails } from './utils';
|
||||
import routerAuth from './routers/router.auth';
|
||||
|
||||
export enum Events {
|
||||
WantAdded = 'WantAdded',
|
||||
WantsAdded = 'WantsAdded',
|
||||
StartupSync = 'StartupSync',
|
||||
ListingsUpdated = 'ListingsUpdated',
|
||||
Connection = 'Connection',
|
||||
@@ -37,26 +37,28 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) {
|
||||
log.error('event error', e);
|
||||
});
|
||||
|
||||
events.on(Events.WantAdded, async function wantAdded(want: Want) {
|
||||
log.info({ event: Events.WantAdded, ...wantDetails(want) });
|
||||
const listings = await populateListings(want);
|
||||
log.info({ listings: listings.length, ...wantDetails(want) }, 'listings added');
|
||||
events.emit(Events.ListingsUpdated);
|
||||
});
|
||||
|
||||
events.on(Events.StartupSync, async function wantAdded() {
|
||||
const wants = await pg.wantsToSync();
|
||||
log.info({ event: Events.StartupSync, wants: wants.length });
|
||||
|
||||
async function updateWantListings(wants: Want[]) {
|
||||
for (const want of wants) {
|
||||
const listings = await populateListings(want);
|
||||
log.info({ listings: listings.length, ...wantDetails(want) }, 'listings added');
|
||||
}
|
||||
|
||||
log.info({ wants: wants.length }, 'finished syncing');
|
||||
}
|
||||
|
||||
events.on(Events.WantsAdded, async function wantsAdded(wants: Want[]) {
|
||||
log.info({ event: Events.WantsAdded, wants: wants.map(w => wantDetails(w)) }, 'starting listings population');
|
||||
await updateWantListings(wants);
|
||||
log.info({ event: Events.WantsAdded, wants: wants.map(w => wantDetails(w)) }, 'finished populating listings');
|
||||
events.emit(Events.ListingsUpdated);
|
||||
});
|
||||
|
||||
events.on(Events.StartupSync, async function startupSync() {
|
||||
const wants = await pg.wantsToSync();
|
||||
log.info({ event: Events.StartupSync, wants: wants.length });
|
||||
await updateWantListings(wants);
|
||||
events.emit(Events.ListingsUpdated);
|
||||
});
|
||||
|
||||
events.on(Events.ListingsUpdated, async function listingsUpdated() {
|
||||
const bundles = await offers.bundles();
|
||||
|
||||
+9
-5
@@ -9,11 +9,15 @@ import { logAxiosError, wantDetails } from './utils';
|
||||
import { Pg } from './pg';
|
||||
|
||||
export enum Status {
|
||||
Pending = 'Pending',
|
||||
Accepted = 'Accepted',
|
||||
Declined = 'Declined',
|
||||
Confirmed = 'Confirmed',
|
||||
Complete = 'Complete',
|
||||
Confirmed = 'Confirmed',
|
||||
Accepted = 'Accepted',
|
||||
Pending = 'Pending',
|
||||
Declined = 'Declined',
|
||||
}
|
||||
|
||||
function sortOffers(o) {
|
||||
return Object.values(Status).indexOf(o.status);
|
||||
}
|
||||
|
||||
export default function createOffers(log: Log, pg: Pg) {
|
||||
@@ -130,7 +134,7 @@ export default function createOffers(log: Log, pg: Pg) {
|
||||
seller: offers[0]?.listing.data.seller.id,
|
||||
shipsFrom: offers[0]?.listing.data.ships_from,
|
||||
shipping,
|
||||
offers,
|
||||
offers: sortBy(offers, sortOffers),
|
||||
mentionsAustralia: shipping.toLowerCase().includes('australia'),
|
||||
mentionsWorldwide: shipping.toLowerCase().includes('world'),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user