parent
5f1ab4a2f3
commit
0df26cbd54
|
@ -1,12 +1,15 @@
|
|||
import { JsonController } from 'routing-controllers';
|
||||
import { OpenAPI } from 'routing-controllers-openapi';
|
||||
import { Authorized, Get, JsonController, OnUndefined, Param } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { DonationNotFoundError } from '../errors/DonationErrors';
|
||||
import { DistanceDonation } from '../models/entities/DistanceDonation';
|
||||
import { Donation } from '../models/entities/Donation';
|
||||
import { ResponseDistanceDonation } from '../models/responses/ResponseDistanceDonation';
|
||||
import { ResponseDonation } from '../models/responses/ResponseDonation';
|
||||
|
||||
@JsonController('/scans')
|
||||
@JsonController('/donations')
|
||||
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
||||
export class ScanController {
|
||||
export class DonationController {
|
||||
private donationRepository: Repository<Donation>;
|
||||
private distanceDonationRepository: Repository<DistanceDonation>;
|
||||
|
||||
|
@ -18,32 +21,32 @@ export class ScanController {
|
|||
this.distanceDonationRepository = getConnectionManager().get().getRepository(DistanceDonation);
|
||||
}
|
||||
|
||||
// @Get()
|
||||
// @Authorized("SCAN:GET")
|
||||
// @ResponseSchema(ResponseScan, { isArray: true })
|
||||
// @ResponseSchema(ResponseTrackScan, { isArray: true })
|
||||
// @OpenAPI({ description: 'Lists all scans (normal or track) from all runners. <br> This includes the scan\'s runner\'s distance ran.' })
|
||||
// async getAll() {
|
||||
// let responseScans: ResponseScan[] = new Array<ResponseScan>();
|
||||
// const scans = await this.scanRepository.find({ relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] });
|
||||
// scans.forEach(scan => {
|
||||
// responseScans.push(scan.toResponse());
|
||||
// });
|
||||
// return responseScans;
|
||||
// }
|
||||
@Get()
|
||||
@Authorized("DONATION:GET")
|
||||
@ResponseSchema(ResponseDonation, { isArray: true })
|
||||
@ResponseSchema(ResponseDistanceDonation, { isArray: true })
|
||||
@OpenAPI({ description: 'Lists all donations (fixed or distance based) from all donors. <br> This includes the donations\'s runner\'s distance ran(if distance donation).' })
|
||||
async getAll() {
|
||||
let responseDonations: ResponseDonation[] = new Array<ResponseDonation>();
|
||||
const donations = await this.donationRepository.find({ relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] });
|
||||
donations.forEach(donation => {
|
||||
responseDonations.push(donation.toResponse());
|
||||
});
|
||||
return responseDonations;
|
||||
}
|
||||
|
||||
// @Get('/:id')
|
||||
// @Authorized("SCAN:GET")
|
||||
// @ResponseSchema(ResponseScan)
|
||||
// @ResponseSchema(ResponseTrackScan)
|
||||
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 })
|
||||
// @OnUndefined(ScanNotFoundError)
|
||||
// @OpenAPI({ description: 'Lists all information about the scan whose id got provided. This includes the scan\'s runner\'s distance ran.' })
|
||||
// async getOne(@Param('id') id: number) {
|
||||
// let scan = await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })
|
||||
// if (!scan) { throw new ScanNotFoundError(); }
|
||||
// return scan.toResponse();
|
||||
// }
|
||||
@Get('/:id')
|
||||
@Authorized("DONATION:GET")
|
||||
@ResponseSchema(ResponseDonation)
|
||||
@ResponseSchema(ResponseDistanceDonation)
|
||||
@ResponseSchema(DonationNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(DonationNotFoundError)
|
||||
@OpenAPI({ description: 'Lists all information about the donation whose id got provided. This includes the donation\'s runner\'s distance ran (if distance donation).' })
|
||||
async getOne(@Param('id') id: number) {
|
||||
let donation = await this.donationRepository.findOne({ id: id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] })
|
||||
if (!donation) { throw new DonationNotFoundError(); }
|
||||
return donation.toResponse();
|
||||
}
|
||||
|
||||
// @Post()
|
||||
// @UseBefore(ScanAuth)
|
||||
|
|
Loading…
Reference in New Issue