1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 06:31:58 +00:00

handle updates to path

fix typing

simplify type
This commit is contained in:
mertalev 2024-09-02 18:01:36 -04:00
parent 011520b127
commit cfeec70e44
No known key found for this signature in database
GPG key ID: 9181CD92C0A1C5E3
2 changed files with 18 additions and 5 deletions

View file

@ -100,10 +100,7 @@ export type AssetWithoutRelations = Omit<
| 'tags'
>;
type AssetUpdateWithoutRelations = Pick<AssetWithoutRelations, 'id'> & Partial<AssetWithoutRelations>;
type AssetUpdateWithLivePhotoRelation = Pick<AssetWithoutRelations, 'id'> & Pick<AssetEntity, 'livePhotoVideo'>;
export type AssetUpdateOptions = AssetUpdateWithoutRelations | AssetUpdateWithLivePhotoRelation;
export type AssetUpdateOptions = Partial<AssetWithoutRelations & Pick<AssetEntity, 'livePhotoVideo'>>;
export type AssetUpdateAllOptions = Omit<Partial<AssetWithoutRelations>, 'id'>;

View file

@ -336,7 +336,23 @@ export class AssetRepository implements IAssetRepository {
}
async update(asset: AssetUpdateOptions): Promise<void> {
await this.repository.update(asset.id, asset);
const values: QueryDeepPartialEntity<AssetEntity> = asset;
const query = this.repository.createQueryBuilder('asset').update().where('id = :id', { id: asset.id });
if (asset.originalPath) {
const cte = this.repository.manager
.createQueryBuilder()
.insert()
.into(AssetFolderEntity)
.values({ path: () => 'file_parent(:path)' })
.orIgnore()
.returning('id');
values.folderId = coalesceFolderId; // use newly inserted folder id or query for existing folder id
query.addCommonTableExpression(cte, 'folder').setParameter('path', values.originalPath);
}
await query.set(values).execute();
}
async remove(asset: AssetEntity): Promise<void> {