Skip to content

Commit

Permalink
Modify: 불필요한 코드 삭제 및 변수명 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
JJieunn committed Oct 25, 2022
1 parent 4a97bf8 commit 9fa3e06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/configs/db.connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ myDataSource
.then(() => {
console.log("Data Source has been initailized!");
})
.catch((err: any) => {
.catch(() => {
console.log("Database initialize failed.");
});

Expand Down
19 changes: 9 additions & 10 deletions src/models/postsDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ const isPostExistByUserId = async (userId: string | string[] | undefined, postId


const createPost = async (userId: string | string[] | undefined, postData: CreatePostDTO): Promise<object> => {
const userNumId: number = Number(userId);
return await myDataSource
.createQueryBuilder()
.insert()
.into(Posts)
.values({
user_id: userNumId,
user_id: userId,
title: postData.title,
content: postData.content
})
Expand All @@ -51,21 +50,21 @@ const createPost = async (userId: string | string[] | undefined, postData: Creat
const getPostList = async (): Promise<Posts[]> => {
return await myDataSource
.createQueryBuilder()
.select(["post.id", "post.title", "post.created_at", "post.user_id", "user.nickname"])
.innerJoin(Users, "user", "post.user_id = user.id")
.from(Posts, "post")
.orderBy("post.created_at", "DESC")
.select(["p.id", "p.title", "p.created_at", "p.user_id", "u.nickname"])
.innerJoin(Users, "u", "p.user_id = u.id")
.from(Posts, "p")
.orderBy("p.created_at", "DESC")
.getMany()
}


const getPost = async (postId: string): Promise<Posts | null> => {
return await myDataSource
.createQueryBuilder()
.select(["post.id", "post.title", "post.content", "post.created_at", "post.user_id", "user.nickname"])
.innerJoin(Users, "user", "post.user_id = user.id")
.from(Posts, "post")
.where("post.id = :postId", { postId })
.select(["p.id", "p.title", "p.content", "p.created_at", "p.user_id", "u.nickname"])
.innerJoin(Users, "u", "p.user_id = u.id")
.from(Posts, "p")
.where("p.id = :postId", { postId })
.getOne()
}

Expand Down

0 comments on commit 9fa3e06

Please sign in to comment.