ref #157
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
import { Request } from "express";
 | 
			
		||||
import * as jwt from "jsonwebtoken";
 | 
			
		||||
import { Body, Get, JsonController, OnUndefined, Param, Post, QueryParam } from 'routing-controllers';
 | 
			
		||||
import { Body, Get, JsonController, OnUndefined, Param, Post, QueryParam, Req, UseBefore } from 'routing-controllers';
 | 
			
		||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
 | 
			
		||||
import { getConnectionManager, Repository } from 'typeorm';
 | 
			
		||||
import { config } from '../config';
 | 
			
		||||
@@ -7,23 +8,27 @@ import { InvalidCredentialsError, JwtNotProvidedError } from '../errors/AuthErro
 | 
			
		||||
import { MailSendingError } from '../errors/MailErrors';
 | 
			
		||||
import { RunnerEmailNeededError, RunnerNotFoundError, RunnerSelfserviceTimeoutError } from '../errors/RunnerErrors';
 | 
			
		||||
import { RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors';
 | 
			
		||||
import { ScanStationNotFoundError } from '../errors/ScanStationErrors';
 | 
			
		||||
import { JwtCreator } from '../jwtcreator';
 | 
			
		||||
import { Mailer } from '../mailer';
 | 
			
		||||
import ScanAuth from '../middlewares/ScanAuth';
 | 
			
		||||
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
 | 
			
		||||
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
 | 
			
		||||
import { Runner } from '../models/entities/Runner';
 | 
			
		||||
import { RunnerGroup } from '../models/entities/RunnerGroup';
 | 
			
		||||
import { RunnerOrganization } from '../models/entities/RunnerOrganization';
 | 
			
		||||
import { ScanStation } from '../models/entities/ScanStation';
 | 
			
		||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
 | 
			
		||||
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
 | 
			
		||||
import { ResponseSelfServiceOrganisation } from '../models/responses/ResponseSelfServiceOrganisation';
 | 
			
		||||
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
 | 
			
		||||
import { ResponseSelfServiceScan } from '../models/responses/ResponseSelfServiceScan';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@JsonController()
 | 
			
		||||
export class RunnerSelfServiceController {
 | 
			
		||||
	private runnerRepository: Repository<Runner>;
 | 
			
		||||
	private orgRepository: Repository<RunnerOrganization>;
 | 
			
		||||
	private stationRepository: Repository<ScanStation>;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Gets the repository of this controller's model/entity.
 | 
			
		||||
@@ -31,6 +36,7 @@ export class RunnerSelfServiceController {
 | 
			
		||||
	constructor() {
 | 
			
		||||
		this.runnerRepository = getConnectionManager().get().getRepository(Runner);
 | 
			
		||||
		this.orgRepository = getConnectionManager().get().getRepository(RunnerOrganization);
 | 
			
		||||
		this.stationRepository = getConnectionManager().get().getRepository(ScanStation);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Get('/runners/me/:jwt')
 | 
			
		||||
@@ -56,6 +62,18 @@ export class RunnerSelfServiceController {
 | 
			
		||||
		return responseScans;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Get('/stations/me')
 | 
			
		||||
	@UseBefore(ScanAuth)
 | 
			
		||||
	@ResponseSchema(ResponseScanStation)
 | 
			
		||||
	@ResponseSchema(ScanStationNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@OnUndefined(ScanStationNotFoundError)
 | 
			
		||||
	@OpenAPI({ description: 'Lists basic information about the station whose token got provided. <br> This includes it\'s associated track. <br> Just set the ID to 0.', security: [{ "ScanApiToken": [] }] })
 | 
			
		||||
	async getStationMe(@Req() req: Request) {
 | 
			
		||||
		let scan = await this.stationRepository.findOne({ id: parseInt(req.headers["station_id"].toString()) }, { relations: ['track'] })
 | 
			
		||||
		if (!scan) { throw new ScanStationNotFoundError(); }
 | 
			
		||||
		return scan.toResponse();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Post('/runners/forgot')
 | 
			
		||||
	@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@OnUndefined(ResponseEmpty)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,8 @@
 | 
			
		||||
import { Request } from 'express';
 | 
			
		||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam, Req, UseBefore } from 'routing-controllers';
 | 
			
		||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
 | 
			
		||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
 | 
			
		||||
import { getConnectionManager, Repository } from 'typeorm';
 | 
			
		||||
import { ScanStationHasScansError, ScanStationIdsNotMatchingError, ScanStationNotFoundError } from '../errors/ScanStationErrors';
 | 
			
		||||
import { TrackNotFoundError } from '../errors/TrackErrors';
 | 
			
		||||
import ScanAuth from '../middlewares/ScanAuth';
 | 
			
		||||
import { CreateScanStation } from '../models/actions/create/CreateScanStation';
 | 
			
		||||
import { UpdateScanStation } from '../models/actions/update/UpdateScanStation';
 | 
			
		||||
import { ScanStation } from '../models/entities/ScanStation';
 | 
			
		||||
@@ -49,18 +47,6 @@ export class ScanStationController {
 | 
			
		||||
		return scan.toResponse();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Get('/:id/me')
 | 
			
		||||
	@UseBefore(ScanAuth)
 | 
			
		||||
	@ResponseSchema(ResponseScanStation)
 | 
			
		||||
	@ResponseSchema(ScanStationNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@OnUndefined(ScanStationNotFoundError)
 | 
			
		||||
	@OpenAPI({ description: 'Lists basic information about the station whose token got provided. <br> This includes it\'s associated track. <br> Just set the ID to 0.', security: [{ "ScanApiToken": [] }] })
 | 
			
		||||
	async getMe(@Req() req: Request) {
 | 
			
		||||
		let scan = await this.stationRepository.findOne({ id: parseInt(req.headers["station_id"].toString()) }, { relations: ['track'] })
 | 
			
		||||
		if (!scan) { throw new ScanStationNotFoundError(); }
 | 
			
		||||
		return scan.toResponse();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Post()
 | 
			
		||||
	@Authorized("STATION:CREATE")
 | 
			
		||||
	@ResponseSchema(ResponseScanStation)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user