diff --git a/server/src/interfaces/asset.interface.ts b/server/src/interfaces/asset.interface.ts index 1b32c57d41..7659f31467 100644 --- a/server/src/interfaces/asset.interface.ts +++ b/server/src/interfaces/asset.interface.ts @@ -162,6 +162,7 @@ export interface IAssetRepository { getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise; getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated; getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise; + getByTagId(ownerId: string, tagId: string): Promise; getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated; getById( id: string, diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts index ce7d257b40..9d14756931 100644 --- a/server/src/repositories/asset.repository.ts +++ b/server/src/repositories/asset.repository.ts @@ -163,6 +163,20 @@ export class AssetRepository implements IAssetRepository { return assets.map((asset) => asset.deviceAssetId); } + async getByTagId(ownerId: string, tagId: string): Promise { + const assets = await this.repository.find({ + select: { + tags: true, + }, + where: { + ownerId, + tags: [{ id: tagId }], + }, + }); + + return assets.map((asset) => asset.id); + } + getByUserId( pagination: PaginationOptions, userId: string, diff --git a/server/src/services/tag.service.ts b/server/src/services/tag.service.ts index 2aca400cc7..a8bab15746 100644 --- a/server/src/services/tag.service.ts +++ b/server/src/services/tag.service.ts @@ -70,7 +70,8 @@ export class TagService extends BaseService { async remove(auth: AuthDto, id: string): Promise { await this.requireAccess({ auth, permission: Permission.TAG_DELETE, ids: [id] }); - // TODO sync tag changes for affected assets + const assetIdList = await this.assetRepository.getByTagId(auth.user.id, id); + await this.removeAssets(auth, id, { ids: assetIdList }); await this.tagRepository.delete(id); }