hotfix(server): getAlbumByAssetId alters album content (#1828)

This commit is contained in:
Alex 2023-02-21 21:53:00 -06:00 committed by GitHub
parent 9ebed3c1b4
commit 3102c3128f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import { AlbumEntity, AssetEntity, UserEntity } from '@app/infra'; import { AlbumEntity, AssetEntity, UserEntity } from '@app/infra';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository, Not, IsNull, FindManyOptions } from 'typeorm'; import { Repository, Not, IsNull, FindManyOptions, In } from 'typeorm';
import { AddAssetsDto } from './dto/add-assets.dto'; import { AddAssetsDto } from './dto/add-assets.dto';
import { AddUsersDto } from './dto/add-users.dto'; import { AddUsersDto } from './dto/add-users.dto';
import { CreateAlbumDto } from './dto/create-album.dto'; import { CreateAlbumDto } from './dto/create-album.dto';
@ -121,12 +121,12 @@ export class AlbumRepository implements IAlbumRepository {
async getListByAssetId(userId: string, assetId: string): Promise<AlbumEntity[]> { async getListByAssetId(userId: string, assetId: string): Promise<AlbumEntity[]> {
const albums = await this.albumRepository.find({ const albums = await this.albumRepository.find({
where: { ownerId: userId, assets: { id: assetId } }, where: { ownerId: userId },
relations: { owner: true, assets: true, sharedUsers: true }, relations: { owner: true, assets: true, sharedUsers: true },
order: { assets: { fileCreatedAt: 'ASC' } }, order: { assets: { fileCreatedAt: 'ASC' } },
}); });
return albums; return albums.filter((album) => album.assets.some((asset) => asset.id === assetId));
} }
async get(albumId: string): Promise<AlbumEntity | null> { async get(albumId: string): Promise<AlbumEntity | null> {