parent
5ae20e945f
commit
7e15291806
@ -0,0 +1,29 @@
|
||||
import {Controller} from "@extollo/lib"
|
||||
import {Inject, Injectable} from "@extollo/di"
|
||||
import {TransactionResource, TransactionResourceItem} from "../../../rtdb/TransactionResource"
|
||||
import {one} from "@extollo/util"
|
||||
|
||||
/**
|
||||
* Blockchain Controller
|
||||
* ------------------------------------
|
||||
* Route handlers for API endpoints.
|
||||
*/
|
||||
@Injectable()
|
||||
export class Blockchain extends Controller {
|
||||
|
||||
public async postTransaction() {
|
||||
const item: TransactionResourceItem = {
|
||||
firebaseID: '',
|
||||
seqID: -1,
|
||||
combinedHash: String(this.request.input('combinedHash')),
|
||||
timestamp: parseInt(String(this.request.input('timestamp'))),
|
||||
encodedGPSLocation: String(this.request.input('encodedGPSLocation')),
|
||||
partnerPublicKey: String(this.request.input('partnerPublicKey')),
|
||||
validationSignature: String(this.request.input('validationSignature')),
|
||||
}
|
||||
|
||||
await (<TransactionResource> this.make(TransactionResource)).push(item)
|
||||
return one(item)
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import {Controller, view, Session} from '@extollo/lib';
|
||||
import {Inject, Injectable} from "@extollo/di";
|
||||
|
||||
@Injectable()
|
||||
export class Home extends Controller {
|
||||
@Inject()
|
||||
protected readonly session!: Session;
|
||||
|
||||
public welcome() {
|
||||
this.session.set('app_visits', this.session.get('app_visits', 0) + 1)
|
||||
|
||||
return view('welcome', {
|
||||
app_visits: this.session.get('app_visits'),
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import {error, Middleware} from "@extollo/lib"
|
||||
import {Injectable} from "@extollo/di"
|
||||
import {HTTPStatus} from "@extollo/util";
|
||||
|
||||
/**
|
||||
* ValidateEncounterTransaction Middleware
|
||||
* --------------------------------------------
|
||||
* Put some description here.
|
||||
*/
|
||||
@Injectable()
|
||||
export class ValidateEncounterTransaction extends Middleware {
|
||||
public async apply() {
|
||||
const required: string[] = [
|
||||
'combinedHash',
|
||||
'encodedGPSLocation',
|
||||
'partnerPublicKey',
|
||||
'validationSignature',
|
||||
'timestamp',
|
||||
]
|
||||
|
||||
for ( const field of required ) {
|
||||
if ( !this.request.input(field) ) {
|
||||
return error(`Missing required field: ${field}`, HTTPStatus.BAD_REQUEST, 'json')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
import {Route} from "@extollo/lib"
|
||||
|
||||
Route.get('/', 'main:Home.welcome')
|
||||
Route.group('/api/v1', () => {
|
||||
Route.post('/encounter', 'api:Blockchain.postTransaction')
|
||||
.pre('api:ValidateEncounterTransaction')
|
||||
})
|
||||
|
Loading…
Reference in new issue