2023-03-02 21:47:08 -05:00
|
|
|
import { AssetSearchOptions, IAssetRepository } from '@app/domain';
|
2023-02-25 09:12:03 -05:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
import { Not, Repository } from 'typeorm';
|
|
|
|
|
import { AssetEntity, AssetType } from '../entities';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class AssetRepository implements IAssetRepository {
|
|
|
|
|
constructor(@InjectRepository(AssetEntity) private repository: Repository<AssetEntity>) {}
|
|
|
|
|
|
|
|
|
|
async deleteAll(ownerId: string): Promise<void> {
|
|
|
|
|
await this.repository.delete({ ownerId });
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-02 21:47:08 -05:00
|
|
|
getAll(options?: AssetSearchOptions | undefined): Promise<AssetEntity[]> {
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
|
|
return this.repository.find({
|
|
|
|
|
where: {
|
|
|
|
|
isVisible: options.isVisible,
|
|
|
|
|
},
|
|
|
|
|
relations: {
|
|
|
|
|
exifInfo: true,
|
|
|
|
|
smartInfo: true,
|
|
|
|
|
tags: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-02-25 09:12:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async save(asset: Partial<AssetEntity>): Promise<AssetEntity> {
|
|
|
|
|
const { id } = await this.repository.save(asset);
|
2023-03-02 21:47:08 -05:00
|
|
|
return this.repository.findOneOrFail({
|
|
|
|
|
where: { id },
|
|
|
|
|
relations: {
|
|
|
|
|
exifInfo: true,
|
|
|
|
|
owner: true,
|
|
|
|
|
smartInfo: true,
|
|
|
|
|
tags: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-02-25 09:12:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findLivePhotoMatch(livePhotoCID: string, otherAssetId: string, type: AssetType): Promise<AssetEntity | null> {
|
|
|
|
|
return this.repository.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
id: Not(otherAssetId),
|
|
|
|
|
type,
|
|
|
|
|
exifInfo: {
|
|
|
|
|
livePhotoCID,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
relations: {
|
|
|
|
|
exifInfo: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|