feat: add partner create endpoint (#21625)

This commit is contained in:
Jason Rasmussen
2025-09-05 17:59:11 -04:00
committed by GitHub
parent db0ea0f3a8
commit 5a7042364b
18 changed files with 477 additions and 75 deletions

View File

@@ -53,7 +53,7 @@ describe(PartnerService.name, () => {
mocks.partner.get.mockResolvedValue(void 0);
mocks.partner.create.mockResolvedValue(partner);
await expect(sut.create(auth, user2.id)).resolves.toBeDefined();
await expect(sut.create(auth, { sharedWithId: user2.id })).resolves.toBeDefined();
expect(mocks.partner.create).toHaveBeenCalledWith({
sharedById: partner.sharedById,
@@ -69,7 +69,7 @@ describe(PartnerService.name, () => {
mocks.partner.get.mockResolvedValue(partner);
await expect(sut.create(auth, user2.id)).rejects.toBeInstanceOf(BadRequestException);
await expect(sut.create(auth, { sharedWithId: user2.id })).rejects.toBeInstanceOf(BadRequestException);
expect(mocks.partner.create).not.toHaveBeenCalled();
});

View File

@@ -1,7 +1,7 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { Partner } from 'src/database';
import { AuthDto } from 'src/dtos/auth.dto';
import { PartnerResponseDto, PartnerSearchDto, UpdatePartnerDto } from 'src/dtos/partner.dto';
import { PartnerCreateDto, PartnerResponseDto, PartnerSearchDto, PartnerUpdateDto } from 'src/dtos/partner.dto';
import { mapUser } from 'src/dtos/user.dto';
import { Permission } from 'src/enum';
import { PartnerDirection, PartnerIds } from 'src/repositories/partner.repository';
@@ -9,7 +9,7 @@ import { BaseService } from 'src/services/base.service';
@Injectable()
export class PartnerService extends BaseService {
async create(auth: AuthDto, sharedWithId: string): Promise<PartnerResponseDto> {
async create(auth: AuthDto, { sharedWithId }: PartnerCreateDto): Promise<PartnerResponseDto> {
const partnerId: PartnerIds = { sharedById: auth.user.id, sharedWithId };
const exists = await this.partnerRepository.get(partnerId);
if (exists) {
@@ -39,7 +39,7 @@ export class PartnerService extends BaseService {
.map((partner) => this.mapPartner(partner, direction));
}
async update(auth: AuthDto, sharedById: string, dto: UpdatePartnerDto): Promise<PartnerResponseDto> {
async update(auth: AuthDto, sharedById: string, dto: PartnerUpdateDto): Promise<PartnerResponseDto> {
await this.requireAccess({ auth, permission: Permission.PartnerUpdate, ids: [sharedById] });
const partnerId: PartnerIds = { sharedById, sharedWithId: auth.user.id };