Skip to content

Commit

Permalink
fix: 사용자 글 목록 좋아요 응답 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyongp committed Nov 15, 2023
1 parent eb64793 commit 424249b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/controllers/my/blogs/:blogId([0-9]+)/posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const getMyPostsByBlog = createRouter({
description: "내 블로그의 글 목록을 가져옵니다.",
authorized: true,
async handler(ctx) {
const list = await posts.findAll({
const list = await posts.findAll(ctx.auth.user.id, {
userId: ctx.auth.user.id,
blogId: +ctx.param.blogId,
});
Expand Down
7 changes: 1 addition & 6 deletions src/controllers/my/liked-posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ export const getMyLikedPosts = createRouter({
const list = await likes.findAllPosts(ctx.auth.user.id, options, {
userId: ctx.auth.user.id,
});
return Promise.all(
list.map(({ post }) => ({
...toCommunityPost(post),
liked: true,
})),
);
return Promise.all(list.map(({ post }) => toCommunityPost(post)));
},
});
2 changes: 1 addition & 1 deletion src/controllers/my/posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const getMyPosts = createRouter({
description: "내 게시글 목록을 가져옵니다.",
authorized: true,
async handler(ctx): Promise<Post[]> {
const list = await posts.findAll({
const list = await posts.findAll(ctx.auth.user.id, {
userId: ctx.auth.user.id,
});
return list.map(toPost);
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/users/:userId([0-9]+)/posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const getUserPosts = createRouter({
description: "사용자의 게시글 목록을 가져옵니다.",
authorized: true,
async handler(ctx): Promise<Post[]> {
const list = await posts.findAll({ userId: +ctx.param.userId });
const list = await posts.findAll(ctx.auth.user.id, {
userId: +ctx.param.userId,
});
return list.map(toPost);
},
});
7 changes: 5 additions & 2 deletions src/services/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { prisma } from "prisma";
import { unixTimeToDate } from "utils/datetime";
import { isBefore } from "date-fns";

export function findAll(where: { userId: number; blogId?: number }) {
export function findAll(
authUserId: number,
where: { userId: number; blogId?: number },
) {
return prisma.post.findMany({
where: {
userId: where.userId,
Expand All @@ -12,7 +15,7 @@ export function findAll(where: { userId: number; blogId?: number }) {
include: {
postTags: true,
postLikes: {
where: { userId: where.userId },
where: { userId: authUserId },
take: 1,
},
},
Expand Down
1 change: 1 addition & 0 deletions src/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Prisma } from "@prisma/client";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
import { prisma } from "prisma";
import { HttpError } from "utils/http";
import { CursorBasedPagination } from "utils/pagination";

// TODO: AuthUser Context 전달하도록 개선
export const userInclude = (authUserId: number): Prisma.UserInclude => ({
Expand Down

0 comments on commit 424249b

Please sign in to comment.