fix e2e tests and some bugs

This commit is contained in:
mgabor
2024-04-22 13:50:28 +02:00
parent ba8b57a9d9
commit 2cc9220b47
3 changed files with 26 additions and 15 deletions

View File

@@ -53,7 +53,7 @@ export class AlbumEntity {
@Column({ comment: 'Asset ID to be used as thumbnail', nullable: true })
albumThumbnailAssetId!: string | null;
@OneToMany(() => AlbumUserEntity, ({ album }) => album)
@OneToMany(() => AlbumUserEntity, ({ album }) => album, { cascade: true, onDelete: 'CASCADE' })
albumUsers!: AlbumUserEntity[];
@ManyToMany(() => AssetEntity, (asset) => asset.albums)

View File

@@ -214,7 +214,7 @@ export class AlbumService {
async addUsers(auth: AuthDto, id: string, dto: AddUsersDto): Promise<AlbumResponseDto> {
await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id);
const album = await this.findOrFail(id, { withAssets: true });
const album = await this.findOrFail(id, { withAssets: false });
for (const userId of dto.sharedUserIds) {
if (album.ownerId === userId) {
@@ -234,7 +234,7 @@ export class AlbumService {
album.albumUsers.push(await this.albumUserRepository.create({ userId: userId, albumId: id }));
}
return mapAlbumWithoutAssets(album);
return this.findOrFail(id, { withAssets: true }).then(mapAlbumWithoutAssets);
}
async removeUser(auth: AuthDto, id: string, userId: string | 'me'): Promise<void> {
@@ -264,13 +264,6 @@ export class AlbumService {
async updateUser(auth: AuthDto, id: string, userId: string, dto: Partial<AlbumUserEntity>): Promise<void> {
await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id);
const album = await this.findOrFail(id, { withAssets: false });
const permission = album.albumUsers.find(({ user: { id } }) => id === userId);
if (!permission) {
throw new BadRequestException('Album not shared with user');
}
await this.albumUserRepository.update({ albumId: id, userId }, { role: dto.role });
}