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 { 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;
}
}

View File

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