expand offers
This commit is contained in:
1 parent
f0623cb74b
commit
6b73831b51
5 files changed
+15
-13
No files matched your search
@@ -1,5 +1,4 @@
|
|||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
contact options on landing page
|
contact options on landing page
|
||||||
|
|
||||||
move want add to rpc
|
move want add to rpc
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ model Offer {
|
|||||||
wantId String @db.Uuid
|
wantId String @db.Uuid
|
||||||
want Want @relation(fields: [wantId], references: [id], onDelete: Cascade)
|
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
|
// only one offer per want for a user
|
||||||
// @@unique([userId, wantId])
|
// @@unique([userId, wantId])
|
||||||
@@unique([listingId])
|
@@unique([listingId])
|
||||||
|
|||||||
+10
-2
@@ -21,7 +21,10 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function userWants(user: User) {
|
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) {
|
async function userOffers(user: User) {
|
||||||
@@ -34,6 +37,7 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
|||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
orderBy: [
|
orderBy: [
|
||||||
|
{ updatedAt: 'asc' },
|
||||||
{ total: 'asc' },
|
{ total: 'asc' },
|
||||||
{ listingId: 'asc' },
|
{ listingId: 'asc' },
|
||||||
],
|
],
|
||||||
@@ -223,6 +227,7 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
|||||||
// but for ease of abstraction we get the listings themselves
|
// but for ease of abstraction we get the listings themselves
|
||||||
// grouped by seller
|
// grouped by seller
|
||||||
const candidates = await prisma.$queryRaw`
|
const candidates = await prisma.$queryRaw`
|
||||||
|
WITH groups AS (
|
||||||
select
|
select
|
||||||
seller, count(distinct("wantId")), array_agg(id) as listings
|
seller, count(distinct("wantId")), array_agg(id) as listings
|
||||||
from
|
from
|
||||||
@@ -233,7 +238,10 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
|||||||
seller
|
seller
|
||||||
order by
|
order by
|
||||||
count desc
|
count desc
|
||||||
limit 5;
|
)
|
||||||
|
select *
|
||||||
|
from groups
|
||||||
|
where count >= 5;
|
||||||
` as BundleCandidate[];
|
` as BundleCandidate[];
|
||||||
|
|
||||||
return Promise.all(candidates.map(async c => prisma.listing.findMany({
|
return Promise.all(candidates.map(async c => prisma.listing.findMany({
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ function Want(want) {
|
|||||||
</div>
|
</div>
|
||||||
<img src={r.thumb} />
|
<img src={r.thumb} />
|
||||||
<div class='details'>
|
<div class='details'>
|
||||||
<div class='alt'>{r.year}</div>
|
<div class='alt'>{r.year} - {r.formats[0].descriptions.join(' ')}</div>
|
||||||
<div class='alt'>{r.formats[0].descriptions.join(' ')}</div>
|
<div class='alt'>{want._count.offers} offers</div>
|
||||||
</div>
|
</div>
|
||||||
<button onClick={onClick} >{text}</button>
|
<button onClick={onClick} >{text}</button>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@@ -74,14 +74,6 @@ function Home() {
|
|||||||
ws.sendAcpListingsSync();
|
ws.sendAcpListingsSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!offers.length) {
|
|
||||||
return (
|
|
||||||
<div class={'offers'}>
|
|
||||||
loading...
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<button onClick={sync}> sync listings </button>
|
<button onClick={sync}> sync listings </button>
|
||||||
|
|||||||
Reference in new issue
Block a user