refactor: make Donation.donor optional

This commit is contained in:
Philipp Dormann 2025-04-28 10:56:06 +02:00
parent d06f6a4407
commit 2ab6e985e3
Signed by: philipp
GPG Key ID: 3BB9ADD52DCA4314
2 changed files with 2 additions and 7 deletions

View File

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

View File

@ -1,6 +1,5 @@
import { import {
IsInt, IsInt
IsNotEmpty
} from "class-validator"; } from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { ResponseDonation } from '../responses/ResponseDonation'; import { ResponseDonation } from '../responses/ResponseDonation';
@ -24,7 +23,6 @@ export abstract class Donation {
/** /**
* The donations's donor. * The donations's donor.
*/ */
@IsNotEmpty()
@ManyToOne(() => Donor, donor => donor.donations) @ManyToOne(() => Donor, donor => donor.donations)
donor: Donor; donor: Donor;