mirror of
https://github.com/immich-app/immich.git
synced 2026-03-04 09:57:33 +03:00
chore: migrate database files (#8126)
This commit is contained in:
39
server/src/repositories/partner.repository.ts
Normal file
39
server/src/repositories/partner.repository.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { PartnerEntity } from 'src/entities/partner.entity';
|
||||
import { Instrumentation } from 'src/infra/instrumentation';
|
||||
import { IPartnerRepository, PartnerIds } from 'src/interfaces/partner.repository';
|
||||
import { DeepPartial, Repository } from 'typeorm';
|
||||
|
||||
@Instrumentation()
|
||||
@Injectable()
|
||||
export class PartnerRepository implements IPartnerRepository {
|
||||
constructor(@InjectRepository(PartnerEntity) private readonly repository: Repository<PartnerEntity>) {}
|
||||
|
||||
getAll(userId: string): Promise<PartnerEntity[]> {
|
||||
return this.repository.find({ where: [{ sharedWithId: userId }, { sharedById: userId }] });
|
||||
}
|
||||
|
||||
get({ sharedWithId, sharedById }: PartnerIds): Promise<PartnerEntity | null> {
|
||||
return this.repository.findOne({ where: { sharedById, sharedWithId } });
|
||||
}
|
||||
|
||||
create({ sharedById, sharedWithId }: PartnerIds): Promise<PartnerEntity> {
|
||||
return this.save({ sharedBy: { id: sharedById }, sharedWith: { id: sharedWithId } });
|
||||
}
|
||||
|
||||
async remove(entity: PartnerEntity): Promise<void> {
|
||||
await this.repository.remove(entity);
|
||||
}
|
||||
|
||||
update(entity: Partial<PartnerEntity>): Promise<PartnerEntity> {
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
private async save(entity: DeepPartial<PartnerEntity>): Promise<PartnerEntity> {
|
||||
await this.repository.save(entity);
|
||||
return this.repository.findOneOrFail({
|
||||
where: { sharedById: entity.sharedById, sharedWithId: entity.sharedWithId },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user