Skip to content

Commit

Permalink
장바구니 도서 상세 조회 기능 추가
Browse files Browse the repository at this point in the history
- 장바구니 도서 상세 조회 기능을 추가했습니다.
  - 새로운 도메인 함수 findCartItemAndBook(userId: number)를 추가했습니다.
  - 이 함수는 장바구니 정보와 함께 연결된 도서 정보를 상세하게 조회합니다.
  • Loading branch information
jihwooon committed Mar 18, 2024
1 parent 7afa25b commit 4ec9aad
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions server/src/cartItems/domain/cartItem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ export const findCartItemWithBook = async (userId: number, selectedId: number[])
);
};

export const findCartItemAndBook = async (userId: number) => {
const [rows] = await doQuery((connection) =>
connection.execute<RowDataPacket[]>(
`SELECT ci.id, ci.book_id, b.title, b.summary, b.price, ci.count
FROM cartItems ci
LEFT JOIN books b
ON b.id = ci.book_id
WHERE ci.user_id = ?`,
[userId],
),
);

return (rows ?? []).map(
(row) =>
new CartItem({
id: row.id,
bookId: row.book_id,
count: row.count,
books: new Book({
title: row.title,
summary: row.summary,
price: row.price,
}),
}),
);
};

export const deleteById = async (id: number): Promise<boolean> => {
const [{ affectedRows }] = await doQuery((connection) =>
connection.execute<ResultSetHeader>(
Expand Down

0 comments on commit 4ec9aad

Please sign in to comment.