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

+1 -1
View File
@@ -28,7 +28,7 @@ async function start() {
events,
} = createServices(log);
events.emit(Events.StartupSync);
// events.emit(Events.StartupSync);
// events.emit(Events.ListingsUpdated);
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
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 {
+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(
offers.map(offer => prisma.offer.upsert({
where: {
listingId: offer.listingId,
},
create: offer,
update: _.omit(offer, ['status']),
update: _.omit(offer, ['status', 'id']),
}))
);
}