From 1a63d3837e6e1cc73b7fd00c0dc052732a8b9c8b Mon Sep 17 00:00:00 2001 From: PyKen Date: Tue, 5 Dec 2023 01:22:00 +0900 Subject: [PATCH] fix(server): Return correct asset count in album (#5465) * fix(server): Return correct asset count in album * Update album.repository.sql Add generated sql --- server/src/infra/repositories/album.repository.ts | 2 +- server/src/infra/sql/album.repository.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/infra/repositories/album.repository.ts b/server/src/infra/repositories/album.repository.ts index 8a63897ed..a7698b952 100644 --- a/server/src/infra/repositories/album.repository.ts +++ b/server/src/infra/repositories/album.repository.ts @@ -76,7 +76,7 @@ export class AlbumRepository implements IAlbumRepository { .select('album.id') .addSelect('MIN(assets.fileCreatedAt)', 'start_date') .addSelect('MAX(assets.fileCreatedAt)', 'end_date') - .addSelect('COUNT(album_assets.assetsId)', 'asset_count') + .addSelect('COUNT(assets.id)', 'asset_count') .leftJoin('albums_assets_assets', 'album_assets', 'album_assets.albumsId = album.id') .leftJoin('assets', 'assets', 'assets.id = album_assets.assetsId') .where('album.id IN (:...ids)', { ids }) diff --git a/server/src/infra/sql/album.repository.sql b/server/src/infra/sql/album.repository.sql index 777edb097..4b2bfe19a 100644 --- a/server/src/infra/sql/album.repository.sql +++ b/server/src/infra/sql/album.repository.sql @@ -207,7 +207,7 @@ SELECT "album"."id" AS "album_id", MIN("assets"."fileCreatedAt") AS "start_date", MAX("assets"."fileCreatedAt") AS "end_date", - COUNT("album_assets"."assetsId") AS "asset_count" + COUNT("assets"."id") AS "asset_count" FROM "albums" "album" LEFT JOIN "albums_assets_assets" "album_assets" ON "album_assets"."albumsId" = "album"."id"