parent
f9889bea3d
commit
aeec2e1c32
@ -1,6 +1,7 @@
|
|||||||
import { Authorized, Get, JsonController } from 'routing-controllers';
|
import { Authorized, Get, JsonController, OnUndefined, Param } from 'routing-controllers';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
|
import { ScanNotFoundError } from '../errors/ScanErrors';
|
||||||
import { Scan } from '../models/entities/Scan';
|
import { Scan } from '../models/entities/Scan';
|
||||||
import { ResponseScan } from '../models/responses/ResponseScan';
|
import { ResponseScan } from '../models/responses/ResponseScan';
|
||||||
import { ResponseTrackScan } from '../models/responses/ResponseTrackScan';
|
import { ResponseTrackScan } from '../models/responses/ResponseTrackScan';
|
||||||
@ -21,7 +22,7 @@ export class ScanController {
|
|||||||
@Authorized("SCAN:GET")
|
@Authorized("SCAN:GET")
|
||||||
@ResponseSchema(ResponseScan, { isArray: true })
|
@ResponseSchema(ResponseScan, { isArray: true })
|
||||||
@ResponseSchema(ResponseTrackScan, { isArray: true })
|
@ResponseSchema(ResponseTrackScan, { isArray: true })
|
||||||
@OpenAPI({ description: 'Lists all runners from all teams/orgs. <br> This includes the runner\'s group and distance ran.' })
|
@OpenAPI({ description: 'Lists all scans (normal or track) from all runners. <br> This includes the runner\'s group and distance ran.' })
|
||||||
async getAll() {
|
async getAll() {
|
||||||
let responseScans: ResponseScan[] = new Array<ResponseScan>();
|
let responseScans: ResponseScan[] = new Array<ResponseScan>();
|
||||||
const scans = await this.scanRepository.find();
|
const scans = await this.scanRepository.find();
|
||||||
@ -31,17 +32,18 @@ export class ScanController {
|
|||||||
return responseScans;
|
return responseScans;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Get('/:id')
|
@Get('/:id')
|
||||||
// @Authorized("DONOR:GET")
|
@Authorized("DONOR:GET")
|
||||||
// @ResponseSchema(ResponseDonor)
|
@ResponseSchema(ResponseScan)
|
||||||
// @ResponseSchema(DonorNotFoundError, { statusCode: 404 })
|
@ResponseSchema(ResponseTrackScan)
|
||||||
// @OnUndefined(DonorNotFoundError)
|
@ResponseSchema(ScanNotFoundError, { statusCode: 404 })
|
||||||
// @OpenAPI({ description: 'Lists all information about the runner whose id got provided.' })
|
@OnUndefined(ScanNotFoundError)
|
||||||
// async getOne(@Param('id') id: number) {
|
@OpenAPI({ description: 'Lists all information about the runner whose id got provided.' })
|
||||||
// let donor = await this.donorRepository.findOne({ id: id })
|
async getOne(@Param('id') id: number) {
|
||||||
// if (!donor) { throw new DonorNotFoundError(); }
|
let scan = await this.scanRepository.findOne({ id: id })
|
||||||
// return new ResponseDonor(donor);
|
if (!scan) { throw new ScanNotFoundError(); }
|
||||||
// }
|
return scan;
|
||||||
|
}
|
||||||
|
|
||||||
// @Post()
|
// @Post()
|
||||||
// @Authorized("DONOR:CREATE")
|
// @Authorized("DONOR:CREATE")
|
||||||
|
25
src/errors/ScanErrors.ts
Normal file
25
src/errors/ScanErrors.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { IsString } from 'class-validator';
|
||||||
|
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when a Scan couldn't be found.
|
||||||
|
*/
|
||||||
|
export class ScanNotFoundError extends NotFoundError {
|
||||||
|
@IsString()
|
||||||
|
name = "ScanNotFoundError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "Scan not found!"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when two Scans' ids don't match.
|
||||||
|
* Usually occurs when a user tries to change a Scan's id.
|
||||||
|
*/
|
||||||
|
export class ScanIdsNotMatchingError extends NotAcceptableError {
|
||||||
|
@IsString()
|
||||||
|
name = "ScanIdsNotMatchingError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "The ids don't match! \n And if you wanted to change a Scan's id: This isn't allowed!"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user