refactor: make Donation.donor optional

This commit is contained in:
2025-04-28 10:56:06 +02:00
parent d06f6a4407
commit 2ab6e985e3
2 changed files with 2 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
import { IsInt, IsOptional, IsPositive } from 'class-validator';
import { getConnection } from 'typeorm';
import { DonorNotFoundError } from '../../../errors/DonorErrors';
import { Donation } from '../../entities/Donation';
import { Donor } from '../../entities/Donor';
@@ -14,6 +13,7 @@ export abstract class CreateDonation {
*/
@IsInt()
@IsPositive()
@IsOptional()
donor: number;
/**
@@ -33,9 +33,6 @@ export abstract class CreateDonation {
*/
public async getDonor(): Promise<Donor> {
const donor = await getConnection().getRepository(Donor).findOne({ id: this.donor });
if (!donor) {
throw new DonorNotFoundError();
}
return donor;
}
}