High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(server): Correctly set album start and end dates (#4698)
Michael Manganiellob6f18cbe8112
diff --git a/server/src/domain/album/album-response.dto.spec.ts b/server/src/domain/album/album-response.dto.spec.tsnew file mode 100644index 0000000000..c8485af650--- /dev/null+++ b/server/src/domain/album/album-response.dto.spec.ts@@ -0,0 +1,16 @@+import { albumStub } from '@test';+import { mapAlbum } from './album-response.dto';++describe('mapAlbum', () => {+ it('should set start and end dates', () => {+ const dto = mapAlbum(albumStub.twoAssets, false);+ expect(dto.startDate).toEqual(new Date('2023-02-22T05:06:29.716Z'));+ expect(dto.endDate).toEqual(new Date('2023-02-23T05:06:29.716Z'));+ });++ it('should not set start and end dates for empty assets', () => {+ const dto = mapAlbum(albumStub.empty, false);+ expect(dto.startDate).toBeUndefined();+ expect(dto.endDate).toBeUndefined();+ });+});diff --git a/server/src/domain/album/album-response.dto.ts b/server/src/domain/album/album-response.dto.tsindex 9f0e134c74..b426bc37d6 100644--- a/server/src/domain/album/album-response.dto.ts+++ b/server/src/domain/album/album-response.dto.ts@@ -36,6 +36,15 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean): AlbumResponsconst hasSharedLink = entity.sharedLinks?.length > 0;const hasSharedUser = sharedUsers.length > 0;+ let startDate = assets.at(0)?.fileCreatedAt || undefined;+ let endDate = assets.at(-1)?.fileCreatedAt || undefined;+ // Swap dates if start date is greater than end date.+ if (startDate && endDate && startDate > endDate) {+ const temp = startDate;+ startDate = endDate;+ endDate = temp;+ }+return {albumName: entity.albumName,description: entity.description,@@ -48,8 +57,8 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean): AlbumResponssharedUsers,shared: hasSharedUser || hasSharedLink,hasSharedLink,- startDate: assets.at(0)?.fileCreatedAt || undefined,- endDate: assets.at(-1)?.fileCreatedAt || undefined,+ startDate,+ endDate,assets: (withAssets ? assets : []).map((asset) => mapAsset(asset)),assetCount: entity.assets?.length || 0,};diff --git a/server/src/domain/metadata/metadata.service.spec.ts b/server/src/domain/metadata/metadata.service.spec.tsindex 86befcee83..e6ca7f199c 100644--- a/server/src/domain/metadata/metadata.service.spec.ts+++ b/server/src/domain/metadata/metadata.service.spec.ts@@ -277,7 +277,7 @@ describe(MetadataService.name, () => {id: assetStub.withLocation.id,duration: null,fileCreatedAt: assetStub.withLocation.createdAt,- localDateTime: new Date('2023-02-23T05:06:29.716Z'),+ localDateTime: new Date('2023-02-22T05:06:29.716Z'),});});diff --git a/server/test/fixtures/asset.stub.ts b/server/test/fixtures/asset.stub.tsindex 3454818438..4c6288c408 100644--- a/server/test/fixtures/asset.stub.ts+++ b/server/test/fixtures/asset.stub.ts@@ -434,8 +434,8 @@ export const assetStub = {withLocation: Object.freeze<AssetEntity>({id: 'asset-with-favorite-id',deviceAssetId: 'device-asset-id',- fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'),- fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'),+ fileModifiedAt: new Date('2023-02-22T05:06:29.716Z'),+ fileCreatedAt: new Date('2023-02-22T05:06:29.716Z'),owner: userStub.user1,ownerId: 'user-id',deviceId: 'device-id',@@ -447,9 +447,9 @@ export const assetStub = {webpPath: null,thumbhash: null,encodedVideoPath: null,- createdAt: new Date('2023-02-23T05:06:29.716Z'),- updatedAt: new Date('2023-02-23T05:06:29.716Z'),- localDateTime: new Date('2023-02-23T05:06:29.716Z'),+ createdAt: new Date('2023-02-22T05:06:29.716Z'),+ updatedAt: new Date('2023-02-22T05:06:29.716Z'),+ localDateTime: new Date('2023-02-22T05:06:29.716Z'),isFavorite: false,isArchived: false,isReadOnly: false,