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
1 changed files with 20 additions and 20 deletions

View File

@ -87,7 +87,7 @@ export class DonationController {
@ResponseSchema(DonorNotFoundError, { statusCode: 404 })
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@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) {
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();
}
// @Put('/trackscans/:id')
// @Authorized("SCAN:UPDATE")
// @ResponseSchema(ResponseTrackScan)
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 })
// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
// @ResponseSchema(ScanStationNotFoundError, { statusCode: 404 })
// @ResponseSchema(ScanIdsNotMatchingError, { 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.' })
// async putTrackScan(@Param('id') id: number, @Body({ validate: true }) scan: UpdateTrackScan) {
// let oldScan = await this.trackScanRepository.findOne({ id: id });
@Put('/distance/:id')
@Authorized("DONATION:UPDATE")
@ResponseSchema(ResponseDonation)
@ResponseSchema(DonationNotFoundError, { statusCode: 404 })
@ResponseSchema(DonorNotFoundError, { statusCode: 404 })
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@ResponseSchema(DonationIdsNotMatchingError, { statusCode: 406 })
@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 putDistance(@Param('id') id: number, @Body({ validate: true }) donation: UpdateDistanceDonation) {
let oldDonation = await this.distanceDonationRepository.findOne({ id: id });
// if (!oldScan) {
// throw new ScanNotFoundError();
// }
if (!oldDonation) {
throw new DonationNotFoundError();
}
// if (oldScan.id != scan.id) {
// throw new ScanIdsNotMatchingError();
// }
if (oldDonation.id != donation.id) {
throw new DonationIdsNotMatchingError();
}
// await this.trackScanRepository.save(await scan.update(oldScan));
// return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse();
// }
await this.distanceDonationRepository.save(await donation.update(oldDonation));
return (await this.donationRepository.findOne({ id: donation.id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] })).toResponse();
}
@Delete('/:id')
@Authorized("DONATION:DELETE")