|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
|
|
|
|
import { Request } from "express";
|
|
|
|
import * as jwt from "jsonwebtoken";
|
|
|
|
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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
|
|
|
import { getConnectionManager, Repository } from 'typeorm';
|
|
|
|
import { getConnectionManager, Repository } from 'typeorm';
|
|
|
|
import { config } from '../config';
|
|
|
|
import { config } from '../config';
|
|
|
|
@@ -7,23 +8,27 @@ import { InvalidCredentialsError, JwtNotProvidedError } from '../errors/AuthErro
|
|
|
|
import { MailSendingError } from '../errors/MailErrors';
|
|
|
|
import { MailSendingError } from '../errors/MailErrors';
|
|
|
|
import { RunnerEmailNeededError, RunnerNotFoundError, RunnerSelfserviceTimeoutError } from '../errors/RunnerErrors';
|
|
|
|
import { RunnerEmailNeededError, RunnerNotFoundError, RunnerSelfserviceTimeoutError } from '../errors/RunnerErrors';
|
|
|
|
import { RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors';
|
|
|
|
import { RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors';
|
|
|
|
|
|
|
|
import { ScanStationNotFoundError } from '../errors/ScanStationErrors';
|
|
|
|
import { JwtCreator } from '../jwtcreator';
|
|
|
|
import { JwtCreator } from '../jwtcreator';
|
|
|
|
import { Mailer } from '../mailer';
|
|
|
|
import { Mailer } from '../mailer';
|
|
|
|
|
|
|
|
import ScanAuth from '../middlewares/ScanAuth';
|
|
|
|
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
|
|
|
|
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
|
|
|
|
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
|
|
|
|
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
|
|
|
|
import { Runner } from '../models/entities/Runner';
|
|
|
|
import { Runner } from '../models/entities/Runner';
|
|
|
|
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
|
|
|
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
|
|
|
import { RunnerOrganization } from '../models/entities/RunnerOrganization';
|
|
|
|
import { RunnerOrganization } from '../models/entities/RunnerOrganization';
|
|
|
|
|
|
|
|
import { ScanStation } from '../models/entities/ScanStation';
|
|
|
|
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
|
|
|
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
|
|
|
|
|
|
|
import { ResponseScanStation } from '../models/responses/ResponseScanStation';
|
|
|
|
import { ResponseSelfServiceOrganisation } from '../models/responses/ResponseSelfServiceOrganisation';
|
|
|
|
import { ResponseSelfServiceOrganisation } from '../models/responses/ResponseSelfServiceOrganisation';
|
|
|
|
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
|
|
|
|
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
|
|
|
|
import { ResponseSelfServiceScan } from '../models/responses/ResponseSelfServiceScan';
|
|
|
|
import { ResponseSelfServiceScan } from '../models/responses/ResponseSelfServiceScan';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@JsonController()
|
|
|
|
@JsonController()
|
|
|
|
export class RunnerSelfServiceController {
|
|
|
|
export class RunnerSelfServiceController {
|
|
|
|
private runnerRepository: Repository<Runner>;
|
|
|
|
private runnerRepository: Repository<Runner>;
|
|
|
|
private orgRepository: Repository<RunnerOrganization>;
|
|
|
|
private orgRepository: Repository<RunnerOrganization>;
|
|
|
|
|
|
|
|
private stationRepository: Repository<ScanStation>;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Gets the repository of this controller's model/entity.
|
|
|
|
* Gets the repository of this controller's model/entity.
|
|
|
|
@@ -31,6 +36,7 @@ export class RunnerSelfServiceController {
|
|
|
|
constructor() {
|
|
|
|
constructor() {
|
|
|
|
this.runnerRepository = getConnectionManager().get().getRepository(Runner);
|
|
|
|
this.runnerRepository = getConnectionManager().get().getRepository(Runner);
|
|
|
|
this.orgRepository = getConnectionManager().get().getRepository(RunnerOrganization);
|
|
|
|
this.orgRepository = getConnectionManager().get().getRepository(RunnerOrganization);
|
|
|
|
|
|
|
|
this.stationRepository = getConnectionManager().get().getRepository(ScanStation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Get('/runners/me/:jwt')
|
|
|
|
@Get('/runners/me/:jwt')
|
|
|
|
@@ -56,6 +62,18 @@ export class RunnerSelfServiceController {
|
|
|
|
return responseScans;
|
|
|
|
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.', 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')
|
|
|
|
@Post('/runners/forgot')
|
|
|
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
|
|
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
|
|
|
@OnUndefined(ResponseEmpty)
|
|
|
|
@OnUndefined(ResponseEmpty)
|
|
|
|
|