simplify and automate offer creation

This commit is contained in:
ntr committed 2022-09-02 00:06:51 +10:00
1 parent 7ea2c37116
commit a43d4f32e4
10 files changed
+97 -67

No files matched your search

+6 -6
View File
@@ -2,6 +2,7 @@ import bcrypt from 'bcrypt';
import type Log from 'bunyan';
import type { PrismaClient, Want, User, Listing, Offer, Prisma } from '@prisma/client';
import * as Bluebird from 'bluebird';
import omit from 'lodash/omit';
import { Status } from './offers';
@@ -54,7 +55,7 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
want: true,
},
orderBy: {
status: 'desc',
total: 'asc',
},
});
}
@@ -184,6 +185,8 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
seller, count(distinct("wantId")), array_agg(id) as listings
from
listings
where
seller not in (3709203)
group by
seller
order by
@@ -208,13 +211,10 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
return await prisma.$transaction(
offers.map(offer => prisma.offer.upsert({
where: {
userId_wantId: {
userId: offer.userId,
wantId: offer.wantId,
},
listingId: offer.listingId,
},
create: offer,
update: offer
update: omit(offer, ['status']),
}))
);
}