refactor: remove move entity (#17489)

This commit is contained in:
Zack Pollard 2025-04-09 16:54:20 +01:00 committed by GitHub
parent 206545356d
commit d03647904b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 28 deletions

View File

@ -1,9 +0,0 @@
import { PathType } from 'src/enum';
export class MoveEntity {
id!: string;
entityId!: string;
pathType!: PathType;
oldPath!: string;
newPath!: string;
}

View File

@ -3,49 +3,38 @@ import { Insertable, Kysely, sql, Updateable } from 'kysely';
import { InjectKysely } from 'nestjs-kysely';
import { DB, MoveHistory } from 'src/db';
import { DummyValue, GenerateSql } from 'src/decorators';
import { MoveEntity } from 'src/entities/move.entity';
import { AssetPathType, PathType } from 'src/enum';
export type MoveCreate = Pick<MoveEntity, 'oldPath' | 'newPath' | 'entityId' | 'pathType'> & Partial<MoveEntity>;
@Injectable()
export class MoveRepository {
constructor(@InjectKysely() private db: Kysely<DB>) {}
create(entity: Insertable<MoveHistory>): Promise<MoveEntity> {
return this.db
.insertInto('move_history')
.values(entity)
.returningAll()
.executeTakeFirstOrThrow() as Promise<MoveEntity>;
create(entity: Insertable<MoveHistory>) {
return this.db.insertInto('move_history').values(entity).returningAll().executeTakeFirstOrThrow();
}
@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING] })
getByEntity(entityId: string, pathType: PathType): Promise<MoveEntity | undefined> {
getByEntity(entityId: string, pathType: PathType) {
return this.db
.selectFrom('move_history')
.selectAll()
.where('entityId', '=', entityId)
.where('pathType', '=', pathType)
.executeTakeFirst() as Promise<MoveEntity | undefined>;
.executeTakeFirst();
}
update(id: string, entity: Updateable<MoveHistory>): Promise<MoveEntity> {
update(id: string, entity: Updateable<MoveHistory>) {
return this.db
.updateTable('move_history')
.set(entity)
.where('id', '=', id)
.returningAll()
.executeTakeFirstOrThrow() as unknown as Promise<MoveEntity>;
.executeTakeFirstOrThrow();
}
@GenerateSql({ params: [DummyValue.UUID] })
delete(id: string): Promise<MoveEntity> {
return this.db
.deleteFrom('move_history')
.where('id', '=', id)
.returningAll()
.executeTakeFirstOrThrow() as unknown as Promise<MoveEntity>;
delete(id: string) {
return this.db.deleteFrom('move_history').where('id', '=', id).returningAll().executeTakeFirstOrThrow();
}
@GenerateSql()