import { $log , Controller , Get , QueryParams } from '@tsed/common' ; import { InsecureRandomService } from '../services/InsecureRandomService' ; export interface ICouponsResponse { coupons : number [ ] ; } export interface ICheckResponse { valid : boolean ; flag : string ; } @ Controller ( "/random" ) export class InsecureRandomController { static nextCoupons : number [ ] ; static currentCoupons : number [ ] ; @ Get ( "/" ) public index ( ) { InsecureRandomController . currentCoupons = InsecureRandomService . generate5RandomValues ( 5 ) ; InsecureRandomController . nextCoupons = InsecureRandomService . generate5RandomValues ( 5 ) ; $log . info ( "Generated 5 coupons: " + InsecureRandomController . currentCoupons . toString ( ) + " - and 5 to be predicted: " + InsecureRandomController . nextCoupons . toString ( ) ) ; return { coupons : InsecureRandomController . currentCoupons } ; } @ Get ( "/check" ) public check ( @ QueryParams ( "couponCode" ) code ) { if ( InsecureRandomController . currentCoupons . includes ( code ) ) return { valid : true , flag : "" } ; else if ( InsecureRandomController . nextCoupons . includes ( code ) ) return { valid : true , flag : InsecureRandomService . getFlag ( ) } ; else return { flag : "" , valid : false } ; } }