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 a60209d commit 239d4f5
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);

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

0 comments on commit 239d4f5

Please sign in to comment.