chore: migrate database files (#8126)

This commit is contained in:
Jason Rasmussen
2024-03-20 16:02:51 -05:00
committed by GitHub
parent 84f7ca855a
commit c1402eee8e
310 changed files with 358 additions and 362 deletions

View 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 },
});
}
}