Skip to content

Commit

Permalink
fix(server): update album updatedAt on assets/users removed/added (im…
Browse files Browse the repository at this point in the history
  • Loading branch information
Fynn Petersen-Frey authored Mar 11, 2023
1 parent 63ad802 commit 3cce433
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/apps/immich/src/api-v1/album/album-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class AlbumRepository implements IAlbumRepository {

async addSharedUsers(album: AlbumEntity, addUsersDto: AddUsersDto): Promise<AlbumEntity> {
album.sharedUsers.push(...addUsersDto.sharedUserIds.map((id) => ({ id } as UserEntity)));
album.updatedAt = new Date().toISOString();

await this.albumRepository.save(album);

Expand All @@ -164,6 +165,7 @@ export class AlbumRepository implements IAlbumRepository {

async removeUser(album: AlbumEntity, userId: string): Promise<void> {
album.sharedUsers = album.sharedUsers.filter((user) => user.id !== userId);
album.updatedAt = new Date().toISOString();
await this.albumRepository.save(album);
}

Expand All @@ -174,9 +176,13 @@ export class AlbumRepository implements IAlbumRepository {
return !removeAssetsDto.assetIds.includes(asset.id);
});

const numRemovedAssets = assetCount - album.assets.length;
if (numRemovedAssets > 0) {
album.updatedAt = new Date().toISOString();
}
await this.albumRepository.save(album, {});

return assetCount - album.assets.length;
return numRemovedAssets;
}

async addAssets(album: AlbumEntity, addAssetsDto: AddAssetsDto): Promise<AddAssetsResponseDto> {
Expand All @@ -197,10 +203,14 @@ export class AlbumRepository implements IAlbumRepository {
album.albumThumbnailAssetId = album.assets[0].id;
}

const successfullyAdded = addAssetsDto.assetIds.length - alreadyExisting.length;
if (successfullyAdded > 0) {
album.updatedAt = new Date().toISOString();
}
await this.albumRepository.save(album);

return {
successfullyAdded: addAssetsDto.assetIds.length - alreadyExisting.length,
successfullyAdded,
alreadyInAlbum: alreadyExisting,
};
}
Expand Down

0 comments on commit 3cce433

Please sign in to comment.