From 0c037536422ecae950eb208b6612f558785d6e8b Mon Sep 17 00:00:00 2001
From: Alex <alex.tran1502@gmail.com>
Date: Wed, 11 Dec 2024 14:51:56 -0600
Subject: [PATCH] fix(server): fix getByDayOfYear query (#14655)

* fix(server): fix getByDayOfYear query

* generate sql
---
 server/src/queries/asset.repository.sql     | 15 ++++++++++++++-
 server/src/repositories/asset.repository.ts |  2 +-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/server/src/queries/asset.repository.sql b/server/src/queries/asset.repository.sql
index f4b1b2fea1..4694cd20fc 100644
--- a/server/src/queries/asset.repository.sql
+++ b/server/src/queries/asset.repository.sql
@@ -71,7 +71,20 @@ FROM
   INNER JOIN "asset_files" "files" ON "files"."assetId" = "entity"."id"
 WHERE
   (
-    "files"."type" = $1
+    "entity"."ownerId" IN ($1)
+    AND "entity"."isVisible" = true
+    AND "entity"."isArchived" = false
+    AND EXTRACT(
+      DAY
+      FROM
+        "entity"."localDateTime" AT TIME ZONE 'UTC'
+    ) = $2
+    AND EXTRACT(
+      MONTH
+      FROM
+        "entity"."localDateTime" AT TIME ZONE 'UTC'
+    ) = $3
+    AND "files"."type" = $4
     AND EXTRACT(
       YEAR
       FROM
diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts
index b3066a37bc..33d1e2457e 100644
--- a/server/src/repositories/asset.repository.ts
+++ b/server/src/repositories/asset.repository.ts
@@ -92,7 +92,7 @@ export class AssetRepository implements IAssetRepository {
       )
       .leftJoinAndSelect('entity.exifInfo', 'exifInfo')
       .innerJoinAndSelect('entity.files', 'files')
-      .where('files.type = :type', { type: AssetFileType.THUMBNAIL })
+      .andWhere('files.type = :type', { type: AssetFileType.THUMBNAIL })
       .andWhere(
         `EXTRACT(YEAR FROM CURRENT_DATE AT TIME ZONE 'UTC') - EXTRACT(YEAR FROM entity.localDateTime AT TIME ZONE 'UTC') > 0`,
       )