mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
feat: remove tag from assets when it is deleted
This commit is contained in:
parent
a60209db3e
commit
239d4f5a29
3 changed files with 17 additions and 1 deletions
|
@ -162,6 +162,7 @@ export interface IAssetRepository {
|
||||||
getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise<string | undefined>;
|
getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise<string | undefined>;
|
||||||
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
|
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
|
||||||
getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<string[]>;
|
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>;
|
getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated<AssetEntity>;
|
||||||
getById(
|
getById(
|
||||||
id: string,
|
id: string,
|
||||||
|
|
|
@ -163,6 +163,20 @@ export class AssetRepository implements IAssetRepository {
|
||||||
return assets.map((asset) => asset.deviceAssetId);
|
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(
|
getByUserId(
|
||||||
pagination: PaginationOptions,
|
pagination: PaginationOptions,
|
||||||
userId: string,
|
userId: string,
|
||||||
|
|
|
@ -70,7 +70,8 @@ export class TagService extends BaseService {
|
||||||
async remove(auth: AuthDto, id: string): Promise<void> {
|
async remove(auth: AuthDto, id: string): Promise<void> {
|
||||||
await this.requireAccess({ auth, permission: Permission.TAG_DELETE, ids: [id] });
|
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);
|
await this.tagRepository.delete(id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue