Skip to content

Commit

Permalink
fix: include assets shared via owner albums
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed May 13, 2024
1 parent 8c2a4e9 commit 803d977
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
14 changes: 3 additions & 11 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ export class AssetRepository implements IAssetRepository {
isFavorite,
fileCreatedAt: OptionalBetween(fileCreatedAfter, fileCreatedBefore),
};

const assets = await this.repository.find({
select: {
id: true,
Expand All @@ -519,20 +520,11 @@ export class AssetRepository implements IAssetRepository {
},
},
where: [
{
ownerId: In([...ownerIds]),
...where,
},
{
albums: {
id: In([...albumIds]),
},
...where,
},
{ ...where, ownerId: In([...ownerIds]) },
{ ...where, albums: { id: In([...albumIds]) } },
],
relations: {
exifInfo: true,
albums: true,
},
order: {
fileCreatedAt: 'DESC',
Expand Down
13 changes: 10 additions & 3 deletions server/src/services/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,25 @@ export class AssetService {

async getMapMarkers(auth: AuthDto, options: MapMarkerDto): Promise<MapMarkerResponseDto[]> {
const userIds: string[] = [auth.user.id];
const albumIds: string[] = [];
// TODO convert to SQL join
if (options.withPartners) {
const partners = await this.partnerRepository.getAll(auth.user.id);
const partnersIds = partners
.filter((partner) => partner.sharedBy && partner.sharedWith && partner.sharedById != auth.user.id)
.map((partner) => partner.sharedById);
userIds.push(...partnersIds);
}

// TODO convert to SQL join
const albumIds: string[] = [];
if (options.withSharedAlbums) {
const sharedAlbums = await this.albumRepository.getShared(auth.user.id);
albumIds.push(...sharedAlbums.map((album) => album.id));
const [ownedAlbums, sharedAlbums] = await Promise.all([
this.albumRepository.getOwned(auth.user.id),
this.albumRepository.getShared(auth.user.id),
]);
albumIds.push(...ownedAlbums.map((album) => album.id), ...sharedAlbums.map((album) => album.id));
}

return this.assetRepository.getMapMarkers(userIds, albumIds, options);
}

Expand Down

0 comments on commit 803d977

Please sign in to comment.