| @@ -1,4 +1,4 @@ | ||||
| import { Authorized, Get, JsonController, OnUndefined, Param } from 'routing-controllers'; | ||||
| import { Authorized, Delete, Get, JsonController, OnUndefined, Param, QueryParam } from 'routing-controllers'; | ||||
| import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; | ||||
| import { getConnectionManager, Repository } from 'typeorm'; | ||||
| import { DonationNotFoundError } from '../errors/DonationErrors'; | ||||
| @@ -6,6 +6,7 @@ import { DistanceDonation } from '../models/entities/DistanceDonation'; | ||||
| import { Donation } from '../models/entities/Donation'; | ||||
| import { ResponseDistanceDonation } from '../models/responses/ResponseDistanceDonation'; | ||||
| import { ResponseDonation } from '../models/responses/ResponseDonation'; | ||||
| import { ResponseEmpty } from '../models/responses/ResponseEmpty'; | ||||
|  | ||||
| @JsonController('/donations') | ||||
| @OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) | ||||
| @@ -115,18 +116,19 @@ export class DonationController { | ||||
| 	// 	return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse(); | ||||
| 	// } | ||||
|  | ||||
| 	// @Delete('/:id') | ||||
| 	// @Authorized("SCAN:DELETE") | ||||
| 	// @ResponseSchema(ResponseScan) | ||||
| 	// @ResponseSchema(ResponseEmpty, { statusCode: 204 }) | ||||
| 	// @OnUndefined(204) | ||||
| 	// @OpenAPI({ description: 'Delete the scan whose id you provided. <br> If no scan with this id exists it will just return 204(no content).' }) | ||||
| 	// async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { | ||||
| 	// 	let scan = await this.scanRepository.findOne({ id: id }); | ||||
| 	// 	if (!scan) { return null; } | ||||
| 	// 	const responseScan = await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] }); | ||||
| 	@Delete('/:id') | ||||
| 	@Authorized("DONATION:DELETE") | ||||
| 	@ResponseSchema(ResponseDonation) | ||||
| 	@ResponseSchema(ResponseDistanceDonation) | ||||
| 	@ResponseSchema(ResponseEmpty, { statusCode: 204 }) | ||||
| 	@OnUndefined(204) | ||||
| 	@OpenAPI({ description: 'Delete the donation whose id you provided. <br> If no donation with this id exists it will just return 204(no content).' }) | ||||
| 	async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { | ||||
| 		let donation = await this.donationRepository.findOne({ id: id }); | ||||
| 		if (!donation) { return null; } | ||||
| 		const responseScan = await this.donationRepository.findOne({ id: donation.id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] }); | ||||
|  | ||||
| 	// 	await this.scanRepository.delete(scan); | ||||
| 	// 	return responseScan.toResponse(); | ||||
| 	// } | ||||
| 		await this.donationRepository.delete(donation); | ||||
| 		return responseScan.toResponse(); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user