mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
3c9fb651d0
* feat: SyncAssetEditV1 * fix: audit table import * fix: sql tools table fetch * fix: medium tests (wip) * fix: circ dependency * chore: finalize tests * chore: codegen/lint * fix: code review
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { Kysely } from 'kysely';
|
|
import { InjectKysely } from 'nestjs-kysely';
|
|
import { columns } from 'src/database';
|
|
import { DummyValue, GenerateSql } from 'src/decorators';
|
|
import { AssetEditActionItem, AssetEditActionItemResponseDto } from 'src/dtos/editing.dto';
|
|
import { DB } from 'src/schema';
|
|
|
|
@Injectable()
|
|
export class AssetEditRepository {
|
|
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
replaceAll(assetId: string, edits: AssetEditActionItem[]): Promise<AssetEditActionItemResponseDto[]> {
|
|
return this.db.transaction().execute(async (trx) => {
|
|
await trx.deleteFrom('asset_edit').where('assetId', '=', assetId).execute();
|
|
|
|
if (edits.length > 0) {
|
|
return trx
|
|
.insertInto('asset_edit')
|
|
.values(edits.map((edit, i) => ({ assetId, sequence: i, ...edit })))
|
|
.returning(['id', 'action', 'parameters'])
|
|
.execute();
|
|
}
|
|
|
|
return [];
|
|
});
|
|
}
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
getAll(assetId: string): Promise<AssetEditActionItemResponseDto[]> {
|
|
return this.db
|
|
.selectFrom('asset_edit')
|
|
.select(['id', 'action', 'parameters'])
|
|
.where('assetId', '=', assetId)
|
|
.orderBy('sequence', 'asc')
|
|
.execute();
|
|
}
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
getWithSyncInfo(assetId: string) {
|
|
return this.db
|
|
.selectFrom('asset_edit')
|
|
.select(columns.syncAssetEdit)
|
|
.where('assetId', '=', assetId)
|
|
.orderBy('sequence', 'asc')
|
|
.execute();
|
|
}
|
|
}
|