Skip to content

Commit

Permalink
feat: remove tag from assets when it is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
p2kmgcl committed Nov 15, 2024
1 parent 4ca27a3 commit be5ed20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/src/interfaces/asset.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion server/src/services/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit be5ed20

Please sign in to comment.