From cfeec70e44888248851b1b4dc3114b87ffffb0f5 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Mon, 2 Sep 2024 18:01:36 -0400 Subject: [PATCH] handle updates to path fix typing simplify type --- server/src/interfaces/asset.interface.ts | 5 +---- server/src/repositories/asset.repository.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/server/src/interfaces/asset.interface.ts b/server/src/interfaces/asset.interface.ts index 09d93d3ac7..a7ab36d852 100644 --- a/server/src/interfaces/asset.interface.ts +++ b/server/src/interfaces/asset.interface.ts @@ -100,10 +100,7 @@ export type AssetWithoutRelations = Omit< | 'tags' >; -type AssetUpdateWithoutRelations = Pick & Partial; -type AssetUpdateWithLivePhotoRelation = Pick & Pick; - -export type AssetUpdateOptions = AssetUpdateWithoutRelations | AssetUpdateWithLivePhotoRelation; +export type AssetUpdateOptions = Partial>; export type AssetUpdateAllOptions = Omit, 'id'>; diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts index 9c9eaa72fb..ae7ecd6d9a 100644 --- a/server/src/repositories/asset.repository.ts +++ b/server/src/repositories/asset.repository.ts @@ -336,7 +336,23 @@ export class AssetRepository implements IAssetRepository { } async update(asset: AssetUpdateOptions): Promise { - await this.repository.update(asset.id, asset); + const values: QueryDeepPartialEntity = 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 {