|
|
@ -1,35 +1,47 @@ |
|
|
|
import * as AnalyticUnit from '../models/analytic_unit_model'; |
|
|
|
import * as AnalyticUnit from '../models/analytic_unit_model'; |
|
|
|
|
|
|
|
|
|
|
|
import { createAnalyticUnitFromObject } from '../controllers/analytics_controller' |
|
|
|
import { createAnalyticUnitFromObject } from '../controllers/analytics_controller'; |
|
|
|
|
|
|
|
|
|
|
|
import * as Router from 'koa-router'; |
|
|
|
import * as Router from 'koa-router'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getStatus(ctx: Router.IRouterContext) { |
|
|
|
async function getStatus(ctx: Router.IRouterContext) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
ctx.response.body = { status: 'READY', errorMessage: undefined }; |
|
|
|
let analyticUnitId = ctx.request.query.id; |
|
|
|
|
|
|
|
if(analyticUnitId === undefined) { |
|
|
|
|
|
|
|
throw new Error('Cannot get status of undefined id'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let analyticUnit = await AnalyticUnit.findById(analyticUnitId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.response.body = { |
|
|
|
|
|
|
|
status: analyticUnit.status |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(analyticUnit.status === AnalyticUnit.AnalyticUnitStatus.FAILED) { |
|
|
|
|
|
|
|
ctx.response.body.errorMessage = analyticUnit.error; |
|
|
|
|
|
|
|
} |
|
|
|
} catch(e) { |
|
|
|
} catch(e) { |
|
|
|
console.error(e); |
|
|
|
console.error(e); |
|
|
|
// TODO: better send 404 when we know than isn`t found
|
|
|
|
ctx.response.status = 404; |
|
|
|
ctx.response.status = 500; |
|
|
|
ctx.response.body = 'Can`t find anything'; |
|
|
|
ctx.response.body = { error: 'Can`t return anything' }; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function getUnit(ctx: Router.IRouterContext) { |
|
|
|
async function getUnit(ctx: Router.IRouterContext) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
let id = ctx.request.query.id; |
|
|
|
let analyticUnitId = ctx.request.query.id; |
|
|
|
|
|
|
|
|
|
|
|
if(id === undefined) { |
|
|
|
if(analyticUnitId === undefined) { |
|
|
|
throw new Error('No id param in query'); |
|
|
|
throw new Error('No id param in query'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let unit: AnalyticUnit.AnalyticUnit = await AnalyticUnit.findById(id); |
|
|
|
let analyticUnit = await AnalyticUnit.findById(analyticUnitId); |
|
|
|
|
|
|
|
|
|
|
|
ctx.response.body = { |
|
|
|
ctx.response.body = { |
|
|
|
name: unit.name, |
|
|
|
name: analyticUnit.name, |
|
|
|
metric: unit.metric, |
|
|
|
metric: analyticUnit.metric, |
|
|
|
status: unit.status |
|
|
|
status: analyticUnit.status |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
} catch(e) { |
|
|
|
} catch(e) { |
|
|
|