diff --git a/server/src/interfaces/asset.interface.ts b/server/src/interfaces/asset.interface.ts index 1b32c57d4141b2..7659f31467f694 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 ce7d257b40f288..9d14756931c950 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 2aca400cc71e20..a8bab157467d7f 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); }