mirror of
https://github.com/immich-app/immich.git
synced 2024-12-28 22:51:59 +00:00
handle updates to path
fix typing simplify type
This commit is contained in:
parent
011520b127
commit
cfeec70e44
2 changed files with 18 additions and 5 deletions
|
@ -100,10 +100,7 @@ export type AssetWithoutRelations = Omit<
|
||||||
| 'tags'
|
| 'tags'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type AssetUpdateWithoutRelations = Pick<AssetWithoutRelations, 'id'> & Partial<AssetWithoutRelations>;
|
export type AssetUpdateOptions = Partial<AssetWithoutRelations & Pick<AssetEntity, 'livePhotoVideo'>>;
|
||||||
type AssetUpdateWithLivePhotoRelation = Pick<AssetWithoutRelations, 'id'> & Pick<AssetEntity, 'livePhotoVideo'>;
|
|
||||||
|
|
||||||
export type AssetUpdateOptions = AssetUpdateWithoutRelations | AssetUpdateWithLivePhotoRelation;
|
|
||||||
|
|
||||||
export type AssetUpdateAllOptions = Omit<Partial<AssetWithoutRelations>, 'id'>;
|
export type AssetUpdateAllOptions = Omit<Partial<AssetWithoutRelations>, 'id'>;
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,23 @@ export class AssetRepository implements IAssetRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(asset: AssetUpdateOptions): Promise<void> {
|
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> {
|
async remove(asset: AssetEntity): Promise<void> {
|
||||||
|
|
Loading…
Reference in a new issue