set relations for getByIds

This commit is contained in:
mertalev 2023-11-05 19:44:31 -05:00
parent a0743d8b7d
commit ae4900d71c
No known key found for this signature in database
GPG key ID: 9181CD92C0A1C5E3
3 changed files with 17 additions and 7 deletions

View file

@ -216,7 +216,13 @@ export class PersonService {
return true;
}
const [asset] = await this.assetRepository.getByIds([id]);
const relations = {
exifInfo: true,
faces: {
person: true,
},
};
const [asset] = await this.assetRepository.getByIds([id], relations);
if (!asset || !asset.resizePath || asset.faces?.length > 0) {
return false;
}

View file

@ -1,4 +1,5 @@
import { AssetEntity, AssetType, ExifEntity } from '@app/infra/entities';
import { FindOptionsRelations } from 'typeorm';
import { Paginated, PaginationOptions } from '../domain.util';
export type AssetStats = Record<AssetType, number>;
@ -99,7 +100,7 @@ export const IAssetRepository = 'IAssetRepository';
export interface IAssetRepository {
create(asset: AssetCreate): Promise<AssetEntity>;
getByDate(ownerId: string, date: Date): Promise<AssetEntity[]>;
getByIds(ids: string[]): Promise<AssetEntity[]>;
getByIds(ids: string[], relations?: FindOptionsRelations<AssetEntity>): Promise<AssetEntity[]>;
getByDayOfYear(ownerId: string, monthDay: MonthDay): Promise<AssetEntity[]>;
getByChecksum(userId: string, checksum: Buffer): Promise<AssetEntity | null>;
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;

View file

@ -104,10 +104,9 @@ export class AssetRepository implements IAssetRepository {
.getMany();
}
getByIds(ids: string[]): Promise<AssetEntity[]> {
return this.repository.find({
where: { id: In(ids) },
relations: {
getByIds(ids: string[], relations?: FindOptionsRelations<AssetEntity>): Promise<AssetEntity[]> {
if (!relations) {
relations = {
exifInfo: true,
smartInfo: true,
tags: true,
@ -115,7 +114,11 @@ export class AssetRepository implements IAssetRepository {
person: true,
},
stack: true,
},
};
}
return this.repository.find({
where: { id: In(ids) },
relations,
withDeleted: true,
});
}