comments n stuff

This commit is contained in:
ntr committed 2022-11-23 17:27:38 +11:00
1 parent 28759f9e70
commit f546d76912
4 files changed
+20 -4

No files matched your search

+3 -1
View File
@@ -1,6 +1,8 @@
# TODO # TODO
search input simplify listing ids overflowing
skip unofficial release
status stepper status stepper
+1 -1
View File
@@ -28,7 +28,7 @@ async function start() {
events, events,
} = createServices(log); } = createServices(log);
events.emit(Events.StartupSync); // events.emit(Events.StartupSync);
// events.emit(Events.ListingsUpdated); // events.emit(Events.ListingsUpdated);
api.listen(); api.listen();
+14
View File
@@ -48,6 +48,11 @@ export default function createOffers(log: Log, pg: Pg) {
// and ensure the cheapest one goes in first // and ensure the cheapest one goes in first
const sorted = sortBy(offers, ['item']); 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); const inserts = await pg.offersUpdate(sorted);
return inserts; return inserts;
@@ -76,6 +81,8 @@ export default function createOffers(log: Log, pg: Pg) {
return update; return update;
} }
// converts offers into groups based on seller
// includes some bits of info about shipping etc
async function acpOffers() { async function acpOffers() {
const offers = await pg.offersAdmin(); const offers = await pg.offersAdmin();
@@ -99,12 +106,19 @@ export default function createOffers(log: Log, pg: Pg) {
return sellerOffers; 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) { async function userOffers(user: User) {
const offers = await pg.userOffers(user); const offers = await pg.userOffers(user);
const groups = Object.values(groupBy(offers, (o) => o.wantId)) const groups = Object.values(groupBy(offers, (o) => o.wantId))
.map(g => { .map(g => {
const offers = sortBy(g, sortOffers); const offers = sortBy(g, sortOffers);
// the offer status is just the most advanced status
// based on sort
const status = offers[0].status; const status = offers[0].status;
const details = offers[0].want.data; const details = offers[0].want.data;
return { return {
+2 -2
View File
@@ -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( return await prisma.$transaction(
offers.map(offer => prisma.offer.upsert({ offers.map(offer => prisma.offer.upsert({
where: { where: {
listingId: offer.listingId, listingId: offer.listingId,
}, },
create: offer, create: offer,
update: _.omit(offer, ['status']), update: _.omit(offer, ['status', 'id']),
})) }))
); );
} }