diff --git a/TODO.md b/TODO.md index e127861..caeffef 100644 --- a/TODO.md +++ b/TODO.md @@ -1,14 +1,7 @@ # TODO -info page - minimum quality - acp page needs to fetch offers list -on logged in need to redirect to offers - -discord! - want added -> wants added spamming discogs and generating offers on every want add diff --git a/api/index.ts b/api/index.ts index 4d12a0c..0c70153 100644 --- a/api/index.ts +++ b/api/index.ts @@ -28,7 +28,7 @@ async function start() { events, } = createServices(log); - // events.emit(Events.StartupSync); + events.emit(Events.StartupSync); // events.emit(Events.ListingsUpdated); api.listen(); diff --git a/api/src/api.ts b/api/src/api.ts index d94f2ca..cebf1b4 100644 --- a/api/src/api.ts +++ b/api/src/api.ts @@ -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; }); diff --git a/api/src/discogs.ts b/api/src/discogs.ts index c6289ce..144ef20 100644 --- a/api/src/discogs.ts +++ b/api/src/discogs.ts @@ -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)); } diff --git a/api/src/events.ts b/api/src/events.ts index e7f356d..c06fa79 100644 --- a/api/src/events.ts +++ b/api/src/events.ts @@ -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(); diff --git a/api/src/offers.ts b/api/src/offers.ts index 77faffe..78601fc 100644 --- a/api/src/offers.ts +++ b/api/src/offers.ts @@ -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'), } diff --git a/client/src/components/offer.tsx b/client/src/components/offer.tsx index 9d02283..bb845e2 100644 --- a/client/src/components/offer.tsx +++ b/client/src/components/offer.tsx @@ -29,11 +29,11 @@ export default function Offer(offer) { return (
First, add some records to your List on the Search Page.
-Mates Crates will then make offers to you for releases you add to your List.
+Mates Crates will then make Offers to you for releases you add to your List.
+Check back regularly for updated Offers, the global record marketplace is a living thing.
Not all items on your List will have offers. However, as new users join the site the number of offers we can make increases, so be sure to tell your friends!
Think of offers like an expression of interest, they are not confirmed until they are set to Confirmed status.
After that they will be shipped to Melbourne and ready for pick up.
All Mates Crates offers are for records that are either mint condition or close to it.
+All Mates Crates offers are for records that are either mint or very good condition.
Records are usually available for pickup within a week. We order in bulk, which often means express, insured shipping to Melbourne.
+Sometimes we can get a record from multiple sources, these appear as duplicate offers. Accepting multiple offers increases the chance the item will be confirmed.
Please invite other collectors to the site. More users means offers can become cheaper and shipped sooner.