Added the basics for distance donation updateing

ref #66
This commit is contained in:
Nicolai Ort 2021-01-12 19:03:33 +01:00
parent 110387dbd3
commit 72c3fc78b3

View File

@ -87,7 +87,7 @@ export class DonationController {
@ResponseSchema(DonorNotFoundError, { statusCode: 404 }) @ResponseSchema(DonorNotFoundError, { statusCode: 404 })
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@ResponseSchema(DonationIdsNotMatchingError, { statusCode: 406 }) @ResponseSchema(DonationIdsNotMatchingError, { statusCode: 406 })
@OpenAPI({ description: "Update the fixed donation (not distance donation - use /donations/fixed instead) whose id you provided. <br> Please remember that ids can't be changed and amounts must be positive." }) @OpenAPI({ description: "Update the fixed donation (not distance donation - use /donations/distance instead) whose id you provided. <br> Please remember that ids can't be changed and amounts must be positive." })
async putFixed(@Param('id') id: number, @Body({ validate: true }) donation: UpdateFixedDonation) { async putFixed(@Param('id') id: number, @Body({ validate: true }) donation: UpdateFixedDonation) {
let oldDonation = await this.fixedDonationRepository.findOne({ id: id }); let oldDonation = await this.fixedDonationRepository.findOne({ id: id });
@ -103,28 +103,28 @@ export class DonationController {
return (await this.donationRepository.findOne({ id: donation.id }, { relations: ['donor'] })).toResponse(); return (await this.donationRepository.findOne({ id: donation.id }, { relations: ['donor'] })).toResponse();
} }
// @Put('/trackscans/:id') @Put('/distance/:id')
// @Authorized("SCAN:UPDATE") @Authorized("DONATION:UPDATE")
// @ResponseSchema(ResponseTrackScan) @ResponseSchema(ResponseDonation)
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 }) @ResponseSchema(DonationNotFoundError, { statusCode: 404 })
// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) @ResponseSchema(DonorNotFoundError, { statusCode: 404 })
// @ResponseSchema(ScanStationNotFoundError, { statusCode: 404 }) @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
// @ResponseSchema(ScanIdsNotMatchingError, { statusCode: 406 }) @ResponseSchema(DonationIdsNotMatchingError, { statusCode: 406 })
// @OpenAPI({ description: 'Update the track scan (not "normal" scan use /scans/trackscans/:id instead) whose id you provided. <br> Please remember that only the validity, runner and track can be changed.' }) @OpenAPI({ description: "Update the distance donation (not fixed donation - use /donations/fixed instead) whose id you provided. <br> Please remember that ids can't be changed and amountPerDistance must be positive." })
// async putTrackScan(@Param('id') id: number, @Body({ validate: true }) scan: UpdateTrackScan) { async putDistance(@Param('id') id: number, @Body({ validate: true }) donation: UpdateDistanceDonation) {
// let oldScan = await this.trackScanRepository.findOne({ id: id }); let oldDonation = await this.distanceDonationRepository.findOne({ id: id });
// if (!oldScan) { if (!oldDonation) {
// throw new ScanNotFoundError(); throw new DonationNotFoundError();
// } }
// if (oldScan.id != scan.id) { if (oldDonation.id != donation.id) {
// throw new ScanIdsNotMatchingError(); throw new DonationIdsNotMatchingError();
// } }
// await this.trackScanRepository.save(await scan.update(oldScan)); await this.distanceDonationRepository.save(await donation.update(oldDonation));
// return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse(); return (await this.donationRepository.findOne({ id: donation.id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] })).toResponse();
// } }
@Delete('/:id') @Delete('/:id')
@Authorized("DONATION:DELETE") @Authorized("DONATION:DELETE")