Skip to content

Commit

Permalink
rework getallstorageimages
Browse files Browse the repository at this point in the history
  • Loading branch information
ufaboy committed Jan 19, 2024
1 parent cb73cd3 commit d7e43b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ dist



docker-compose.yml
28 changes: 20 additions & 8 deletions src/services/imageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ async function viewImage(id: number) {
}

async function viewImageByName(bookID: number, imageName: string) {
const image = await prisma.image.findFirst({ where: { book_id: bookID, file_name: imageName } });
const image = await prisma.image.findFirst({
where: { book_id: bookID, file_name: imageName },
});
if (image) {
return image;
}
Expand Down Expand Up @@ -151,17 +153,27 @@ async function searchImage(params: QueryImages) {
}

async function totalImageBooks() {
// const result = await prisma.image.groupBy({
// by: ['book_id'],
// _count: {
// book_id: true,
// },
// });

// return result.map((item) => ({
// book_id: item.book_id,
// images_count: item._count.book_id,
// }));
return await getAllStorageImages()
const storageImages = await getAllStorageImages();
const books = await prisma.book.findMany({
select: {
id: true,
name: true,
},
where: {
id: { in: storageImages.map((item) => item.bookID) },
},
});
const result = storageImages.map(item => {
const book = books.find(elem => elem.id === item.bookID)
return {bookID: item.bookID, bookName: book?.name, images: item.images}
})

return result;
}

async function removeImage(id: number) {
Expand Down

0 comments on commit d7e43b2

Please sign in to comment.