diff --git a/api/resolvers/item.js b/api/resolvers/item.js index de2d53f4..3c461e46 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -398,6 +398,29 @@ export default { return pin.position }, + prior: async (item, args, { models }) => { + if (!item.pinId) { + return null + } + + const prior = await models.item.findFirst({ + where: { + pinId: item.pinId, + createdAt: { + lt: item.createdAt + } + }, + orderBy: { + createdAt: 'desc' + } + }) + + if (!prior) { + return null + } + + return prior.id + }, user: async (item, args, { models }) => await models.user.findUnique({ where: { id: item.userId } }), ncomments: async (item, args, { models }) => { diff --git a/api/typeDefs/item.js b/api/typeDefs/item.js index dacb2373..e176f517 100644 --- a/api/typeDefs/item.js +++ b/api/typeDefs/item.js @@ -64,5 +64,6 @@ export default gql` comments: [Item!]! path: String position: Int + prior: Int } ` diff --git a/components/item.js b/components/item.js index 35106650..9b034518 100644 --- a/components/item.js +++ b/components/item.js @@ -70,6 +70,13 @@ export default function Item ({ item, rank, children }) { {timeSince(new Date(item.createdAt))} + {item.prior && + <> + \ + + yesterday + + } {canEdit && <> diff --git a/fragments/items.js b/fragments/items.js index 7012af2a..0f9a645c 100644 --- a/fragments/items.js +++ b/fragments/items.js @@ -72,6 +72,7 @@ export const ITEM_FULL = gql` query Item($id: ID!) { item(id: $id) { ...ItemFields + prior position text comments {