mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 02:27:23 +03:00
chore: migrate database files (#8126)
This commit is contained in:
49
server/src/repositories/asset-stack.repository.ts
Normal file
49
server/src/repositories/asset-stack.repository.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { AssetStackEntity } from 'src/entities/asset-stack.entity';
|
||||
import { Instrumentation } from 'src/infra/instrumentation';
|
||||
import { IAssetStackRepository } from 'src/interfaces/asset-stack.repository';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Instrumentation()
|
||||
@Injectable()
|
||||
export class AssetStackRepository implements IAssetStackRepository {
|
||||
constructor(@InjectRepository(AssetStackEntity) private repository: Repository<AssetStackEntity>) {}
|
||||
|
||||
create(entity: Partial<AssetStackEntity>) {
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.repository.delete(id);
|
||||
}
|
||||
|
||||
update(entity: Partial<AssetStackEntity>) {
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<AssetStackEntity | null> {
|
||||
return this.repository.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: {
|
||||
primaryAsset: true,
|
||||
assets: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async save(entity: Partial<AssetStackEntity>) {
|
||||
const { id } = await this.repository.save(entity);
|
||||
return this.repository.findOneOrFail({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: {
|
||||
primaryAsset: true,
|
||||
assets: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user