mirror of
https://github.com/immich-app/immich.git
synced 2026-03-04 09:57:33 +03:00
refactor(server): rename asset stack to stack (#10828)
This commit is contained in:
56
server/src/repositories/stack.repository.ts
Normal file
56
server/src/repositories/stack.repository.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { StackEntity } from 'src/entities/stack.entity';
|
||||
import { IStackRepository } from 'src/interfaces/stack.interface';
|
||||
import { Instrumentation } from 'src/utils/instrumentation';
|
||||
import { In, Repository } from 'typeorm';
|
||||
|
||||
@Instrumentation()
|
||||
@Injectable()
|
||||
export class StackRepository implements IStackRepository {
|
||||
constructor(@InjectRepository(StackEntity) private repository: Repository<StackEntity>) {}
|
||||
|
||||
create(entity: Partial<StackEntity>) {
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.repository.delete(id);
|
||||
}
|
||||
|
||||
update(entity: Partial<StackEntity>) {
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<StackEntity | null> {
|
||||
return this.repository.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: {
|
||||
primaryAsset: true,
|
||||
assets: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async deleteAll(userId: string): Promise<void> {
|
||||
// TODO add owner to stack entity
|
||||
const stacks = await this.repository.find({ where: { primaryAsset: { ownerId: userId } } });
|
||||
const stackIds = new Set(stacks.map((stack) => stack.id));
|
||||
await this.repository.delete({ id: In([...stackIds]) });
|
||||
}
|
||||
|
||||
private async save(entity: Partial<StackEntity>) {
|
||||
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