feat(server) Tagging system (#1046)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { SearchPropertiesDto } from './dto/search-properties.dto';
|
||||
import { CuratedLocationsResponseDto } from './response-dto/curated-locations-response.dto';
|
||||
import { AssetEntity, AssetType } from '@app/database/entities/asset.entity';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm/repository/Repository';
|
||||
import { CreateAssetDto } from './dto/create-asset.dto';
|
||||
@@ -14,6 +14,7 @@ import { CheckExistingAssetsDto } from './dto/check-existing-assets.dto';
|
||||
import { CheckExistingAssetsResponseDto } from './response-dto/check-existing-assets-response.dto';
|
||||
import { In } from 'typeorm/find-options/operator/In';
|
||||
import { UpdateAssetDto } from './dto/update-asset.dto';
|
||||
import { ITagRepository, TAG_REPOSITORY } from '../tag/tag.repository';
|
||||
|
||||
export interface IAssetRepository {
|
||||
create(
|
||||
@@ -25,7 +26,7 @@ export interface IAssetRepository {
|
||||
checksum?: Buffer,
|
||||
livePhotoAssetEntity?: AssetEntity,
|
||||
): Promise<AssetEntity>;
|
||||
update(asset: AssetEntity, dto: UpdateAssetDto): Promise<AssetEntity>;
|
||||
update(userId: string, asset: AssetEntity, dto: UpdateAssetDto): Promise<AssetEntity>;
|
||||
getAllByUserId(userId: string, skip?: number): Promise<AssetEntity[]>;
|
||||
getAllByDeviceId(userId: string, deviceId: string): Promise<string[]>;
|
||||
getById(assetId: string): Promise<AssetEntity>;
|
||||
@@ -53,6 +54,8 @@ export class AssetRepository implements IAssetRepository {
|
||||
constructor(
|
||||
@InjectRepository(AssetEntity)
|
||||
private assetRepository: Repository<AssetEntity>,
|
||||
|
||||
@Inject(TAG_REPOSITORY) private _tagRepository: ITagRepository,
|
||||
) {}
|
||||
|
||||
async getAssetWithNoSmartInfo(): Promise<AssetEntity[]> {
|
||||
@@ -222,7 +225,7 @@ export class AssetRepository implements IAssetRepository {
|
||||
where: {
|
||||
id: assetId,
|
||||
},
|
||||
relations: ['exifInfo'],
|
||||
relations: ['exifInfo', 'tags'],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -237,9 +240,9 @@ export class AssetRepository implements IAssetRepository {
|
||||
.andWhere('asset.resizePath is not NULL')
|
||||
.andWhere('asset.isVisible = true')
|
||||
.leftJoinAndSelect('asset.exifInfo', 'exifInfo')
|
||||
.leftJoinAndSelect('asset.tags', 'tags')
|
||||
.skip(skip || 0)
|
||||
.orderBy('asset.createdAt', 'DESC');
|
||||
|
||||
return await query.getMany();
|
||||
}
|
||||
|
||||
@@ -286,9 +289,14 @@ export class AssetRepository implements IAssetRepository {
|
||||
/**
|
||||
* Update asset
|
||||
*/
|
||||
async update(asset: AssetEntity, dto: UpdateAssetDto): Promise<AssetEntity> {
|
||||
async update(userId: string, asset: AssetEntity, dto: UpdateAssetDto): Promise<AssetEntity> {
|
||||
asset.isFavorite = dto.isFavorite ?? asset.isFavorite;
|
||||
|
||||
if (dto.tagIds) {
|
||||
const tags = await this._tagRepository.getByIds(userId, dto.tagIds);
|
||||
asset.tags = tags;
|
||||
}
|
||||
|
||||
return await this.assetRepository.save(asset);
|
||||
}
|
||||
|
||||
@@ -347,10 +355,10 @@ export class AssetRepository implements IAssetRepository {
|
||||
|
||||
async countByIdAndUser(assetId: string, userId: string): Promise<number> {
|
||||
return await this.assetRepository.count({
|
||||
where: {
|
||||
id: assetId,
|
||||
userId
|
||||
}
|
||||
where: {
|
||||
id: assetId,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user