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

-1
View File
@@ -1,5 +1,4 @@
# TODO
contact options on landing page
move want add to rpc
+3
View File
@@ -80,6 +80,9 @@ model Offer {
wantId String @db.Uuid
want Want @relation(fields: [wantId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
// only one offer per want for a user
// @@unique([userId, wantId])
@@unique([listingId])
+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({
+2 -2
View File
@@ -30,8 +30,8 @@ function Want(want) {
</div>
<img src={r.thumb} />
<div class='details'>
<div class='alt'>{r.year}</div>
<div class='alt'>{r.formats[0].descriptions.join(' ')}</div>
<div class='alt'>{r.year} - {r.formats[0].descriptions.join(' ')}</div>
<div class='alt'>{want._count.offers} offers</div>
</div>
<button onClick={onClick} >{text}</button>
</article>
-8
View File
@@ -74,14 +74,6 @@ function Home() {
ws.sendAcpListingsSync();
}
if (!offers.length) {
return (
<div class={'offers'}>
loading...
</div>
);
}
return (
<div>
<button onClick={sync}> sync listings </button>