|
|
@ -105,6 +105,29 @@ async function createUnit(ctx: Router.IRouterContext) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function updateUnit(ctx: Router.IRouterContext) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const unit = ctx.request.body as AnalyticUnit.AnalyticUnit; |
|
|
|
|
|
|
|
if(unit.id === undefined) { |
|
|
|
|
|
|
|
throw new Error('Cannot update undefined id'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: we can't allow to update everything
|
|
|
|
|
|
|
|
AnalyticUnit.update(unit.id, unit); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.response.body = { |
|
|
|
|
|
|
|
code: 200, |
|
|
|
|
|
|
|
message: 'Success' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
ctx.response.status = 500; |
|
|
|
|
|
|
|
ctx.response.body = { |
|
|
|
|
|
|
|
code: 500, |
|
|
|
|
|
|
|
message: `PATCH /analyticUnits error: ${e.message}` |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function updateMetric(ctx: Router.IRouterContext) { |
|
|
|
async function updateMetric(ctx: Router.IRouterContext) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const { analyticUnitId, metric, datasource } = ctx.request.body as { |
|
|
|
const { analyticUnitId, metric, datasource } = ctx.request.body as { |
|
|
@ -192,5 +215,7 @@ router.get('/status', getStatus); |
|
|
|
router.get('/types', getTypes); |
|
|
|
router.get('/types', getTypes); |
|
|
|
router.patch('/metric', updateMetric); |
|
|
|
router.patch('/metric', updateMetric); |
|
|
|
router.patch('/alert', updateAlert); |
|
|
|
router.patch('/alert', updateAlert); |
|
|
|
|
|
|
|
|
|
|
|
router.post('/', createUnit); |
|
|
|
router.post('/', createUnit); |
|
|
|
router.delete('/', deleteUnit); |
|
|
|
router.delete('/', deleteUnit); |
|
|
|
|
|
|
|
router.patch('/', updateUnit); |
|
|
|