Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove tag from assets when it is deleted #14166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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);

Check failure on line 73 in server/src/services/tag.service.ts

View workflow job for this annotation

GitHub Actions / Test & Lint Server

src/services/tag.service.spec.ts > TagService > remove > should remove a tag

TypeError: this.assetRepository.getByTagId is not a function ❯ TagService.remove src/services/tag.service.ts:73:52 ❯ src/services/tag.service.spec.ts:167:7
await this.removeAssets(auth, id, { ids: assetIdList });

await this.tagRepository.delete(id);
}
Expand Down
Loading