parent
cf788fe07b
commit
5581c03f77
|
@ -0,0 +1,129 @@
|
|||
import { JsonController } from 'routing-controllers';
|
||||
import { OpenAPI } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { DistanceDonation } from '../models/entities/DistanceDonation';
|
||||
import { Donation } from '../models/entities/Donation';
|
||||
|
||||
@JsonController('/scans')
|
||||
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
||||
export class ScanController {
|
||||
private donationRepository: Repository<Donation>;
|
||||
private distanceDonationRepository: Repository<DistanceDonation>;
|
||||
|
||||
/**
|
||||
* Gets the repository of this controller's model/entity.
|
||||
*/
|
||||
constructor() {
|
||||
this.donationRepository = getConnectionManager().get().getRepository(Donation);
|
||||
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('/: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();
|
||||
// }
|
||||
|
||||
// @Post()
|
||||
// @UseBefore(ScanAuth)
|
||||
// @ResponseSchema(ResponseScan)
|
||||
// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
// @OpenAPI({ description: 'Create a new scan (not track scan - use /scans/trackscans instead). <br> Please rmemember to provide the scan\'s runner\'s id and distance.', security: [{ "ScanApiToken": [] }, { "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
||||
// async post(@Body({ validate: true }) createScan: CreateScan) {
|
||||
// let scan = await createScan.toEntity();
|
||||
// scan = await this.scanRepository.save(scan);
|
||||
// return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse();
|
||||
// }
|
||||
|
||||
// @Post("/trackscans")
|
||||
// @UseBefore(ScanAuth)
|
||||
// @ResponseSchema(ResponseTrackScan)
|
||||
// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
// @OpenAPI({ description: 'Create a new track scan (for "normal" scans use /scans instead). <br> Please remember that to provide the scan\'s card\'s station\'s id.', security: [{ "ScanApiToken": [] }, { "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
||||
// async postTrackScans(@Body({ validate: true }) createScan: CreateTrackScan) {
|
||||
// let scan = await createScan.toEntity();
|
||||
// scan = await this.trackScanRepository.save(scan);
|
||||
// return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse();
|
||||
// }
|
||||
|
||||
// @Put('/:id')
|
||||
// @Authorized("SCAN:UPDATE")
|
||||
// @ResponseSchema(ResponseScan)
|
||||
// @ResponseSchema(ScanNotFoundError, { statusCode: 404 })
|
||||
// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
// @ResponseSchema(ScanIdsNotMatchingError, { statusCode: 406 })
|
||||
// @OpenAPI({ description: "Update the scan (not track scan use /scans/trackscans/:id instead) whose id you provided. <br> Please remember that ids can't be changed and distances must be positive." })
|
||||
// async put(@Param('id') id: number, @Body({ validate: true }) scan: UpdateScan) {
|
||||
// let oldScan = await this.scanRepository.findOne({ id: id });
|
||||
|
||||
// if (!oldScan) {
|
||||
// throw new ScanNotFoundError();
|
||||
// }
|
||||
|
||||
// if (oldScan.id != scan.id) {
|
||||
// throw new ScanIdsNotMatchingError();
|
||||
// }
|
||||
|
||||
// await this.scanRepository.save(await scan.update(oldScan));
|
||||
// return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).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 });
|
||||
|
||||
// if (!oldScan) {
|
||||
// throw new ScanNotFoundError();
|
||||
// }
|
||||
|
||||
// if (oldScan.id != scan.id) {
|
||||
// throw new ScanIdsNotMatchingError();
|
||||
// }
|
||||
|
||||
// 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();
|
||||
// }
|
||||
|
||||
// @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'] });
|
||||
|
||||
// await this.scanRepository.delete(scan);
|
||||
// return responseScan.toResponse();
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue