wip
This commit is contained in:
parent
ce9b765b81
commit
9875b4f392
@ -4,6 +4,7 @@ import { Repository, getConnectionManager } from 'typeorm';
|
||||
import { DonationIdsNotMatchingError, DonationNotFoundError } from '../errors/DonationErrors';
|
||||
import { DonorNotFoundError } from '../errors/DonorErrors';
|
||||
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||
import { CreateAnonymousDonation } from '../models/actions/create/CreateAnonymousDonation';
|
||||
import { CreateDistanceDonation } from '../models/actions/create/CreateDistanceDonation';
|
||||
import { CreateFixedDonation } from '../models/actions/create/CreateFixedDonation';
|
||||
import { UpdateDistanceDonation } from '../models/actions/update/UpdateDistanceDonation';
|
||||
@ -76,6 +77,17 @@ export class DonationController {
|
||||
return (await this.donationRepository.findOne({ id: donation.id }, { relations: ['donor'] })).toResponse();
|
||||
}
|
||||
|
||||
@Post('/anonymous')
|
||||
@Authorized("DONATION:CREATE")
|
||||
@ResponseSchema(ResponseDonation)
|
||||
@ResponseSchema(DonorNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Create a anonymous donation' })
|
||||
async postAnonymous(@Body({ validate: true }) createDonation: CreateAnonymousDonation) {
|
||||
let donation = await createDonation.toEntity();
|
||||
donation = await this.fixedDonationRepository.save(donation);
|
||||
return (await this.donationRepository.findOne({ id: donation.id })).toResponse();
|
||||
}
|
||||
|
||||
@Post('/distance')
|
||||
@Authorized("DONATION:CREATE")
|
||||
@ResponseSchema(ResponseDistanceDonation)
|
||||
|
29
src/models/actions/create/CreateAnonymousDonation.ts
Normal file
29
src/models/actions/create/CreateAnonymousDonation.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { IsInt, IsPositive } from 'class-validator';
|
||||
import { FixedDonation } from '../../entities/FixedDonation';
|
||||
import { CreateDonation } from './CreateDonation';
|
||||
|
||||
/**
|
||||
* This class is used to create a new FixedDonation entity from a json body (post request).
|
||||
*/
|
||||
export class CreateAnonymousDonation extends CreateDonation {
|
||||
|
||||
/**
|
||||
* The donation's amount.
|
||||
* The unit is your currency's smallest unit (default: euro cent).
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
amount: number;
|
||||
|
||||
/**
|
||||
* Creates a new FixedDonation entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<FixedDonation> {
|
||||
let newDonation = new FixedDonation;
|
||||
|
||||
newDonation.amount = this.amount;
|
||||
newDonation.paidAmount = this.paidAmount;
|
||||
|
||||
return newDonation;
|
||||
}
|
||||
}
|
@ -10,6 +10,14 @@ import { CreateDonation } from './CreateDonation';
|
||||
*/
|
||||
export class CreateDistanceDonation extends CreateDonation {
|
||||
|
||||
/**
|
||||
* The donation's associated donor's id.
|
||||
* This is important to link donations to donors.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
donor: number;
|
||||
|
||||
/**
|
||||
* The donation's associated runner's id.
|
||||
* This is important to link the runner's distance ran to the donation.
|
||||
|
@ -6,6 +6,15 @@ import { CreateDonation } from './CreateDonation';
|
||||
* This class is used to create a new FixedDonation entity from a json body (post request).
|
||||
*/
|
||||
export class CreateFixedDonation extends CreateDonation {
|
||||
|
||||
/**
|
||||
* The donation's associated donor's id.
|
||||
* This is important to link donations to donors.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
donor: number;
|
||||
|
||||
/**
|
||||
* The donation's amount.
|
||||
* The unit is your currency's smallest unit (default: euro cent).
|
||||
|
Loading…
x
Reference in New Issue
Block a user