expand offers

This commit is contained in:
ntr committed 2022-12-21 22:02:24 +11:00
1 parent f0623cb74b
commit 6b73831b51
5 files changed
+25 -23

No files matched your search

+20 -12
View File
@@ -21,7 +21,10 @@ export default function createPg(log: Log, prisma: PrismaClient) {
}
async function userWants(user: User) {
return prisma.want.findMany({ where: { userId: user.id }});
return prisma.want.findMany({
where: { userId: user.id },
include: { _count: { select: { offers: true }} },
});
}
async function userOffers(user: User) {
@@ -34,6 +37,7 @@ export default function createPg(log: Log, prisma: PrismaClient) {
want: true,
},
orderBy: [
{ updatedAt: 'asc' },
{ total: 'asc' },
{ listingId: 'asc' },
],
@@ -223,17 +227,21 @@ export default function createPg(log: Log, prisma: PrismaClient) {
// but for ease of abstraction we get the listings themselves
// grouped by seller
const candidates = await prisma.$queryRaw`
select
seller, count(distinct("wantId")), array_agg(id) as listings
from
listings
where
seller not in (3709203)
group by
seller
order by
count desc
limit 5;
WITH groups AS (
select
seller, count(distinct("wantId")), array_agg(id) as listings
from
listings
where
seller not in (3709203)
group by
seller
order by
count desc
)
select *
from groups
where count >= 5;
` as BundleCandidate[];
return Promise.all(candidates.map(async c => prisma.listing.findMany({