diff --git a/TODO.md b/TODO.md
index abbb330..d352325 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,4 @@
# TODO
-
contact options on landing page
move want add to rpc
diff --git a/api/prisma/schema.prisma b/api/prisma/schema.prisma
index 6bbf028..2b49044 100644
--- a/api/prisma/schema.prisma
+++ b/api/prisma/schema.prisma
@@ -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])
diff --git a/api/src/pg.ts b/api/src/pg.ts
index 83c7b0e..0db7412 100644
--- a/api/src/pg.ts
+++ b/api/src/pg.ts
@@ -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({
diff --git a/client/src/components/want.tsx b/client/src/components/want.tsx
index 1adba20..503e916 100644
--- a/client/src/components/want.tsx
+++ b/client/src/components/want.tsx
@@ -30,8 +30,8 @@ function Want(want) {