a097e903c9
* wip * span class decorator fix typing * improvements * noisy postgres logs formatting * add source * strict string comparison Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> * remove debug code * execution time histogram * remove prometheus stuff remove prometheus data * disable by default disable nestjs-otel stuff by default update imports * re-add postgres instrumentation formatting formatting * refactor: execution time histogram * decorator alias * formatting * keep original method order in filesystem repo * linting * enable otel sdk in e2e * actually enable otel sdk in e2e * share exclude paths * formatting * fix rebase * more buckets * add example setup * add envs fix actual fix * linting * update comments * update docker env * use more specific env --------- Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { IPartnerRepository, PartnerIds } from '@app/domain';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { DeepPartial, Repository } from 'typeorm';
|
|
import { PartnerEntity } from '../entities';
|
|
import { Instrumentation } from '../instrumentation';
|
|
|
|
@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 },
|
|
});
|
|
}
|
|
}
|