diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 5ff729d3..ac169d11 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -26,7 +26,7 @@ import { verifyHmac } from './wallet' function commentsOrderByClause (me, models, sort) { if (sort === 'recent') { - return 'ORDER BY ("Item"."deletedAt" IS NULL) DESC, ("Item".cost > 0 OR "Item"."weightedVotes" - "Item"."weightedDownVotes" > 0) DESC, "Item".created_at DESC, "Item".id DESC' + return 'ORDER BY ("Item"."deletedAt" IS NULL) DESC, ("Item".cost > 0 OR "Item"."weightedVotes" - "Item"."weightedDownVotes" > 0) DESC, COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC, "Item".id DESC' } if (me && sort === 'hot') { @@ -412,10 +412,10 @@ export default { typeClause(type), muteClause(me) )} - ORDER BY "Item".created_at DESC + ORDER BY COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC OFFSET $2 LIMIT $3`, - orderBy: 'ORDER BY "Item"."createdAt" DESC' + orderBy: 'ORDER BY COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC' }, decodedCursor.time, decodedCursor.offset, limit, ...subArr) break case 'top': diff --git a/api/typeDefs/item.js b/api/typeDefs/item.js index e44eca24..f817e340 100644 --- a/api/typeDefs/item.js +++ b/api/typeDefs/item.js @@ -107,6 +107,7 @@ export default gql` id: ID! createdAt: Date! updatedAt: Date! + invoicePaidAt: Date deletedAt: Date deleteScheduledAt: Date reminderScheduledAt: Date diff --git a/components/item-info.js b/components/item-info.js index f7301789..ad0ed310 100644 --- a/components/item-info.js +++ b/components/item-info.js @@ -135,8 +135,8 @@ export default function ItemInfo ({ {embellishUser} } - - {timeSince(new Date(item.createdAt))} + + {timeSince(new Date(item.invoicePaidAt || item.createdAt))} {item.prior && <> @@ -250,6 +250,11 @@ function InfoDropdownItem ({ item }) {
{item.id}
created at
{item.createdAt}
+ {item.invoicePaidAt && + <> +
paid at
+
{item.invoicePaidAt}
+ }
cost
{item.cost}
stacked
diff --git a/fragments/comments.js b/fragments/comments.js index 50cdfafd..991bc299 100644 --- a/fragments/comments.js +++ b/fragments/comments.js @@ -18,6 +18,7 @@ export const COMMENT_FIELDS = gql` position parentId createdAt + invoicePaidAt deletedAt text user { diff --git a/fragments/items.js b/fragments/items.js index ada616cd..f51d1771 100644 --- a/fragments/items.js +++ b/fragments/items.js @@ -18,6 +18,7 @@ export const ITEM_FIELDS = gql` id parentId createdAt + invoicePaidAt deletedAt title url diff --git a/prisma/migrations/20250122114228_recent_sort_by_invoice_paid_at/migration.sql b/prisma/migrations/20250122114228_recent_sort_by_invoice_paid_at/migration.sql new file mode 100644 index 00000000..4db8be41 --- /dev/null +++ b/prisma/migrations/20250122114228_recent_sort_by_invoice_paid_at/migration.sql @@ -0,0 +1,3 @@ +-- CreateIndex +CREATE INDEX "Item_invoicePaidAt_idx" ON "Item"("invoicePaidAt"); +CREATE INDEX "Item_paid_created_idx" ON "Item" (COALESCE("invoicePaidAt", created_at) DESC); \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dcdb3b93..5b227594 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -598,6 +598,7 @@ model Item { @@index([cost]) @@index([url]) @@index([boost]) + @@index([invoicePaidAt]) } // we use this to denormalize a user's aggregated interactions (zaps) with an item