mirror of
https://github.com/immich-app/immich.git
synced 2024-11-24 08:52:28 +02:00
feat: remove tag from assets when it is deleted
This commit is contained in:
parent
a60209db3e
commit
239d4f5a29
@ -162,6 +162,7 @@ export interface IAssetRepository {
|
||||
getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise<string | undefined>;
|
||||
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
|
||||
getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<string[]>;
|
||||
getByTagId(ownerId: string, tagId: string): Promise<string[]>;
|
||||
getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated<AssetEntity>;
|
||||
getById(
|
||||
id: string,
|
||||
|
@ -163,6 +163,20 @@ export class AssetRepository implements IAssetRepository {
|
||||
return assets.map((asset) => asset.deviceAssetId);
|
||||
}
|
||||
|
||||
async getByTagId(ownerId: string, tagId: string): Promise<string[]> {
|
||||
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,
|
||||
|
@ -70,7 +70,8 @@ export class TagService extends BaseService {
|
||||
async remove(auth: AuthDto, id: string): Promise<void> {
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user