|
|
|
|
@ -5,7 +5,7 @@ import { LibraryStatsResponseDto } from 'src/dtos/library.dto';
|
|
|
|
|
import { LibraryEntity } from 'src/entities/library.entity';
|
|
|
|
|
import { ILibraryRepository } from 'src/interfaces/library.interface';
|
|
|
|
|
import { Instrumentation } from 'src/utils/instrumentation';
|
|
|
|
|
import { EntityNotFoundError, IsNull, Not } from 'typeorm';
|
|
|
|
|
import { IsNull, Not } from 'typeorm';
|
|
|
|
|
import { Repository } from 'typeorm/repository/Repository.js';
|
|
|
|
|
|
|
|
|
|
@Instrumentation()
|
|
|
|
|
@ -24,21 +24,6 @@ export class LibraryRepository implements ILibraryRepository {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GenerateSql({ params: [DummyValue.STRING] })
|
|
|
|
|
existsByName(name: string, withDeleted = false): Promise<boolean> {
|
|
|
|
|
return this.repository.exist({
|
|
|
|
|
where: {
|
|
|
|
|
name,
|
|
|
|
|
},
|
|
|
|
|
withDeleted,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
|
|
|
getCountForUser(ownerId: string): Promise<number> {
|
|
|
|
|
return this.repository.countBy({ ownerId });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GenerateSql({ params: [] })
|
|
|
|
|
getAll(withDeleted = false): Promise<LibraryEntity[]> {
|
|
|
|
|
return this.repository.find({
|
|
|
|
|
@ -85,7 +70,7 @@ export class LibraryRepository implements ILibraryRepository {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
|
|
|
async getStatistics(id: string): Promise<LibraryStatsResponseDto> {
|
|
|
|
|
async getStatistics(id: string): Promise<LibraryStatsResponseDto | undefined> {
|
|
|
|
|
const stats = await this.repository
|
|
|
|
|
.createQueryBuilder('libraries')
|
|
|
|
|
.addSelect(`COUNT(assets.id) FILTER (WHERE assets.type = 'IMAGE' AND assets.isVisible)`, 'photos')
|
|
|
|
|
@ -98,7 +83,7 @@ export class LibraryRepository implements ILibraryRepository {
|
|
|
|
|
.getRawOne();
|
|
|
|
|
|
|
|
|
|
if (!stats) {
|
|
|
|
|
throw new EntityNotFoundError(LibraryEntity, { where: { id } });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
@ -109,26 +94,6 @@ export class LibraryRepository implements ILibraryRepository {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
|
|
|
async getOnlineAssetPaths(libraryId: string): Promise<string[]> {
|
|
|
|
|
// Return all non-offline asset paths for a given library
|
|
|
|
|
const rawResults = await this.repository
|
|
|
|
|
.createQueryBuilder('library')
|
|
|
|
|
.innerJoinAndSelect('library.assets', 'assets')
|
|
|
|
|
.where('library.id = :id', { id: libraryId })
|
|
|
|
|
.andWhere('assets.isOffline = false')
|
|
|
|
|
.select('assets.originalPath')
|
|
|
|
|
.getRawMany();
|
|
|
|
|
|
|
|
|
|
const results: string[] = [];
|
|
|
|
|
|
|
|
|
|
for (const rawPath of rawResults) {
|
|
|
|
|
results.push(rawPath.assets_originalPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
|
|
|
async getAssetIds(libraryId: string, withDeleted = false): Promise<string[]> {
|
|
|
|
|
const builder = this.repository
|
|
|
|
|
|