diff --git a/TODO.md b/TODO.md index ff25f63..40006d3 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,8 @@ # TODO -search input simplify +listing ids overflowing + +skip unofficial release status stepper diff --git a/api/index.ts b/api/index.ts index 0c70153..4d12a0c 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/offers.ts b/api/src/offers.ts index 5c55a38..605acdc 100644 --- a/api/src/offers.ts +++ b/api/src/offers.ts @@ -48,6 +48,11 @@ export default function createOffers(log: Log, pg: Pg) { // and ensure the cheapest one goes in first const sorted = sortBy(offers, ['item']); + // TODO probably need to take one of each condition of record from a store + // eg. they have a VG+ and a M we should make offers for each + + log.info(sorted); + const inserts = await pg.offersUpdate(sorted); return inserts; @@ -76,6 +81,8 @@ export default function createOffers(log: Log, pg: Pg) { return update; } + // converts offers into groups based on seller + // includes some bits of info about shipping etc async function acpOffers() { const offers = await pg.offersAdmin(); @@ -99,12 +106,19 @@ export default function createOffers(log: Log, pg: Pg) { return sellerOffers; } + // also groups offers by seller for users + // but mostly just munges the structure so the details + // are easily available async function userOffers(user: User) { const offers = await pg.userOffers(user); const groups = Object.values(groupBy(offers, (o) => o.wantId)) .map(g => { const offers = sortBy(g, sortOffers); + + // the offer status is just the most advanced status + // based on sort const status = offers[0].status; + const details = offers[0].want.data; return { diff --git a/api/src/pg.ts b/api/src/pg.ts index 2119358..f2ae171 100644 --- a/api/src/pg.ts +++ b/api/src/pg.ts @@ -247,14 +247,14 @@ export default function createPg(log: Log, prisma: PrismaClient) { }))); } - async function offersUpdate(offers: Offer[]) { + async function offersUpdate(offers) { return await prisma.$transaction( offers.map(offer => prisma.offer.upsert({ where: { listingId: offer.listingId, }, create: offer, - update: _.omit(offer, ['status']), + update: _.omit(offer, ['status', 'id']), })) ); }