refactor: make Donation.donor optional
This commit is contained in:
parent
d06f6a4407
commit
2ab6e985e3
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user