91
									
								
								src/controllers/ScanStationController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								src/controllers/ScanStationController.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | |||||||
|  | import { JsonController } from 'routing-controllers'; | ||||||
|  | import { OpenAPI } from 'routing-controllers-openapi'; | ||||||
|  | import { getConnectionManager, Repository } from 'typeorm'; | ||||||
|  | import { ScanStation } from '../models/entities/ScanStation'; | ||||||
|  |  | ||||||
|  | @JsonController('/stations') | ||||||
|  | @OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) | ||||||
|  | export class ScanStationController { | ||||||
|  | 	private stationRepository: Repository<ScanStation>; | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Gets the repository of this controller's model/entity. | ||||||
|  | 	 */ | ||||||
|  | 	constructor() { | ||||||
|  | 		this.stationRepository = getConnectionManager().get().getRepository(ScanStation); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// @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 runner\'s group and distance ran.' }) | ||||||
|  | 	// async getAll() { | ||||||
|  | 	// 	let responseScans: ResponseScan[] = new Array<ResponseScan>(); | ||||||
|  | 	// 	const scans = await this.scanRepository.find({ relations: ['runner'] }); | ||||||
|  | 	// 	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 runner whose id got provided.' }) | ||||||
|  | 	// async getOne(@Param('id') id: number) { | ||||||
|  | 	// 	let scan = await this.scanRepository.findOne({ id: id }, { relations: ['runner'] }) | ||||||
|  | 	// 	if (!scan) { throw new ScanNotFoundError(); } | ||||||
|  | 	// 	return scan.toResponse(); | ||||||
|  | 	// } | ||||||
|  |  | ||||||
|  | 	// @Post() | ||||||
|  | 	// @Authorized("SCAN:CREATE") | ||||||
|  | 	// @ResponseSchema(ResponseScan) | ||||||
|  | 	// @OpenAPI({ description: 'Create a new runner. <br> Please remeber to provide the runner\'s group\'s id.' }) | ||||||
|  | 	// async post(@Body({ validate: true }) createScan: CreateScan) { | ||||||
|  | 	// 	let scan = await createScan.toScan(); | ||||||
|  | 	// 	scan = await this.scanRepository.save(scan); | ||||||
|  | 	// 	return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner'] })).toResponse(); | ||||||
|  | 	// } | ||||||
|  |  | ||||||
|  | 	// @Put('/:id') | ||||||
|  | 	// @Authorized("SCAN:UPDATE") | ||||||
|  | 	// @ResponseSchema(ResponseScan) | ||||||
|  | 	// @ResponseSchema(ScanNotFoundError, { statusCode: 404 }) | ||||||
|  | 	// @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) | ||||||
|  | 	// @ResponseSchema(ScanIdsNotMatchingError, { statusCode: 406 }) | ||||||
|  | 	// @OpenAPI({ description: "Update the runner whose id you provided. <br> Please remember that ids can't be changed." }) | ||||||
|  | 	// 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.updateScan(oldScan)); | ||||||
|  | 	// 	return (await this.scanRepository.findOne({ id: id }, { relations: ['runner'] })).toResponse(); | ||||||
|  | 	// } | ||||||
|  |  | ||||||
|  | 	// @Delete('/:id') | ||||||
|  | 	// @Authorized("SCAN:DELETE") | ||||||
|  | 	// @ResponseSchema(ResponseScan) | ||||||
|  | 	// @ResponseSchema(ResponseEmpty, { statusCode: 204 }) | ||||||
|  | 	// @OnUndefined(204) | ||||||
|  | 	// @OpenAPI({ description: 'Delete the runner whose id you provided. <br> If no runner 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"] }); | ||||||
|  |  | ||||||
|  | 	// 	await this.scanRepository.delete(scan); | ||||||
|  | 	// 	return responseScan.toResponse(); | ||||||
|  | 	// } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user