Skip to content

Commit

Permalink
fix: and same results as other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
martabal committed Oct 14, 2024
1 parent 5889faa commit 1ea3b54
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
34 changes: 25 additions & 9 deletions server/src/queries/album.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,11 @@ FROM
LEFT JOIN "users" "owner" ON "owner"."id" = "album"."ownerId"
AND ("owner"."deletedAt" IS NULL)
LEFT JOIN "albums_shared_users_users" "album_users" ON "album_users"."albumsId" = "album"."id"
LEFT JOIN "users" "user" ON "user"."id" = "album_users"."usersId"
AND ("user"."deletedAt" IS NULL)
WHERE
(
(
"album"."ownerId" = $1
OR "album_users"."usersId" = $1
)
("album"."ownerId" = $1)
AND (
LOWER("album"."albumName") LIKE $2
OR LOWER("album"."albumName") LIKE $3
Expand Down Expand Up @@ -566,18 +565,35 @@ SELECT
"owner"."updatedAt" AS "owner_updatedAt",
"owner"."quotaSizeInBytes" AS "owner_quotaSizeInBytes",
"owner"."quotaUsageInBytes" AS "owner_quotaUsageInBytes",
"owner"."profileChangedAt" AS "owner_profileChangedAt"
"owner"."profileChangedAt" AS "owner_profileChangedAt",
"album_users"."albumsId" AS "album_users_albumsId",
"album_users"."usersId" AS "album_users_usersId",
"album_users"."role" AS "album_users_role",
"user"."id" AS "user_id",
"user"."name" AS "user_name",
"user"."isAdmin" AS "user_isAdmin",
"user"."email" AS "user_email",
"user"."storageLabel" AS "user_storageLabel",
"user"."oauthId" AS "user_oauthId",
"user"."profileImagePath" AS "user_profileImagePath",
"user"."shouldChangePassword" AS "user_shouldChangePassword",
"user"."createdAt" AS "user_createdAt",
"user"."deletedAt" AS "user_deletedAt",
"user"."status" AS "user_status",
"user"."updatedAt" AS "user_updatedAt",
"user"."quotaSizeInBytes" AS "user_quotaSizeInBytes",
"user"."quotaUsageInBytes" AS "user_quotaUsageInBytes",
"user"."profileChangedAt" AS "user_profileChangedAt"
FROM
"albums" "album"
LEFT JOIN "users" "owner" ON "owner"."id" = "album"."ownerId"
AND ("owner"."deletedAt" IS NULL)
LEFT JOIN "albums_shared_users_users" "album_users" ON "album_users"."albumsId" = "album"."id"
LEFT JOIN "users" "user" ON "user"."id" = "album_users"."usersId"
AND ("user"."deletedAt" IS NULL)
WHERE
(
(
"album"."ownerId" = $1
OR "album_users"."usersId" = $1
)
("album"."ownerId" = $1)
AND (
LOWER("album"."albumName") LIKE $2
OR LOWER("album"."albumName") LIKE $3
Expand Down
13 changes: 9 additions & 4 deletions server/src/repositories/album.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ export class AlbumRepository implements IAlbumRepository {
const getAlbumSharedOptions = () => {
switch (shared) {
case true: {
return { owner: '(album_users.usersId = :userId)', options: '' };
return {
owner:
'(album_users.usersId = :userId OR shared_links.userId = :userId OR (album.ownerId = :userId AND album_users.usersId IS NOT NULL))',
options: '',
};
}
case false: {
return {
Expand All @@ -324,7 +328,7 @@ export class AlbumRepository implements IAlbumRepository {
};
}
case undefined: {
return { owner: '(album.ownerId = :userId OR album_users.usersId = :userId)', options: '' };
return { owner: '(album.ownerId = :userId)', options: '' };
}
}
};
Expand All @@ -334,9 +338,10 @@ export class AlbumRepository implements IAlbumRepository {
let queryBuilder = this.repository
.createQueryBuilder('album')
.leftJoinAndSelect('album.owner', 'owner')
.leftJoin('albums_shared_users_users', 'album_users', 'album_users.albumsId = album.id');
.leftJoinAndSelect('album.albumUsers', 'album_users')
.leftJoinAndSelect('album_users.user', 'user');

if (shared === false) {
if (shared !== undefined) {
queryBuilder = queryBuilder.leftJoin('shared_links', 'shared_links', 'shared_links.albumId = album.id');
}

Expand Down

0 comments on commit 1ea3b54

Please sign in to comment.