Skip to content

Commit d3dfbf9

Browse files
committed
fix: user lastname from null to empty String
1 parent 06b2036 commit d3dfbf9

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

client/src/components/Comment.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const Comment = ({ comment }) => {
214214
{comment.optimistic ? (
215215
<CircularProgress size={20} />
216216
) : (
217-
comment.authorId === user.id && (
217+
comment.authorId === user?.id && (
218218
<MoreButton
219219
setEditing={setEditing}
220220
comment={comment}

client/src/pages/Profile.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,19 @@ const UserMetrics = () => {
283283
title="Comments Received"
284284
value={metrics.commentsReceived}
285285
/>
286-
<MetricItem
287-
title="Longest Post"
288-
value={`${metrics.longestPost?.words} words`}
289-
isLink
290-
linkTo={`/posts/${metrics.longestPost?.id}`}
291-
/>
286+
{metrics.longestPost ? (
287+
<MetricItem
288+
title="Longest Post"
289+
value={`${metrics.longestPost.words} words`}
290+
isLink
291+
linkTo={`/posts/${metrics.longestPost.id}`}
292+
/>
293+
) : (
294+
<MetricItem
295+
title="Longest Post"
296+
value={0}
297+
/>
298+
)}
292299
</Grid>
293300
)}
294301
</ListItem>

server/src/controllers/user.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ export const getUserStats = async ({ params: { id } }: RequestParams) => {
107107
})
108108

109109
const commentsReceived = await prisma.comment.count({
110-
where: { post: { authorId: id } },
110+
where: {
111+
AND: {
112+
post: { authorId: id },
113+
NOT: { authorId: id },
114+
},
115+
},
111116
})
112117
try {
113118
const result = await prisma.$queryRaw<{ id: string; words: number }[]>`
@@ -127,7 +132,7 @@ export const getUserStats = async ({ params: { id } }: RequestParams) => {
127132
return {
128133
posts,
129134
privatePosts,
130-
reactionsReceived: reactionsReceived._sum.reactionCount,
135+
reactionsReceived: reactionsReceived._sum.reactionCount || 0,
131136
commentsReceived,
132137
longestPost: result[0],
133138
}

server/src/lib/prisma.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const prismaClientSingleton = () =>
1212
fullName: {
1313
needs: { firstName: true, lastName: true },
1414
compute(user) {
15-
return `${user.firstName} ${user.lastName}`
15+
return `${user.firstName} ${user.lastName || ''}`
1616
},
1717
},
1818
},

0 commit comments

Comments
 (0)